@antora/redirect-producer
Advanced tools
Comparing version 2.3.4 to 3.0.0-alpha.1
@@ -5,3 +5,2 @@ 'use strict' | ||
const File = require('vinyl') | ||
const { URL } = require('url') | ||
@@ -53,3 +52,6 @@ const ENCODED_SPACE_RX = /%20/g | ||
case 'static': | ||
return populateStaticRedirectFiles(aliases, siteUrl) | ||
return populateStaticRedirectFiles( | ||
aliases.filter((it) => it.out), | ||
siteUrl | ||
) | ||
default: | ||
@@ -77,3 +79,5 @@ return unpublish(aliases) | ||
toUrl = ~toUrl.indexOf('%20') ? `'${urlPath}${toUrl.replace(ENCODED_SPACE_RX, ' ')}'` : urlPath + toUrl | ||
accum.push(`Redirect 301 ${fromUrl} ${toUrl}`) | ||
// see https://httpd.apache.org/docs/current/en/mod/mod_alias.html#redirect | ||
// NOTE: redirect rule for directory prefix does not require trailing slash | ||
accum.push(`Redirect ${file.pub.splat ? '302' : '301'} ${fromUrl} ${toUrl}`) | ||
return accum | ||
@@ -92,5 +96,9 @@ }, []) | ||
const toUrl = urlPath + file.rel.pub.url | ||
accum.push(`${fromUrl} ${toUrl} 301!`) | ||
if (includeDirectoryRedirects && fromUrl.endsWith('/index.html')) { | ||
accum.push(`${fromUrl.substr(0, fromUrl.length - 10)} ${toUrl} 301!`) | ||
if (file.pub.splat) { | ||
accum.push(`${fromUrl}/* ${toUrl}/:splat 302!`) | ||
} else { | ||
accum.push(`${fromUrl} ${toUrl} 301!`) | ||
if (includeDirectoryRedirects && fromUrl.endsWith('/index.html')) { | ||
accum.push(`${fromUrl.substr(0, fromUrl.length - 10)} ${toUrl} 301!`) | ||
} | ||
} | ||
@@ -109,3 +117,7 @@ return accum | ||
toUrl = ~toUrl.indexOf('%20') ? `'${urlPath}${toUrl.replace(ENCODED_SPACE_RX, ' ')}'` : urlPath + toUrl | ||
return `location = ${fromUrl} { return 301 ${toUrl}; }` | ||
if (file.pub.splat) { | ||
return `location ^~ ${fromUrl}/ { rewrite ^${regexpEscape(fromUrl)}/(.*)$ ${regexpEscape(toUrl)}/$1; }` | ||
} else { | ||
return `location = ${fromUrl} { return 301 ${toUrl}; }` | ||
} | ||
}) | ||
@@ -140,2 +152,7 @@ return [new File({ contents: Buffer.from(rules.join('\n') + '\n'), out: { path: '.etc/nginx/rewrite.conf' } })] | ||
function regexpEscape (str) { | ||
// we don't escape "-" since it's meaningless in a literal | ||
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') | ||
} | ||
module.exports = produceRedirects |
{ | ||
"name": "@antora/redirect-producer", | ||
"version": "2.3.4", | ||
"version": "3.0.0-alpha.1", | ||
"description": "Produces redirects (HTTP redirections) for pages in an Antora site.", | ||
@@ -18,7 +18,7 @@ "license": "MPL-2.0", | ||
"dependencies": { | ||
"@antora/asciidoc-loader": "2.3.4", | ||
"@antora/asciidoc-loader": "3.0.0-alpha.1", | ||
"vinyl": "~2.2" | ||
}, | ||
"engines": { | ||
"node": ">=8.11.0" | ||
"node": ">=10.17.0" | ||
}, | ||
@@ -36,3 +36,3 @@ "files": [ | ||
], | ||
"gitHead": "5a40191c970ece6baecbd1a3a7a599d7161351a9" | ||
"gitHead": "337ff6d2ed11e1f4d0a8ef993ddc8eaac7a73e9f" | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
25456
149
1
+ Added@antora/asciidoc-loader@3.0.0-alpha.1(transitive)
- Removed@antora/asciidoc-loader@2.3.4(transitive)