@antora/redirect-producer
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -136,13 +136,20 @@ 'use strict' | ||
const targetUrl = file.rel.pub.url | ||
const relativeUrl = computeRelativeUrlPath(file.pub.url, targetUrl) | ||
const canonicalUrl = siteUrl && siteUrl.charAt() !== '/' ? siteUrl + targetUrl : undefined | ||
const canonicalLink = canonicalUrl ? `<link rel="canonical" href="${canonicalUrl}">\n` : '' | ||
let linkTag | ||
let to = targetUrl.charAt() === '/' ? computeRelativeUrlPath(file.pub.url, targetUrl) : undefined | ||
let toText = to | ||
if (to) { | ||
if (siteUrl && siteUrl.charAt() !== '/') { | ||
linkTag = `<link rel="canonical" href="${(toText = siteUrl + targetUrl)}">\n` | ||
} | ||
} else { | ||
linkTag = `<link rel="canonical" href="${(toText = to = targetUrl)}">\n` | ||
} | ||
return `<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
${canonicalLink}<script>location="${relativeUrl}"</script> | ||
<meta http-equiv="refresh" content="0; url=${relativeUrl}"> | ||
${linkTag || ''}<script>location="${to}"</script> | ||
<meta http-equiv="refresh" content="0; url=${to}"> | ||
<meta name="robots" content="noindex"> | ||
<title>Redirect Notice</title> | ||
<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="${to}">${toText}</a>.</p>` | ||
} | ||
@@ -156,7 +163,4 @@ | ||
function computeRelativeUrlPath (from, to) { | ||
return from === to | ||
? to.charAt(to.length - 1) === '/' | ||
? './' | ||
: path.basename(to) | ||
: (path.relative(path.dirname(from + '.'), to) || '.') + (to.charAt(to.length - 1) === '/' ? '/' : '') | ||
if (to === from) return to.charAt(to.length - 1) === '/' ? './' : path.basename(to) | ||
return (path.relative(path.dirname(from + '.'), to) || '.') + (to.charAt(to.length - 1) === '/' ? '/' : '') | ||
} | ||
@@ -163,0 +167,0 @@ |
{ | ||
"name": "@antora/redirect-producer", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "Produces redirects (HTTP redirections) for pages in an Antora site.", | ||
@@ -5,0 +5,0 @@ "license": "MPL-2.0", |
10208
174