From b968cd38e4538873edb79d6e77b6e3787a0ed637 Mon Sep 17 00:00:00 2001 From: Neil Dewhurst Date: Tue, 18 Mar 2025 21:04:02 +0000 Subject: [PATCH 1/3] replace version with current if only version --- src/helpers/neo-canonical-current.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/helpers/neo-canonical-current.js b/src/helpers/neo-canonical-current.js index 14af66b3..c0626baa 100644 --- a/src/helpers/neo-canonical-current.js +++ b/src/helpers/neo-canonical-current.js @@ -7,8 +7,9 @@ 'use strict' module.exports = (page) => { - if (!page.latest) return page.canonicalUrl - const re = new RegExp(`/${page.latest.version}/`) + if (!page.latest && !page.attributes['use-current-mapping']) return page.canonicalUrl + const versionToReplace = page.latest ? page.latest.version : page.version + const re = new RegExp(`/${versionToReplace}/`) const latestVersionPath = `/${(page.attributes['latest-version-path'] || 'current')}/` return page.canonicalUrl.replace(re, latestVersionPath) } From b92b16bd3c1cd266b8119cfb80be734383880283 Mon Sep 17 00:00:00 2001 From: Neil Dewhurst Date: Tue, 18 Mar 2025 21:21:56 +0000 Subject: [PATCH 2/3] if no latest use page version if set --- src/helpers/neo-canonical-current.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/helpers/neo-canonical-current.js b/src/helpers/neo-canonical-current.js index c0626baa..03e81675 100644 --- a/src/helpers/neo-canonical-current.js +++ b/src/helpers/neo-canonical-current.js @@ -4,10 +4,14 @@ // 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 there's only one version of the page, there is no page.latest +// if the version is ~ there is no version in the path +// if both of these are true, we return the canonical URL as is + 'use strict' module.exports = (page) => { - if (!page.latest && !page.attributes['use-current-mapping']) return page.canonicalUrl + if (!page.latest && !page.version) return page.canonicalUrl const versionToReplace = page.latest ? page.latest.version : page.version const re = new RegExp(`/${versionToReplace}/`) const latestVersionPath = `/${(page.attributes['latest-version-path'] || 'current')}/` From ae71aa37f821c8e0386b14ac28152463862cd43b Mon Sep 17 00:00:00 2001 From: Neil Dewhurst Date: Tue, 18 Mar 2025 21:40:04 +0000 Subject: [PATCH 3/3] try to get a version, return if empty --- src/helpers/neo-canonical-current.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/helpers/neo-canonical-current.js b/src/helpers/neo-canonical-current.js index 03e81675..628618c9 100644 --- a/src/helpers/neo-canonical-current.js +++ b/src/helpers/neo-canonical-current.js @@ -4,15 +4,14 @@ // 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 there's only one version of the page, there is no page.latest -// if the version is ~ there is no version in the path -// if both of these are true, we return the canonical URL as is +// 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 && !page.version) return page.canonicalUrl 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)