@antora/redirect-producer
Advanced tools
Comparing version 2.3.0-alpha.1 to 2.3.0-alpha.2
@@ -41,4 +41,4 @@ 'use strict' | ||
switch (playbook.urls.redirectFacility) { | ||
case 'static': | ||
return populateStaticRedirectFiles(aliases, siteUrl) | ||
case 'httpd': | ||
return createHttpdHtaccess(aliases, extractUrlPath(siteUrl)) | ||
case 'netlify': | ||
@@ -52,2 +52,4 @@ return createNetlifyRedirects( | ||
return createNginxRewriteConf(aliases, extractUrlPath(siteUrl)) | ||
case 'static': | ||
return populateStaticRedirectFiles(aliases, siteUrl) | ||
default: | ||
@@ -68,8 +70,13 @@ return unpublish(aliases) | ||
function populateStaticRedirectFiles (files, siteUrl) { | ||
files.forEach((file) => { | ||
file.contents = createStaticRedirectContents(file, siteUrl) | ||
file.mediaType = 'text/html' | ||
}) | ||
return [] | ||
function createHttpdHtaccess (files, urlPath) { | ||
const rules = files.reduce((accum, file) => { | ||
delete file.out | ||
let fromUrl = file.pub.url | ||
fromUrl = ~fromUrl.indexOf('%20') ? `'${urlPath}${fromUrl.replace(ENCODED_SPACE_RX, ' ')}'` : urlPath + fromUrl | ||
let toUrl = file.rel.pub.url | ||
toUrl = ~toUrl.indexOf('%20') ? `'${urlPath}${toUrl.replace(ENCODED_SPACE_RX, ' ')}'` : urlPath + toUrl | ||
accum.push(`Redirect 301 ${fromUrl} ${toUrl}`) | ||
return accum | ||
}, []) | ||
return [new File({ contents: Buffer.from(rules.join('\n') + '\n'), out: { path: '.htaccess' } })] | ||
} | ||
@@ -88,3 +95,3 @@ | ||
}, []) | ||
return [new File({ contents: Buffer.from(rules.join('\n')), out: { path: '_redirects' } })] | ||
return [new File({ contents: Buffer.from(rules.join('\n') + '\n'), out: { path: '_redirects' } })] | ||
} | ||
@@ -101,7 +108,10 @@ | ||
}) | ||
return [new File({ contents: Buffer.from(rules.join('\n')), out: { path: '.etc/nginx/rewrite.conf' } })] | ||
return [new File({ contents: Buffer.from(rules.join('\n') + '\n'), out: { path: '.etc/nginx/rewrite.conf' } })] | ||
} | ||
function unpublish (files) { | ||
files.forEach((file) => delete file.out) | ||
function populateStaticRedirectFiles (files, siteUrl) { | ||
files.forEach((file) => { | ||
file.contents = Buffer.from(createStaticRedirectContents(file, siteUrl) + '\n') | ||
file.mediaType = 'text/html' | ||
}) | ||
return [] | ||
@@ -115,3 +125,3 @@ } | ||
const canonicalLink = canonicalUrl ? `<link rel="canonical" href="${canonicalUrl}">\n` : '' | ||
return Buffer.from(`<!DOCTYPE html> | ||
return `<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
@@ -123,5 +133,10 @@ ${canonicalLink}<script>location="${relativeUrl}"</script> | ||
<h1>Redirect Notice</h1> | ||
<p>The page you requested has been relocated to <a href="${relativeUrl}">${canonicalUrl || relativeUrl}</a>.</p>`) | ||
<p>The page you requested has been relocated to <a href="${relativeUrl}">${canonicalUrl || relativeUrl}</a>.</p>` | ||
} | ||
function unpublish (files) { | ||
files.forEach((file) => delete file.out) | ||
return [] | ||
} | ||
module.exports = produceRedirects |
{ | ||
"name": "@antora/redirect-producer", | ||
"version": "2.3.0-alpha.1", | ||
"version": "2.3.0-alpha.2", | ||
"description": "Produces redirects (HTTP redirections) for pages in an Antora site.", | ||
@@ -18,3 +18,3 @@ "license": "MPL-2.0", | ||
"dependencies": { | ||
"@antora/asciidoc-loader": "2.3.0-alpha.1", | ||
"@antora/asciidoc-loader": "2.3.0-alpha.2", | ||
"vinyl": "~2.2" | ||
@@ -21,0 +21,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7877
133
+ Added@antora/asciidoc-loader@2.3.0-alpha.2(transitive)
- Removed@antora/asciidoc-loader@2.3.0-alpha.1(transitive)