Skip to content

Commit 05f4ddc

Browse files
committed
Working on destucking docs building
1 parent 56d7863 commit 05f4ddc

5 files changed

Lines changed: 65 additions & 30 deletions

File tree

api/docusaurus-plugin/src/components/ApiPage.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,24 @@ function mapPackagesToReflection(packages: PackageReflectionGroup[]): TSDDeclara
6060
return map;
6161
}
6262

63+
let cachedMap: TSDDeclarationReflectionMap | null = null;
64+
let cachedPackages: PackageReflectionGroup[] | null = null;
65+
6366
export interface ApiPageProps extends DocRootProps {
6467
options: ApiOptions;
6568
packages: PackageReflectionGroup[];
6669
}
6770

6871
function ApiPage({ options, packages, ...props }: ApiPageProps) {
6972
const value = useMemo(
70-
() => ({ options, reflections: mapPackagesToReflection(packages) }),
73+
() => {
74+
if (cachedMap && cachedPackages === packages) {
75+
return { options, reflections: cachedMap };
76+
}
77+
cachedPackages = packages;
78+
cachedMap = mapPackagesToReflection(packages);
79+
return { options, reflections: cachedMap };
80+
},
7181
[options, packages],
7282
);
7383

api/docusaurus-plugin/src/components/SourceLink.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ function replaceWithSrc(url: string): string {
77
return url.replace(/\/(dts|dist|lib|build|es|esm|cjs|mjs)\//, '/src/');
88
}
99

10+
function isExternalSource(fileName: string): boolean {
11+
return fileName.includes('node_modules') || fileName.includes('declarations') || fileName.includes('android.d.ts');
12+
}
13+
1014
export interface SourceLinkProps {
1115
sources?: JSONOutput.SourceReference[];
1216
}
@@ -19,26 +23,31 @@ export function SourceLink({ sources = [] }: SourceLinkProps) {
1923
return null;
2024
}
2125

26+
const githubHost = (siteConfig.customFields?.githubHost as string) ?? 'github.com';
27+
const githubRepository = `https://${githubHost}/${siteConfig.organizationName}/${siteConfig.projectName}`;
28+
2229
return (
2330
<>
24-
{sources.slice(0, 3).map((source) => (
25-
<a
26-
key={source.fileName}
27-
className="tsd-anchor"
28-
href={
29-
source.url ||
30-
`https://${siteConfig.githubHost}${
31-
siteConfig.githubPort ? `:${siteConfig.githubPort}` : ''
32-
}/${siteConfig.organizationName}/${
33-
siteConfig.projectName
34-
}/blob/${gitRefName}/${replaceWithSrc(source.fileName)}#L${source.line}`
35-
}
36-
rel="noreferrer"
37-
target="_blank"
38-
>
39-
<i className="codicon codicon-file-code" />
40-
</a>
41-
))}
31+
{sources.slice(0, 3).map((source) => {
32+
if (isExternalSource(source.fileName)) {
33+
return null;
34+
}
35+
36+
return (
37+
<a
38+
key={source.fileName}
39+
className="tsd-anchor"
40+
href={
41+
source.url ||
42+
`${githubRepository}/blob/${gitRefName}/${replaceWithSrc(source.fileName)}#L${source.line}`
43+
}
44+
rel="noreferrer"
45+
target="_blank"
46+
>
47+
<i className="codicon codicon-file-code" />
48+
</a>
49+
);
50+
})}
4251
</>
4352
);
4453
}

api/docusaurus-plugin/src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,21 @@ export default function typedocApiPlugin(
274274
return;
275275
}
276276

277+
actions.setGlobalData({
278+
path: normalizeUrl([context.baseUrl, options.routeBasePath ?? 'api']),
279+
versions: content.loadedVersions.map((loadedVersion) => ({
280+
name: loadedVersion.versionName,
281+
label: loadedVersion.versionLabel,
282+
isLast: loadedVersion.isLast,
283+
path: loadedVersion.versionPath,
284+
mainDocId: '',
285+
docs: [],
286+
draftIds: [],
287+
sidebars: {},
288+
})),
289+
breadcrumbs: options.breadcrumbs,
290+
});
291+
277292
const docs: PropVersionDocs = {};
278293

279294
// Create an index of versions for quick lookups.

docusaurus.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ import { readdirSync } from 'fs';
3030
import path from 'path';
3131

3232
const baseUrl = process.env.BASE_URL ?? '/';
33+
const isCI = true; // process.env.npm_command === 'ci';
3334
const configUrl = 'https://nernar.github.io';
3435

3536
export default {
3637
title: 'Inner Core Docs',
3738
tagline: 'Inner Core, Core Engine and Horizon documentation',
3839
url: configUrl,
3940
baseUrl,
40-
onBrokenLinks: 'warn',
41-
onBrokenMarkdownLinks: 'warn',
41+
onBrokenLinks: isCI ? 'ignore' : 'warn',
42+
onBrokenMarkdownLinks: isCI ? 'ignore' : 'warn',
43+
onBrokenAnchors: isCI ? 'ignore' : 'warn',
4244
favicon: 'favicon/favicon.ico',
4345

4446
markdown: {

src/plugins/remark-authors.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Transformer } from 'unified';
2-
import type { Root, Text } from 'mdast';
2+
import type { Root, Text, Parent } from 'mdast';
33

4-
async function processAuthors(text: Text) {
4+
async function processAuthors(text: Text, index: number, parent: Parent) {
55
let children = [];
66
let lastIndex = 0;
77
let match;
@@ -10,7 +10,7 @@ async function processAuthors(text: Text) {
1010
while ((match = authorRegex.exec(text.value)) !== null) {
1111
if (match.index > lastIndex) {
1212
children.push({
13-
type: text.type,
13+
type: 'text',
1414
value: text.value.slice(lastIndex, match.index)
1515
});
1616
}
@@ -21,7 +21,7 @@ async function processAuthors(text: Text) {
2121

2222
if (authors.length > 0) {
2323
children.push({
24-
type: 'mdxJsxFlowElement',
24+
type: 'mdxJsxTextElement',
2525
name: 'GithubAuthors',
2626
attributes: [
2727
{
@@ -39,18 +39,17 @@ async function processAuthors(text: Text) {
3939
if (lastIndex > 0) {
4040
if (lastIndex < text.value.length) {
4141
children.push({
42-
type: text.type,
42+
type: 'text',
4343
value: text.value.slice(lastIndex)
4444
});
4545
}
4646

4747
if (children.length > 0) {
48-
const node: Root = text as unknown as Root;
49-
node.type = 'root';
50-
node.children = children;
48+
parent.children.splice(index, 1, ...children);
5149
}
5250
}
5351
}
52+
5453
export default function plugin(): Transformer<Root> {
5554
return async (tree) => {
5655
const promises = [];
@@ -59,7 +58,7 @@ export default function plugin(): Transformer<Root> {
5958
if (!parent || index === undefined) {
6059
return;
6160
}
62-
promises.push(processAuthors(node));
61+
promises.push(processAuthors(node as Text, index, parent as Parent));
6362
});
6463
await Promise.all(promises);
6564
};

0 commit comments

Comments
 (0)