Skip to content

Commit

Permalink
support hardcoded versions in frontmatter redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahs committed Dec 16, 2020
1 parent a32e2e3 commit 5762bba
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/redirects/permalinks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const patterns = require('../patterns')
const { getVersionedPathWithLanguage } = require('../path-utils')
const { getVersionedPathWithLanguage, getVersionStringFromPath } = require('../path-utils')
const allVersions = Object.keys(require('../all-versions'))
const getOldPathsFromPermalink = require('./get-old-paths-from-permalink')

module.exports = function generateRedirectsForPermalinks (permalinks, redirectFrontmatter) {
Expand All @@ -25,6 +26,12 @@ module.exports = function generateRedirectsForPermalinks (permalinks, redirectFr
// remove trailing slashes (sometimes present in frontmatter)
frontmatterOldPath = frontmatterOldPath.replace(patterns.trailingSlash, '$1')

// support hardcoded versions in redirect frontmatter
if (allVersions.includes(getVersionStringFromPath(frontmatterOldPath))) {
redirects[frontmatterOldPath] = permalink.href
redirects[`/en${frontmatterOldPath}`] = permalink.href
}

// get the old path for the current permalink version
const versionedFrontmatterOldPath = getVersionedPathWithLanguage(frontmatterOldPath, permalink.pageVersion, permalink.languageCode)

Expand Down

0 comments on commit 5762bba

Please sign in to comment.