Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions components/SideBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;

Expand All @@ -39,7 +35,7 @@ const currentVersion = isVersioned ? versionBase : undefined;
/** Docs sidebar, plus a webpack version picker on the versioned API docs. */
export default ({ metadata }) => (
<SideBar
pathname={pathnameFor(metadata.path)}
pathname={toPublicLink(metadata.path, versionBase)}
groups={groupsFor(metadata.path)}
onSelect={redirect}
as={PrefetchLink}
Expand Down
2 changes: 1 addition & 1 deletion plugins/processor/router.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { categoryForReflection } from '../shared/categories.mjs';
import { getConstructorTitle, getMemberTitle } from '../shared/titles.mjs';
import { getSourceMetadata, isTypePage } from './metadata.mjs';
import { createTypePages, TYPE_PAGE_HEADING_KINDS } from './synthetic.mjs';
import { normalizeLink } from '../shared/urls.mjs';
import { normalizeLink } from '../../utils/helpers/urls.mjs';

/**
* The router owns the public Markdown shape. It keeps one class per file,
Expand Down
2 changes: 1 addition & 1 deletion plugins/processor/site.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReflectionKind } from 'typedoc';
import { CATEGORY_RULES } from '../shared/categories.mjs';
import { toPublicLink } from '../shared/urls.mjs';
import { toPublicLink } from '../../utils/helpers/urls.mjs';

const SIDEBAR_KINDS =
ReflectionKind.Project | ReflectionKind.Namespace | ReflectionKind.Class;
Expand Down
2 changes: 1 addition & 1 deletion plugins/processor/typeMap.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReflectionKind } from 'typedoc';
import { isTypePage } from './metadata.mjs';
import { normalizeLink } from '../shared/urls.mjs';
import { normalizeLink } from '../../utils/helpers/urls.mjs';

const TYPE_MAP_KINDS =
ReflectionKind.Class |
Expand Down
16 changes: 0 additions & 16 deletions plugins/shared/urls.mjs

This file was deleted.

15 changes: 15 additions & 0 deletions utils/helpers/urls.mjs
Original file line number Diff line number Diff line change
@@ -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}`;
};
Loading