@antora/redirect-producer
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -38,6 +38,3 @@ 'use strict' | ||
let siteUrl = playbook.site.url | ||
if (siteUrl) { | ||
if (siteUrl === '/') siteUrl = '' | ||
else if (siteUrl.charAt(siteUrl.length - 1) === '/') siteUrl = siteUrl.substr(0, siteUrl.length - 1) | ||
} | ||
if (siteUrl) siteUrl = stripTrailingSlash(siteUrl, '') | ||
switch (playbook.urls.redirectFacility) { | ||
@@ -90,3 +87,3 @@ case 'gitlab': | ||
// NOTE: redirect rule for directory prefix does not require trailing slash | ||
accum.push(`Redirect ${file.pub.splat ? '302' : '301'} ${fromUrl} ${toUrl}`) | ||
accum.push(`Redirect ${file.pub.splat ? '302' : '301'} ${fromUrl} ${stripTrailingSlash(toUrl)}`) | ||
return accum | ||
@@ -107,3 +104,3 @@ }, []) | ||
if (file.pub.splat) { | ||
accum.push(`${fromUrl}/* ${toUrl}/:splat 302${forceFlag}`) | ||
accum.push(`${fromUrl}/* ${ensureTrailingSlash(toUrl)}:splat 302${forceFlag}`) | ||
} else { | ||
@@ -128,3 +125,4 @@ accum.push(`${fromUrl} ${toUrl} 301${forceFlag}`) | ||
if (file.pub.splat) { | ||
return `location ^~ ${fromUrl}/ { rewrite ^${regexpEscape(fromUrl)}/(.*)$ ${toUrl}/$1 redirect; }` | ||
const toUrlWithTrailingSlash = ensureTrailingSlash(toUrl) | ||
return `location ^~ ${fromUrl}/ { rewrite ^${regexpEscape(fromUrl)}/(.*)$ ${toUrlWithTrailingSlash}$1 redirect; }` | ||
} else { | ||
@@ -170,2 +168,12 @@ return `location = ${fromUrl} { return 301 ${toUrl}; }` | ||
function ensureTrailingSlash (str) { | ||
return str.charAt(str.length - 1) === '/' ? str : str + '/' | ||
} | ||
function stripTrailingSlash (str, root = '/') { | ||
if (str === '/') return root | ||
const lastIdx = str.length - 1 | ||
return str.charAt(lastIdx) === '/' ? str.substr(0, lastIdx) : str | ||
} | ||
function regexpEscape (str) { | ||
@@ -172,0 +180,0 @@ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // don't escape "-" since it's meaningless in a literal |
{ | ||
"name": "@antora/redirect-producer", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Produces redirects (HTTP redirections) for pages in an Antora site.", | ||
@@ -17,5 +17,2 @@ "license": "MPL-2.0", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "_mocha" | ||
}, | ||
"dependencies": { | ||
@@ -38,3 +35,7 @@ "vinyl": "~2.2" | ||
], | ||
"gitHead": "e8e6f6ba33b1ab3f796907b5a256893a64844cd1" | ||
"scripts": { | ||
"test": "_mocha", | ||
"prepublishOnly": "node $npm_config_local_prefix/npm/prepublishOnly.js", | ||
"postpublish": "node $npm_config_local_prefix/npm/postpublish.js" | ||
} | ||
} |
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
172
9889
4