diff --git a/components/NavBar.jsx b/components/NavBar.jsx index 19ba306..68cfd08 100644 --- a/components/NavBar.jsx +++ b/components/NavBar.jsx @@ -7,7 +7,7 @@ import SearchBox from '@node-core/doc-kit/src/generators/web/ui/components/Searc import { useTheme } from '@node-core/doc-kit/src/generators/web/ui/hooks/useTheme.mjs'; import { navbar } from '#theme/site'; import { baseURL } from '#theme/config'; -import { toPublicLink } from '../plugins/shared/urls.mjs'; +import { toPublicLink } from '../utils/helpers/urls.mjs'; import Logo from '#theme/Logo'; const versionBase = new URL(baseURL).pathname; diff --git a/components/SideBar.jsx b/components/SideBar.jsx index ffa7954..dff3318 100644 --- a/components/SideBar.jsx +++ b/components/SideBar.jsx @@ -3,6 +3,7 @@ import SideBar from '@node-core/ui-components/Containers/Sidebar'; import { major } from 'semver'; import { sidebar } from '#theme/local/site'; import { version } from '#theme/config'; +import { toPublicLink } from '../utils/helpers/urls.mjs'; import versions from '../versions.json' with { type: 'json' }; /** @param {string} url */ @@ -16,11 +17,6 @@ const isVersioned = Array.isArray(sidebar); // Versioned pages expose a version relative path, we prefix it so it matches the absolute sidebar links. const versionBase = isVersioned ? `/docs/api/v${version.major}.x` : ''; -const pathnameFor = path => { - const clean = path.replace(/\/index$/, '').replace(/^\//, ''); - return (clean ? `${versionBase}/${clean}` : versionBase) || '/'; -}; - const groupsFor = path => { if (isVersioned) return sidebar; @@ -39,7 +35,7 @@ const currentVersion = isVersioned ? versionBase : undefined; /** Docs sidebar, plus a webpack version picker on the versioned API docs. */ export default ({ metadata }) => ( { - if (!url) return '/'; - - return ( - url - .replace(/\.(md|html)$/, '') - .replace(/\/index$/, '') - .replace(/^\//, '') || '/' - ); -}; - -export const toPublicLink = (url, publicPath) => { - const path = normalizeLink(url); - const prefix = publicPath ? `${publicPath.replace(/\/$/g, '')}` : ''; - return path ? `${prefix}/${path}` : prefix || '/'; -}; diff --git a/utils/helpers/urls.mjs b/utils/helpers/urls.mjs new file mode 100644 index 0000000..9df4c3b --- /dev/null +++ b/utils/helpers/urls.mjs @@ -0,0 +1,15 @@ +export const normalizeLink = url => { + if (!url) return ''; + + return url + .replace(/\.(md|html)$/, '') + .replace(/\/index$/, '') + .replace(/^\//, ''); +}; + +export const toPublicLink = (url, publicPath = '') => { + const path = normalizeLink(url); + const prefix = publicPath.replace(/^\/+|\/+$/g, ''); + const combined = [prefix, path].filter(Boolean).join('/'); + return `/${combined}`; +};