Skip to content

Commit 5762bba

Browse files
committed
support hardcoded versions in frontmatter redirects
1 parent a32e2e3 commit 5762bba

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

lib/redirects/permalinks.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const patterns = require('../patterns')
2-
const { getVersionedPathWithLanguage } = require('../path-utils')
2+
const { getVersionedPathWithLanguage, getVersionStringFromPath } = require('../path-utils')
3+
const allVersions = Object.keys(require('../all-versions'))
34
const getOldPathsFromPermalink = require('./get-old-paths-from-permalink')
45

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

29+
// support hardcoded versions in redirect frontmatter
30+
if (allVersions.includes(getVersionStringFromPath(frontmatterOldPath))) {
31+
redirects[frontmatterOldPath] = permalink.href
32+
redirects[`/en${frontmatterOldPath}`] = permalink.href
33+
}
34+
2835
// get the old path for the current permalink version
2936
const versionedFrontmatterOldPath = getVersionedPathWithLanguage(frontmatterOldPath, permalink.pageVersion, permalink.languageCode)
3037

0 commit comments

Comments
 (0)