Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@antora/redirect-producer

Package Overview
Dependencies
Maintainers
2
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antora/redirect-producer - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2

22

lib/produce-redirects.js

@@ -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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc