Skip to content

Commit ae71aa3

Browse files
committed
try to get a version, return if empty
1 parent b92b16b commit ae71aa3

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/helpers/neo-canonical-current.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
// we want to modify the canonical by replacing that version with 'current'
55
// we can allow for a page attribute to be set to override 'current'
66

7-
// if there's only one version of the page, there is no page.latest
8-
// if the version is ~ there is no version in the path
9-
// if both of these are true, we return the canonical URL as is
7+
// if the version is ~ there is no version in the path - we return the canonical URL as is
8+
// if there's only one version of the page, there is no page.latest - we use page.version
109

1110
'use strict'
1211

1312
module.exports = (page) => {
14-
if (!page.latest && !page.version) return page.canonicalUrl
1513
const versionToReplace = page.latest ? page.latest.version : page.version
14+
if (!versionToReplace) return page.canonicalUrl
1615
const re = new RegExp(`/${versionToReplace}/`)
1716
const latestVersionPath = `/${(page.attributes['latest-version-path'] || 'current')}/`
1817
return page.canonicalUrl.replace(re, latestVersionPath)

0 commit comments

Comments
 (0)