-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various Sitewide Fixes & Improvements. #266
Conversation
✅ Deploy Preview for nimble-elf-d9d491 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
…equired.) and document more.
// Constructs the appropriate route path for a given version | ||
function buildRoutePath( | ||
currentPath: string, | ||
locale: string | null, | ||
version: string, | ||
isOnLatest: boolean | ||
) { | ||
if (locale) { | ||
// Replace or add version segment while keeping the locale | ||
// e.g. /en/ -> /en/1.2.0/ or /en/1.2.0/ -> /en/1.3.0/ | ||
if (!isOnLatest) { | ||
if (version === props.versioningPlugin.latestVersion) { | ||
route = router.route.path.replace( | ||
`/${locale}/${currentVersion.value}/`, | ||
`/${locale}/` | ||
); | ||
return currentPath.replace(`/${locale}/${currentVersion.value}/`, `/${locale}/`); | ||
} else { | ||
route = router.route.path.replace( | ||
`/${locale}/${currentVersion}/`, | ||
`/${locale}/${version}/` | ||
); | ||
// Replace any existing version segment with the new one | ||
return currentPath.replace(`/${locale}/${currentVersion.value}/`, `/${locale}/${version}/`); | ||
} | ||
} else { | ||
route = router.route.path.replace( | ||
`/${locale}/`, | ||
`/${locale}/${version}/` | ||
); | ||
// If currently on latest, just add the new version segment | ||
return currentPath.replace(`/${locale}/`, `/${locale}/${version}/`); | ||
} | ||
} else { | ||
// Non-localized routes | ||
// e.g. / -> /1.2.0/ or /1.2.0/ -> /1.3.0/ | ||
if (!isOnLatest) { | ||
if (version === props.versioningPlugin.latestVersion) { | ||
route = router.route.path.replace(`/${currentVersion.value}/`, "/"); | ||
return currentPath.replace(`/${currentVersion.value}/`, "/"); | ||
} else { | ||
route = router.route.path.replace( | ||
`/${currentVersion.value}/`, | ||
`/${version}/` | ||
); | ||
return currentPath.replace(`/${currentVersion.value}/`, `/${version}/`); | ||
} | ||
} else { | ||
route = router.route.path.replace("/", `/${version}/`); | ||
return currentPath.replace("/", `/${version}/`); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this could simply be something like:
currentPath.replace(
currentVersion.value === props.versioningPlugin.latestVersion
? "/"
: `/${currentVersion.value}/`,
newVersion.value === props.versioningPlugin.latestVersion
? "/"
: `/${newVersion.value}/`
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yours doesn't handle locales
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How so? If you've got /it_it/1.20.4/link/to/page
, and you replace /1.20.4/
with /1.21/
, you end up with /it_it/1.21/link/to/page
, which is correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried it, it doesn't work when switching between versions whilst a locale is present. What we have works, I dont think it needs to be changed for the sake of changing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd forgotten the dollar signs; you may keep it as is if it is not worth changing tho
Co-authored-by: Miroma <136986257+its-miroma@users.noreply.github.com>
Closes #239