Skip to content
Merged
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
5 changes: 3 additions & 2 deletions plugins/processor/router.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +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';

/**
* The router owns the public Markdown shape. It keeps one class per file,
Expand Down Expand Up @@ -210,7 +211,7 @@ export class DocKitRouter extends MemberRouter {
const [page, routedAnchor] = fullUrl.split('#');
const anchor =
sourceAnchorName(target) ?? routedAnchor ?? this.getAnchor(target);
const pageUrl = page.replace(/\.md$/, '.html');
const pageUrl = normalizeLink(page);

return anchor ? `${pageUrl}#${anchor}` : pageUrl;
}
Expand Down Expand Up @@ -242,7 +243,7 @@ export class DocKitRouter extends MemberRouter {
const title = anchorTitle(target, pageTarget);
const anchor = this.getSlugger(pageTarget).slug(title);

this.fullUrls.set(target, `${pageUrl.replace(/\.md$/, '.html')}#${anchor}`);
this.fullUrls.set(target, `${normalizeLink(pageUrl)}#${anchor}`);
this.anchors.set(target, anchor);

if (!includeChildren) {
Expand Down
11 changes: 3 additions & 8 deletions plugins/processor/site.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { ReflectionKind } from 'typedoc';
import { CATEGORY_RULES } from '../shared/categories.mjs';
import { toPublicLink } from '../shared/urls.mjs';

const SIDEBAR_KINDS =
ReflectionKind.Project | ReflectionKind.Namespace | ReflectionKind.Class;

const SIDEBAR_GROUP_NAME = 'API Documentation';
const SIDEBAR_GROUP_NAME = 'API';

const getFirstAtxHeading = text => text.match(/^#\s+(.+)$/m)?.[1]?.trim();

const getFirstPathSegment = url => url.replace(/^\//, '').split('/')[0];

const toSidebarLink = (url, basePath) => {
const path = url.replace(/\.md$/, '').replace(/\/index$/, '');
const prefix = basePath ? `/${basePath.replace(/^\/|\/$/g, '')}` : '';
return path ? `${prefix}/${path}` : prefix || '/';
};

const defaultLabelFor = (target, url) => {
if (url.endsWith('/index.md')) return 'Overview';
if (url.endsWith('/types.md')) return 'Types';
Expand Down Expand Up @@ -59,7 +54,7 @@ export const sidebar = (router, basePath) => {
};

group.items.push({
link: toSidebarLink(url, basePath),
link: toPublicLink(url, basePath),
label,
});

Expand Down
3 changes: 2 additions & 1 deletion plugins/processor/typeMap.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ReflectionKind } from 'typedoc';
import { isTypePage } from './metadata.mjs';
import { normalizeLink } from '../shared/urls.mjs';

const TYPE_MAP_KINDS =
ReflectionKind.Class |
Expand All @@ -23,7 +24,7 @@ export const createTypeMap = router => {

const { name } = target;
if (!typeMap.has(name)) {
typeMap.set(name, router.getAnchoredURL(target));
typeMap.set(name, normalizeLink(router.getAnchoredURL(target)));
}
}

Expand Down
11 changes: 11 additions & 0 deletions plugins/shared/urls.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const normalizeLink = url => {
if (!url) return '/';

return url.replace(/\.(md|html)$/, '').replace(/\/index$/, '') || '/';
};

export const toPublicLink = (url, publicPath) => {
const path = normalizeLink(url);
const prefix = publicPath ? `/${publicPath.replace(/^\/|\/$/g, '')}` : '';
return path ? `${prefix}/${path}` : prefix || '/';
};