@antora/redirect-producer
Advanced tools
Comparing version 3.0.2 to 3.0.3
@@ -39,18 +39,10 @@ 'use strict' | ||
if (siteUrl) siteUrl = stripTrailingSlash(siteUrl, '') | ||
const directoryRedirects = (playbook.urls.htmlExtensionStyle || 'default') !== 'default' | ||
switch (playbook.urls.redirectFacility) { | ||
case 'gitlab': | ||
return createNetlifyRedirects( | ||
aliases, | ||
extractUrlPath(siteUrl), | ||
(playbook.urls.htmlExtensionStyle || 'default') === 'default', | ||
false | ||
) | ||
return createNetlifyRedirects(aliases, extractUrlPath(siteUrl), !directoryRedirects, false) | ||
case 'httpd': | ||
return createHttpdHtaccess(aliases, extractUrlPath(siteUrl)) | ||
return createHttpdHtaccess(aliases, extractUrlPath(siteUrl), directoryRedirects) | ||
case 'netlify': | ||
return createNetlifyRedirects( | ||
aliases, | ||
extractUrlPath(siteUrl), | ||
(playbook.urls.htmlExtensionStyle || 'default') === 'default' | ||
) | ||
return createNetlifyRedirects(aliases, extractUrlPath(siteUrl), !directoryRedirects) | ||
case 'nginx': | ||
@@ -78,3 +70,3 @@ return createNginxRewriteConf(aliases, extractUrlPath(siteUrl)) | ||
function createHttpdHtaccess (files, urlPath) { | ||
function createHttpdHtaccess (files, urlPath, directoryRedirects = false) { | ||
const rules = files.reduce((accum, file) => { | ||
@@ -88,3 +80,9 @@ delete file.out | ||
// NOTE: redirect rule for directory prefix does not require trailing slash | ||
accum.push(`Redirect ${file.pub.splat ? '302' : '301'} ${fromUrl} ${stripTrailingSlash(toUrl)}`) | ||
if (file.pub.splat) { | ||
accum.push(`Redirect 302 ${fromUrl} ${stripTrailingSlash(toUrl)}`) | ||
} else if (directoryRedirects) { | ||
accum.push(`RedirectMatch 301 ^${regexpEscape(fromUrl)}$ ${stripTrailingSlash(toUrl)}`) | ||
} else { | ||
accum.push(`Redirect 301 ${fromUrl} ${toUrl}`) | ||
} | ||
return accum | ||
@@ -98,3 +96,3 @@ }, []) | ||
// however, we keep it when generating the rules for clarity | ||
function createNetlifyRedirects (files, urlPath, includeDirectoryRedirects = false, useForceFlag = true) { | ||
function createNetlifyRedirects (files, urlPath, addDirectoryRedirects = false, useForceFlag = true) { | ||
const rules = files.reduce((accum, file) => { | ||
@@ -109,3 +107,3 @@ delete file.out | ||
accum.push(`${fromUrl} ${toUrl} 301${forceFlag}`) | ||
if (includeDirectoryRedirects && fromUrl.endsWith('/index.html')) { | ||
if (addDirectoryRedirects && fromUrl.endsWith('/index.html')) { | ||
accum.push(`${fromUrl.substr(0, fromUrl.length - 10)} ${toUrl} 301${forceFlag}`) | ||
@@ -112,0 +110,0 @@ } |
{ | ||
"name": "@antora/redirect-producer", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Produces redirects (HTTP redirections) for pages in an Antora site.", | ||
@@ -5,0 +5,0 @@ "license": "MPL-2.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
10065
170