Skip to content

Commit

Permalink
fix: new approach to versioned urls
Browse files Browse the repository at this point in the history
  • Loading branch information
timwessman committed Nov 6, 2024
1 parent f46523f commit a8bb077
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions site/src/components/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,32 @@ import versions from '../data/versions.json';
const classNames = (...args) => args.filter((e) => e).join(' ');

const hrefWithVersion = (href, version) => {
return version
&& !href.startsWith(`/${version}`)
&& !href.startsWith('mailto:')
&& !href.startsWith('http')
? withPrefix(`/${version}${href}`)
: withPrefix(`${href}`);
if (!version || version === '' || href.startsWith('mailto:') || href.startsWith('#') || href.startsWith('http'))
return href;

let withVersion = '';
let versionAdded = false;
const pathParts = href.split('/');

pathParts.forEach(part => {
if (part !== '') {
if (part === 'hds-demo' || part.startsWith('preview_') || versionAdded) {
withVersion += '/' + part;
}
else if (!versionAdded) {
withVersion += '/' + version + (!part.startsWith('release-') ? '/' + part : '');
versionAdded = true;
}
}
});

console.log('hrefWithVersion() href:', href,
'version:', version,
'parts:', pathParts,
'return:', withPrefix(`${withVersion}`)
);

return withPrefix(`${withVersion}`);
};
const hrefWithoutVersion = (href, version) => {
return href.replace(`/${version}`, '');
Expand Down

0 comments on commit a8bb077

Please sign in to comment.