Skip to content

Commit 1e55d0c

Browse files
authored
Replace version with current if single version and version is defined (#307)
Use `page.latest` or `page.version` to get a version to replace with `current`. If the component has a single version there is no `page.latest`. If `version: ~` in antora.yml there is no page.version. If there's no version to replace, return the canonicalUrl as is.
1 parent 182d2fe commit 1e55d0c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/helpers/neo-canonical-current.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
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 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
9+
710
'use strict'
811

912
module.exports = (page) => {
10-
if (!page.latest) return page.canonicalUrl
11-
const re = new RegExp(`/${page.latest.version}/`)
13+
const versionToReplace = page.latest ? page.latest.version : page.version
14+
if (!versionToReplace) return page.canonicalUrl
15+
const re = new RegExp(`/${versionToReplace}/`)
1216
const latestVersionPath = `/${(page.attributes['latest-version-path'] || 'current')}/`
1317
return page.canonicalUrl.replace(re, latestVersionPath)
1418
}

0 commit comments

Comments
 (0)