Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/helpers/neo-canonical-current.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
// we want to modify the canonical by replacing that version with 'current'
// we can allow for a page attribute to be set to override 'current'

// if the version is ~ there is no version in the path - we return the canonical URL as is
// if there's only one version of the page, there is no page.latest - we use page.version

'use strict'

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