diff --git a/src/helpers/neo-canonical-current.js b/src/helpers/neo-canonical-current.js index 14af66b3..628618c9 100644 --- a/src/helpers/neo-canonical-current.js +++ b/src/helpers/neo-canonical-current.js @@ -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) }