@alauda/doom 1.21.5 → 1.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli/lint.js +1 -1
- package/lib/eslint.d.ts +2 -2
- package/lib/eslint.js +10 -8
- package/lib/plugins/auto-sidebar/utils.js +1 -2
- package/lib/plugins/directives/remark-directives.js +19 -2
- package/lib/plugins/replace/parse-toc.js +1 -1
- package/lib/remark-lint/check-dead-links.js +3 -17
- package/lib/remark-lint/index.d.ts +2 -0
- package/lib/remark-lint/index.js +2 -0
- package/lib/remark-lint/list-item-punctuation.js +1 -1
- package/lib/remark-lint/maximum-link-content-length.js +3 -4
- package/lib/remark-lint/no-heading-punctuation.js +1 -1
- package/lib/remark-lint/no-multi-open-api-paths.d.ts +2 -0
- package/lib/remark-lint/no-multi-open-api-paths.js +13 -0
- package/lib/remark-lint/no-unmatched-anchor.d.ts +2 -0
- package/lib/remark-lint/no-unmatched-anchor.js +134 -0
- package/lib/remark-lint/site.js +2 -2
- package/lib/remark-lint/utils.d.ts +6 -0
- package/lib/remark-lint/utils.js +20 -0
- package/lib/remarkrc.js +3 -1
- package/lib/runtime/components/Callout.d.ts +6 -0
- package/lib/runtime/components/Callout.js +6 -0
- package/lib/runtime/components/Callouts.d.ts +3 -3
- package/lib/runtime/components/Callouts.js +3 -2
- package/lib/runtime/components/OpenAPIPath.d.ts +10 -3
- package/lib/runtime/components/OpenAPIPath.js +39 -31
- package/lib/runtime/components/OpenAPIRef.d.ts +1 -7
- package/lib/runtime/components/OpenAPIRef.js +6 -14
- package/lib/runtime/components/_HeadingTitle.js +3 -6
- package/lib/runtime/components/_RefLink.js +3 -4
- package/lib/runtime/components/_X.d.ts +2 -1
- package/lib/runtime/components/_X.js +34 -1
- package/lib/runtime/components/index.d.ts +1 -0
- package/lib/runtime/components/index.js +1 -0
- package/lib/shared/helpers.d.ts +0 -4
- package/lib/shared/helpers.js +0 -12
- package/lib/theme/VersionsNav/index.js +5 -4
- package/lib/theme/index.d.ts +23 -0
- package/lib/theme/index.js +2 -0
- package/package.json +3 -2
- package/styles/global.scss +12 -3
- package/lib/remark-lint/constants.d.ts +0 -1
- package/lib/remark-lint/constants.js +0 -1
- package/lib/runtime/components/_context.d.ts +0 -3
- package/lib/runtime/components/_context.js +0 -4
package/lib/cli/lint.js
CHANGED
|
@@ -26,7 +26,7 @@ export const lintCommand = new Command('lint')
|
|
|
26
26
|
overrideConfigFile: true,
|
|
27
27
|
ignorePatterns: globalOptions.ignore ? config.internalRoutes : undefined,
|
|
28
28
|
// @ts-expect-error -- stronger types
|
|
29
|
-
overrideConfig: await doom(cspell ? config
|
|
29
|
+
overrideConfig: await doom(cspell ? config : null),
|
|
30
30
|
});
|
|
31
31
|
logger.start(`Linting \`${cyan(path.relative(process.cwd(), docsDir))}\`...`);
|
|
32
32
|
const results = await eslint.lintFiles(glob);
|
package/lib/eslint.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UserConfig } from '@rspress/shared';
|
|
2
2
|
import tseslint from 'typescript-eslint';
|
|
3
|
-
declare function doom(
|
|
3
|
+
declare function doom(userConfig?: UserConfig | null): Promise<tseslint.ConfigArray>;
|
|
4
4
|
declare function doom(root: string | URL): Promise<tseslint.ConfigArray>;
|
|
5
5
|
export default doom;
|
package/lib/eslint.js
CHANGED
|
@@ -17,17 +17,19 @@ try {
|
|
|
17
17
|
catch {
|
|
18
18
|
remarkConfigPath = cjsRequire.resolve('./remarkrc.js');
|
|
19
19
|
}
|
|
20
|
-
async function doom(
|
|
20
|
+
async function doom(userConfigOrRoot) {
|
|
21
21
|
let cspellOptions;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
let config;
|
|
23
|
+
if (typeof userConfigOrRoot === 'string' || userConfigOrRoot instanceof URL) {
|
|
24
|
+
;
|
|
25
|
+
({ config } = await loadConfig(userConfigOrRoot));
|
|
25
26
|
cspellOptions = config.lint?.cspellOptions;
|
|
26
27
|
}
|
|
27
|
-
else {
|
|
28
|
-
|
|
28
|
+
else if (userConfigOrRoot) {
|
|
29
|
+
config = userConfigOrRoot;
|
|
30
|
+
cspellOptions = userConfigOrRoot.lint?.cspellOptions;
|
|
29
31
|
}
|
|
30
|
-
const cspellEnabled =
|
|
32
|
+
const cspellEnabled = userConfigOrRoot !== null;
|
|
31
33
|
return defineConfig([
|
|
32
34
|
{
|
|
33
35
|
ignores: ['**/.yarn', '**/dist', '**/lib', '**/node_modules'],
|
|
@@ -46,7 +48,7 @@ async function doom(cspellOptionsOrRoot) {
|
|
|
46
48
|
},
|
|
47
49
|
},
|
|
48
50
|
{
|
|
49
|
-
files: ['
|
|
51
|
+
files: [`**/${config?.lang ?? 'en'}/**/*.{js,jsx,md,mdx,ts,tsx}`],
|
|
50
52
|
extends: cspellEnabled ? [cspellRecommended] : [],
|
|
51
53
|
languageOptions: {
|
|
52
54
|
globals: globals.browser,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { logger } from '@rspress/core';
|
|
4
|
-
import { loadFrontMatter } from '@rspress/shared/node-utils';
|
|
5
|
-
import { extractTextAndId } from "../../shared/index.js";
|
|
4
|
+
import { extractTextAndId, loadFrontMatter } from '@rspress/shared/node-utils';
|
|
6
5
|
import { pathExists } from "../../utils/index.js";
|
|
7
6
|
export async function detectFilePath(rawPath, extensions) {
|
|
8
7
|
// The params doesn't have extension name, so we need to try to find the file with the extension name.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { h } from 'hastscript';
|
|
1
2
|
import { toMarkdown } from 'mdast-util-to-markdown';
|
|
2
3
|
import { visit } from 'unist-util-visit';
|
|
3
4
|
const CONTAINER_DIRECTIVE_TYPES = new Set([
|
|
@@ -18,14 +19,30 @@ export const remarkDirectives = function () {
|
|
|
18
19
|
node.type !== 'textDirective') {
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
|
-
const data = node.data || (node.data = {});
|
|
22
22
|
if (node.type === 'containerDirective' &&
|
|
23
23
|
CONTAINER_DIRECTIVE_TYPES.has(node.name)) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
+
const data = (node.data ||= {});
|
|
27
|
+
const setProperties = (className) => {
|
|
28
|
+
// https://github.com/syntax-tree/hastscript/pull/24
|
|
29
|
+
const n = h(data.hName || 'div', node.attributes);
|
|
30
|
+
data.hProperties = {
|
|
31
|
+
...n.properties,
|
|
32
|
+
className: [
|
|
33
|
+
...(n.properties.className || []),
|
|
34
|
+
className,
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
};
|
|
26
38
|
switch (node.name) {
|
|
27
39
|
case 'callouts': {
|
|
28
|
-
|
|
40
|
+
setProperties('doom-callouts');
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case 'callout': {
|
|
44
|
+
data.hName = 'span';
|
|
45
|
+
setProperties('doom-callout');
|
|
29
46
|
break;
|
|
30
47
|
}
|
|
31
48
|
default: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { extractTextAndId } from '@rspress/shared/node-utils';
|
|
1
2
|
import Slugger from 'github-slugger';
|
|
2
3
|
import { visitChildren } from 'unist-util-visit-children';
|
|
3
|
-
import { extractTextAndId } from "../../shared/index.js";
|
|
4
4
|
export const parseToc = (tree, allDepths) => {
|
|
5
5
|
let title = '';
|
|
6
6
|
const toc = [];
|
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
1
|
import path from 'node:path';
|
|
3
|
-
import { PluginDriver, RouteService, remarkLink
|
|
2
|
+
import { PluginDriver, RouteService, remarkLink } from '@rspress/core';
|
|
4
3
|
import { isProduction } from '@rspress/shared';
|
|
5
4
|
import { lintRule } from 'unified-lint-rule';
|
|
6
|
-
import {
|
|
7
|
-
import { OPTIONS_FILE } from "../utils/index.js";
|
|
8
|
-
let config;
|
|
9
|
-
let configFilePath;
|
|
5
|
+
import { getConfig } from "./utils.js";
|
|
10
6
|
export const checkDeadLinks = lintRule('doom-lint:check-dead-links', async (tree, vfile) => {
|
|
11
|
-
|
|
12
|
-
let optionsText;
|
|
13
|
-
try {
|
|
14
|
-
optionsText = await fs.readFile(OPTIONS_FILE, 'utf8');
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
//
|
|
18
|
-
}
|
|
19
|
-
const { root, globalOptions } = (optionsText ? JSON.parse(optionsText) : {});
|
|
20
|
-
({ config, configFilePath } = await loadConfig(root, globalOptions));
|
|
21
|
-
}
|
|
7
|
+
const { config, configFilePath } = await getConfig();
|
|
22
8
|
const relativePath = path.relative(config.root, vfile.path);
|
|
23
9
|
// Ignore files outside the root directory
|
|
24
10
|
if (relativePath.startsWith('..')) {
|
|
@@ -11,7 +11,9 @@ export * from './no-empty-table-cell.ts';
|
|
|
11
11
|
export * from './no-heading-punctuation.ts';
|
|
12
12
|
export * from './no-heading-special-characters.ts';
|
|
13
13
|
export * from './no-heading-sup-sub.ts';
|
|
14
|
+
export * from './no-multi-open-api-paths.ts';
|
|
14
15
|
export * from './no-paragraph-indent.ts';
|
|
16
|
+
export * from './no-unmatched-anchor.ts';
|
|
15
17
|
export * from './site.ts';
|
|
16
18
|
export * from './table-size.ts';
|
|
17
19
|
export * from './unit-case.ts';
|
package/lib/remark-lint/index.js
CHANGED
|
@@ -10,7 +10,9 @@ export * from "./no-empty-table-cell.js";
|
|
|
10
10
|
export * from "./no-heading-punctuation.js";
|
|
11
11
|
export * from "./no-heading-special-characters.js";
|
|
12
12
|
export * from "./no-heading-sup-sub.js";
|
|
13
|
+
export * from "./no-multi-open-api-paths.js";
|
|
13
14
|
export * from "./no-paragraph-indent.js";
|
|
15
|
+
export * from "./no-unmatched-anchor.js";
|
|
14
16
|
export * from "./site.js";
|
|
15
17
|
export * from "./table-size.js";
|
|
16
18
|
export * from "./unit-case.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toString } from 'mdast-util-to-string';
|
|
2
2
|
import { lintRule } from 'unified-lint-rule';
|
|
3
3
|
import { visitParents } from 'unist-util-visit-parents';
|
|
4
|
-
import { PUNCTUATION_REGEX } from "./
|
|
4
|
+
import { PUNCTUATION_REGEX } from "./utils.js";
|
|
5
5
|
const ALLOWED_PUNCTUATIONS = new Set([';', '.']);
|
|
6
6
|
export const listItemPunctuation = lintRule('doom-lint:list-item-punctuation', (root, vfile) => {
|
|
7
7
|
visitParents(root, 'list', (list, parents) => {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { extractTextAndId } from '@rspress/shared/node-utils';
|
|
1
2
|
import stringWidth from 'string-width';
|
|
2
3
|
import { lintRule } from 'unified-lint-rule';
|
|
3
|
-
import { visit } from 'unist-util-visit';
|
|
4
4
|
import { visitParents } from 'unist-util-visit-parents';
|
|
5
|
-
import { extractTextAndId } from "../shared/helpers.js";
|
|
6
5
|
const MAX_LENGTH = 40;
|
|
7
6
|
export const maximumLinkContentLength = lintRule('doom-lint:maximum-link-content-length', (root, vfile) => {
|
|
8
|
-
|
|
7
|
+
visitParents(root, ['link', 'linkReference'], (node, oParents) => {
|
|
9
8
|
visitParents(node, 'text', (text, parents) => {
|
|
10
9
|
let value = text.value;
|
|
11
10
|
try {
|
|
@@ -19,7 +18,7 @@ export const maximumLinkContentLength = lintRule('doom-lint:maximum-link-content
|
|
|
19
18
|
const length = stringWidth(value);
|
|
20
19
|
if (length > MAX_LENGTH) {
|
|
21
20
|
vfile.message(`Link content length \`${length}\` of \`${value}\` is too long, maximum is ${MAX_LENGTH} characters, please shorten it`, {
|
|
22
|
-
ancestors: [...parents, text],
|
|
21
|
+
ancestors: [...oParents, ...parents, text],
|
|
23
22
|
place: text.position,
|
|
24
23
|
});
|
|
25
24
|
}
|
|
@@ -2,7 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import { toString } from 'mdast-util-to-string';
|
|
3
3
|
import { lintRule } from 'unified-lint-rule';
|
|
4
4
|
import { visitParents } from 'unist-util-visit-parents';
|
|
5
|
-
import { PUNCTUATION_REGEX } from "./
|
|
5
|
+
import { PUNCTUATION_REGEX } from "./utils.js";
|
|
6
6
|
const QUESTION_MARKS = new Set(['?', '?']);
|
|
7
7
|
export const noHeadingPunctuation = lintRule('doom-lint:no-heading-punctuation', (root, vfile) => {
|
|
8
8
|
const filename = path.basename(vfile.path, path.extname(vfile.path));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { lintRule } from 'unified-lint-rule';
|
|
2
|
+
import { visitParents } from 'unist-util-visit-parents';
|
|
3
|
+
export const noMultiOpenAPIPaths = lintRule('doom-lint:no-multi-open-api-paths', (root, vfile) => {
|
|
4
|
+
let count = 0;
|
|
5
|
+
visitParents(root, ['mdxJsxFlowElement', 'mdxJsxTextElement'], (element, parents) => {
|
|
6
|
+
if (element.name === 'OpenAPIPath' && ++count > 1) {
|
|
7
|
+
vfile.message('Multiple `OpenAPIPath` components are used in the same file, combine them into a single component by passing an array to the `path` prop instead', {
|
|
8
|
+
ancestors: [...parents, element],
|
|
9
|
+
place: element.position,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isExternalUrl, parseUrl } from '@rspress/shared';
|
|
4
|
+
import { extractTextAndId } from '@rspress/shared/node-utils';
|
|
5
|
+
import { lintRule } from 'unified-lint-rule';
|
|
6
|
+
import { visit } from 'unist-util-visit';
|
|
7
|
+
import { visitParents } from 'unist-util-visit-parents';
|
|
8
|
+
import { isDoc } from "../cli/helpers.js";
|
|
9
|
+
import { mdProcessor, mdxProcessor } from "../plugins/index.js";
|
|
10
|
+
import { getConfig } from "./utils.js";
|
|
11
|
+
const anchorsCache = new Map();
|
|
12
|
+
const astCache = new Map();
|
|
13
|
+
const getAnchors = (filepath) => {
|
|
14
|
+
if (anchorsCache.has(filepath)) {
|
|
15
|
+
return anchorsCache.get(filepath);
|
|
16
|
+
}
|
|
17
|
+
const anchors = new Set();
|
|
18
|
+
let ast = astCache.get(filepath);
|
|
19
|
+
if (!ast) {
|
|
20
|
+
const processor = filepath.endsWith('.mdx') ? mdxProcessor : mdProcessor;
|
|
21
|
+
ast = processor.parse(fs.readFileSync(filepath, 'utf-8'));
|
|
22
|
+
astCache.set(filepath, ast);
|
|
23
|
+
}
|
|
24
|
+
visit(ast, (node) => {
|
|
25
|
+
if (node.type === 'heading') {
|
|
26
|
+
visit(node, 'text', (text) => {
|
|
27
|
+
const [, id] = extractTextAndId(text.value);
|
|
28
|
+
if (id) {
|
|
29
|
+
anchors.add(id);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else if (node.type === 'mdxJsxFlowElement' ||
|
|
34
|
+
node.type === 'mdxJsxTextElement') {
|
|
35
|
+
for (const attr of node.attributes) {
|
|
36
|
+
if (attr.type === 'mdxJsxAttribute' && attr.name === 'id') {
|
|
37
|
+
if (typeof attr.value === 'string') {
|
|
38
|
+
anchors.add(attr.value);
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (node.type === 'html') {
|
|
45
|
+
const matched = node.value.match(
|
|
46
|
+
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
|
47
|
+
/<[a-z]+(?:\s+[^>]*?)?\sid=(["'])([\s\S]*?)\1/iu);
|
|
48
|
+
if (matched) {
|
|
49
|
+
anchors.add(matched[2]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
anchorsCache.set(filepath, anchors);
|
|
54
|
+
return anchors;
|
|
55
|
+
};
|
|
56
|
+
export const noUnmatchedAnchor = lintRule('doom-lint:no-unmatched-anchor', async (root, vfile) => {
|
|
57
|
+
const { config } = await getConfig();
|
|
58
|
+
const filepath = vfile.path;
|
|
59
|
+
const dirpath = path.dirname(filepath);
|
|
60
|
+
const configRoot = config.root;
|
|
61
|
+
const configLang = config.lang;
|
|
62
|
+
const relativePath = path.relative(configRoot, filepath);
|
|
63
|
+
// Ignore files outside the root directory
|
|
64
|
+
if (relativePath.startsWith('..')) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
astCache.set(filepath, root);
|
|
68
|
+
visitParents(root, (node, parents) => {
|
|
69
|
+
let url;
|
|
70
|
+
if (node.type === 'link' || node.type === 'definition') {
|
|
71
|
+
url = node.url;
|
|
72
|
+
}
|
|
73
|
+
else if ((node.type === 'mdxJsxFlowElement' ||
|
|
74
|
+
node.type === 'mdxJsxTextElement') &&
|
|
75
|
+
node.name === 'a') {
|
|
76
|
+
for (const attr of node.attributes) {
|
|
77
|
+
if (attr.type === 'mdxJsxAttribute' && attr.name === 'href') {
|
|
78
|
+
if (typeof attr.value === 'string') {
|
|
79
|
+
url = attr.value;
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (node.type === 'html') {
|
|
86
|
+
const matched = node.value.match(
|
|
87
|
+
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
|
88
|
+
/<a\s+(?:[^>]*?\s)?href=(["'])([\s\S]*?)\1/iu);
|
|
89
|
+
if (matched) {
|
|
90
|
+
url = matched[2];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (!url || isExternalUrl(url) || !url.includes('#')) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const { url: parsedUrl, hash } = parseUrl(url);
|
|
97
|
+
let refFilepath = filepath;
|
|
98
|
+
if (parsedUrl.startsWith('/')) {
|
|
99
|
+
refFilepath = path.resolve(configRoot, configLang + parsedUrl);
|
|
100
|
+
}
|
|
101
|
+
else if (parsedUrl) {
|
|
102
|
+
refFilepath = path.resolve(dirpath, parsedUrl);
|
|
103
|
+
}
|
|
104
|
+
let ext = path.extname(refFilepath);
|
|
105
|
+
if (ext === '.html') {
|
|
106
|
+
refFilepath = refFilepath.slice(0, -ext.length);
|
|
107
|
+
ext = '';
|
|
108
|
+
}
|
|
109
|
+
if (!ext) {
|
|
110
|
+
for (const ext of ['.md', '.mdx']) {
|
|
111
|
+
if (fs.existsSync(refFilepath + ext)) {
|
|
112
|
+
refFilepath += ext;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!isDoc(refFilepath)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// If the referenced file does not exist, we ignore it here and let the `check-dead-links` rule handle it
|
|
121
|
+
if (filepath !== refFilepath && !fs.existsSync(refFilepath)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const relativeRefPath = path.relative(configRoot, refFilepath);
|
|
125
|
+
// We ignore API docs because their anchors are generated dynamically and may not be present in the source files
|
|
126
|
+
if (relativeRefPath.startsWith(`${configLang}/apis/`)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const anchors = getAnchors(refFilepath);
|
|
130
|
+
if (!anchors.has(hash)) {
|
|
131
|
+
vfile.message(`Unmatched anchor \`${hash}\` in link \`${url}\`, make sure the target has the correct id with \`{#${hash}}\` in heading or \`<a id="${hash}"></a>\` element.`, { ancestors: [...parents, node], place: node.position });
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
package/lib/remark-lint/site.js
CHANGED
|
@@ -11,7 +11,7 @@ const SITE_ELEMENTS = new Set([
|
|
|
11
11
|
]);
|
|
12
12
|
const sitesConfigFilePath = path.resolve(SITES_FILE);
|
|
13
13
|
let sites;
|
|
14
|
-
export const site = lintRule('doom:
|
|
14
|
+
export const site = lintRule('doom-lint:site', async (root, vfile) => {
|
|
15
15
|
if (!sites) {
|
|
16
16
|
if (await pathExists(sitesConfigFilePath, 'file')) {
|
|
17
17
|
sites = await resolveStaticConfig(sitesConfigFilePath);
|
|
@@ -20,7 +20,7 @@ export const site = lintRule('doom:lint-site', async (root, vfile) => {
|
|
|
20
20
|
sites = [];
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
visitParents(root, 'mdxJsxFlowElement', (element, parents) => {
|
|
23
|
+
visitParents(root, ['mdxJsxFlowElement', 'mdxJsxTextElement'], (element, parents) => {
|
|
24
24
|
if (!sites?.length || !element.name || !SITE_ELEMENTS.has(element.name)) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { loadConfig } from "../cli/load-config.js";
|
|
3
|
+
import { OPTIONS_FILE } from "../utils/index.js";
|
|
4
|
+
export const PUNCTUATION_REGEX = /\p{P}/u;
|
|
5
|
+
let config;
|
|
6
|
+
let configFilePath;
|
|
7
|
+
export async function getConfig() {
|
|
8
|
+
if (!config || !configFilePath) {
|
|
9
|
+
let optionsText;
|
|
10
|
+
try {
|
|
11
|
+
optionsText = await fs.readFile(OPTIONS_FILE, 'utf8');
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
//
|
|
15
|
+
}
|
|
16
|
+
const { root, globalOptions } = (optionsText ? JSON.parse(optionsText) : {});
|
|
17
|
+
({ config, configFilePath } = await loadConfig(root, globalOptions));
|
|
18
|
+
}
|
|
19
|
+
return { config, configFilePath };
|
|
20
|
+
}
|
package/lib/remarkrc.js
CHANGED
|
@@ -10,7 +10,7 @@ import remarkLintLintMatchPunctuation from 'remark-lint-match-punctuation';
|
|
|
10
10
|
import remarkLintNoChinesePunctuationInNumber from 'remark-lint-no-chinese-punctuation-in-number';
|
|
11
11
|
import remarkLintNoDuplicateHeadingsInSection from 'remark-lint-no-duplicate-headings-in-section';
|
|
12
12
|
import remarkLintNoHiddenTableCell from 'remark-lint-no-hidden-table-cell';
|
|
13
|
-
import doomLint, { checkDeadLinks, noDeepHeading, noDeepList, noParagraphIndent, site, tableSize, unitCase, } from "./remark-lint/index.js";
|
|
13
|
+
import doomLint, { checkDeadLinks, noDeepHeading, noDeepList, noMultiOpenAPIPaths, noParagraphIndent, noUnmatchedAnchor, site, tableSize, unitCase, } from "./remark-lint/index.js";
|
|
14
14
|
export default {
|
|
15
15
|
plugins: [
|
|
16
16
|
remarkDirective,
|
|
@@ -26,7 +26,9 @@ export default {
|
|
|
26
26
|
checkDeadLinks,
|
|
27
27
|
noDeepHeading,
|
|
28
28
|
noDeepList,
|
|
29
|
+
noMultiOpenAPIPaths,
|
|
29
30
|
noParagraphIndent,
|
|
31
|
+
noUnmatchedAnchor,
|
|
30
32
|
site,
|
|
31
33
|
tableSize,
|
|
32
34
|
unitCase,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export interface CalloutProps extends HTMLAttributes<HTMLSpanElement> {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export declare const Callout: ({ className, children, ...props }: CalloutProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export default Callout;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
export const Callout = ({ className, children, ...props }) => {
|
|
4
|
+
return (_jsx("span", { className: clsx('doom-callout', className), ...props, children: children }));
|
|
5
|
+
};
|
|
6
|
+
export default Callout;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
export interface CalloutsProps {
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export interface CalloutsProps extends HTMLAttributes<HTMLDivElement> {
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
}
|
|
5
|
-
export declare const Callouts: ({ children }: CalloutsProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare const Callouts: ({ className, children, ...props }: CalloutsProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
export default Callouts;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
export const Callouts = ({ className, children, ...props }) => {
|
|
4
|
+
return (_jsx("div", { className: clsx('doom-callouts', className), ...props, children: children }));
|
|
4
5
|
};
|
|
5
6
|
export default Callouts;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import BananaSlug from 'github-slugger';
|
|
1
2
|
import { type OpenAPIV3_1 } from 'openapi-types';
|
|
2
3
|
export interface OpenAPIPathProps {
|
|
3
4
|
/**
|
|
4
|
-
* The path under the OpenAPI schema `paths` definition.
|
|
5
|
+
* The path or paths under the OpenAPI schema `paths` definition.
|
|
5
6
|
*/
|
|
6
|
-
path: string;
|
|
7
|
+
path: string | string[];
|
|
7
8
|
/**
|
|
8
9
|
* The specific path to the OpenAPI schema, otherwise the first matched will be used.
|
|
9
10
|
*/
|
|
@@ -21,5 +22,11 @@ export declare const OpenAPIResponses: ({ responses, openapi, }: {
|
|
|
21
22
|
responses: OpenAPIV3_1.ResponsesObject;
|
|
22
23
|
openapi: OpenAPIV3_1.Document;
|
|
23
24
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
24
|
-
export
|
|
25
|
+
export interface OpenAPIPathBaseProps extends Omit<OpenAPIPathProps, 'openapiPath'> {
|
|
26
|
+
path: string;
|
|
27
|
+
pathItem?: OpenAPIV3_1.PathItemObject;
|
|
28
|
+
openapi?: OpenAPIV3_1.Document;
|
|
29
|
+
slugger: BananaSlug;
|
|
30
|
+
}
|
|
31
|
+
export declare const OpenAPIPath: ({ path, openapiPath, pathPrefix, }: OpenAPIPathProps) => import("react/jsx-runtime").JSX.Element;
|
|
25
32
|
export default OpenAPIPath;
|
|
@@ -5,14 +5,13 @@ import openapisMap from 'doom-@api-openapisMap';
|
|
|
5
5
|
import virtual from 'doom-@api-virtual';
|
|
6
6
|
import BananaSlug from 'github-slugger';
|
|
7
7
|
import { OpenAPIV3 } from 'openapi-types';
|
|
8
|
-
import { Fragment,
|
|
8
|
+
import { Fragment, useMemo } from 'react';
|
|
9
9
|
import { omitRoutePathRefs, resolveRef } from '../utils.js';
|
|
10
10
|
import { Markdown } from './Markdown.js';
|
|
11
11
|
import { OpenAPIProperties, OpenAPIProperty, OpenAPIRef } from './OpenAPIRef.js';
|
|
12
12
|
import { HeadingTitle } from './_HeadingTitle.js';
|
|
13
13
|
import { RefLink } from './_RefLink.js';
|
|
14
14
|
import { X } from './_X.js';
|
|
15
|
-
import { UidProvider } from './_context.js';
|
|
16
15
|
export const OpenAPIParameters = ({ parameters, openapi, }) => {
|
|
17
16
|
return (_jsx(X.ul, { children: parameters.map((param, index) => {
|
|
18
17
|
const paramObj = '$ref' in param
|
|
@@ -59,15 +58,14 @@ export const OpenAPIResponses = ({ responses, openapi, }) => {
|
|
|
59
58
|
return (_jsxs(X.li, { children: [_jsx("code", { children: code }), " ", typeNode, ": ", responseObj.description, extraNode] }, code));
|
|
60
59
|
}) }));
|
|
61
60
|
};
|
|
62
|
-
const
|
|
61
|
+
const setRefsForPath = (openapi, path, knownRefs, refs) => {
|
|
63
62
|
const pathSchema = openapi.paths?.[path];
|
|
64
63
|
if (!pathSchema) {
|
|
65
|
-
return
|
|
64
|
+
return;
|
|
66
65
|
}
|
|
67
|
-
const refs = new Set();
|
|
68
66
|
const collectRefs = (schema) => {
|
|
69
67
|
if ('$ref' in schema && typeof schema.$ref === 'string') {
|
|
70
|
-
const ref = schema.$ref.replace(
|
|
68
|
+
const ref = schema.$ref.replace(/^#\/components\/[^/]+\//, '');
|
|
71
69
|
if (!knownRefs[ref]) {
|
|
72
70
|
refs.add(ref);
|
|
73
71
|
schema = resolveRef(openapi, schema.$ref);
|
|
@@ -89,35 +87,14 @@ const getRefsForPath = (openapi, path, knownRefs) => {
|
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
}
|
|
92
|
-
return Array.from(refs);
|
|
93
90
|
};
|
|
94
|
-
|
|
95
|
-
const { page } = usePage();
|
|
91
|
+
const OpenAPIPathBase = ({ path, pathItem, openapi, pathPrefix: pathPrefix_, slugger, }) => {
|
|
96
92
|
const pathPrefix = pathPrefix_ ?? (virtual.pathPrefix || '');
|
|
97
|
-
const id = useId();
|
|
98
|
-
const slugger = useMemo(() => new BananaSlug(), []);
|
|
99
|
-
const [pathItem, openapi, openapiPath, refs] = useMemo(() => {
|
|
100
|
-
for (const [pathname, openapi] of Object.entries(openapisMap)) {
|
|
101
|
-
if (openapiPath_ && pathname !== openapiPath_) {
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const pathItem = openapi.paths?.[path];
|
|
105
|
-
if (pathItem) {
|
|
106
|
-
return [
|
|
107
|
-
pathItem,
|
|
108
|
-
openapi,
|
|
109
|
-
pathname,
|
|
110
|
-
getRefsForPath(openapi, path, omitRoutePathRefs(page.routePath)),
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return [];
|
|
115
|
-
}, [openapiPath_, page.routePath, path]);
|
|
116
93
|
if (!pathItem || !openapi) {
|
|
117
94
|
console.error(`No OpenAPI path definition found for ${path}`);
|
|
118
95
|
return null;
|
|
119
96
|
}
|
|
120
|
-
return (_jsxs(
|
|
97
|
+
return (_jsxs(_Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, level: 2, children: [pathPrefix, path] }), pathItem.parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 3, children: "Common Parameters" }), _jsx(OpenAPIParameters, { parameters: pathItem.parameters, openapi: openapi })] })), Object.values(OpenAPIV3.HttpMethods).map((method) => {
|
|
121
98
|
if (!pathItem[method]) {
|
|
122
99
|
return null;
|
|
123
100
|
}
|
|
@@ -134,8 +111,39 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
134
111
|
? resolveRef(openapi, requestBodyRef)
|
|
135
112
|
: undefined;
|
|
136
113
|
return (_jsxs(Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, level: 3, children: [_jsx("code", { children: method }), " ", summary] }), _jsx(Markdown, { children: description }), parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Parameters" }), _jsx(OpenAPIParameters, { parameters: parameters, openapi: openapi })] })), requestBodySchema && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Request Body" }), _jsxs(X.p, { children: [_jsx(RefLink, { "$ref": requestBodyRef }), requestBodySchema.required && _jsx(Badge, { children: "required" })] })] })), responses && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Response" }), _jsx(OpenAPIResponses, { responses: responses, openapi: openapi })] }))] }, method));
|
|
137
|
-
}), refs?.map((ref) => {
|
|
138
|
-
return (_jsx(OpenAPIRef, { schema: ref, openapiPath: openapiPath, isCommonRef: false, collectRefs: false }, ref));
|
|
139
114
|
})] }));
|
|
140
115
|
};
|
|
116
|
+
export const OpenAPIPath = ({ path, openapiPath, pathPrefix, }) => {
|
|
117
|
+
const { page } = usePage();
|
|
118
|
+
const { paths, pathMap, refMap } = useMemo(() => {
|
|
119
|
+
const paths = Array.isArray(path) ? path : [path];
|
|
120
|
+
const pathMap = new Map();
|
|
121
|
+
const refMap = new Map();
|
|
122
|
+
for (const [pathname, openapi] of Object.entries(openapisMap)) {
|
|
123
|
+
if (openapiPath && pathname !== openapiPath) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
for (const path of paths) {
|
|
127
|
+
const pathItem = openapi.paths?.[path];
|
|
128
|
+
if (pathItem) {
|
|
129
|
+
pathMap.set(path, {
|
|
130
|
+
pathItem,
|
|
131
|
+
openapi,
|
|
132
|
+
});
|
|
133
|
+
if (!refMap.has(pathname)) {
|
|
134
|
+
refMap.set(pathname, new Set());
|
|
135
|
+
}
|
|
136
|
+
const refs = refMap.get(pathname);
|
|
137
|
+
setRefsForPath(openapi, path, omitRoutePathRefs(page.routePath), refs);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { paths, pathMap, refMap };
|
|
142
|
+
}, [openapiPath, page.routePath, path]);
|
|
143
|
+
const slugger = useMemo(() => new BananaSlug(), []);
|
|
144
|
+
return (_jsxs(_Fragment, { children: [paths.map((path) => {
|
|
145
|
+
const p = pathMap.get(path);
|
|
146
|
+
return (_jsx(OpenAPIPathBase, { path: path, pathItem: p?.pathItem, openapi: p?.openapi, pathPrefix: pathPrefix, slugger: slugger }, path));
|
|
147
|
+
}), [...refMap.entries()].map(([openapiPath, refs]) => (_jsx(Fragment, { children: [...refs].map((ref) => (_jsx(OpenAPIRef, { schema: ref, openapiPath: openapiPath, collectRefs: false }, ref))) }, openapiPath)))] }));
|
|
148
|
+
};
|
|
141
149
|
export default OpenAPIPath;
|
|
@@ -8,12 +8,6 @@ export interface OpenAPIRefProps {
|
|
|
8
8
|
* The specific path to the OpenAPI schema, otherwise the first matched will be used.
|
|
9
9
|
*/
|
|
10
10
|
openapiPath?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Whether is a common reference, no `uid` will be generated.
|
|
13
|
-
*
|
|
14
|
-
* @default true
|
|
15
|
-
*/
|
|
16
|
-
isCommonRef?: boolean;
|
|
17
11
|
/**
|
|
18
12
|
* Whether to collect references from the schema.
|
|
19
13
|
*
|
|
@@ -31,5 +25,5 @@ export declare const OpenAPIProperties: ({ properties, openapi, }: {
|
|
|
31
25
|
properties: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject>;
|
|
32
26
|
openapi: OpenAPIV3_1.Document;
|
|
33
27
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
34
|
-
export declare const OpenAPIRef: ({ schema, openapiPath: openapiPath_,
|
|
28
|
+
export declare const OpenAPIRef: ({ schema, openapiPath: openapiPath_, collectRefs, }: OpenAPIRefProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
35
29
|
export default OpenAPIRef;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { usePage } from '@rspress/core/runtime';
|
|
3
3
|
import openapisMap from 'doom-@api-openapisMap';
|
|
4
|
-
import {
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
5
|
import { modelName, omitRoutePathRefs, resolveRef } from '../utils.js';
|
|
6
6
|
import { Markdown } from './Markdown.js';
|
|
7
7
|
import { HeadingTitle } from './_HeadingTitle.js';
|
|
8
8
|
import { RefLink } from './_RefLink.js';
|
|
9
9
|
import { X } from './_X.js';
|
|
10
|
-
import { UidProvider, useUid } from './_context.js';
|
|
11
10
|
export const get$Ref = (obj) => {
|
|
12
11
|
if ('$ref' in obj && obj.$ref) {
|
|
13
12
|
return obj.$ref;
|
|
@@ -78,7 +77,7 @@ const getRefsForSchema = (openapi, schema, knownRefs) => {
|
|
|
78
77
|
const refs = new Set();
|
|
79
78
|
const collectRefs = (schema) => {
|
|
80
79
|
if ('$ref' in schema && typeof schema.$ref === 'string') {
|
|
81
|
-
const ref = schema.$ref.replace(
|
|
80
|
+
const ref = schema.$ref.replace(/^#\/components\/[^/]+\//, '');
|
|
82
81
|
if (!knownRefs[ref]) {
|
|
83
82
|
refs.add(ref);
|
|
84
83
|
schema = resolveRef(openapi, schema.$ref);
|
|
@@ -93,23 +92,16 @@ const getRefsForSchema = (openapi, schema, knownRefs) => {
|
|
|
93
92
|
collectRefs(refSchema);
|
|
94
93
|
return Array.from(refs);
|
|
95
94
|
};
|
|
96
|
-
export const OpenAPIRef = ({ schema, openapiPath: openapiPath_,
|
|
95
|
+
export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, collectRefs = true, }) => {
|
|
97
96
|
const { page } = usePage();
|
|
98
|
-
let uid = useUid();
|
|
99
|
-
const innerId = useId();
|
|
100
|
-
if (isCommonRef) {
|
|
101
|
-
uid = ''; // common references do not need a unique ID
|
|
102
|
-
}
|
|
103
|
-
else if (!uid) {
|
|
104
|
-
uid = innerId;
|
|
105
|
-
}
|
|
106
97
|
// eslint-disable-next-line react-hooks/preserve-manual-memoization
|
|
107
98
|
const [schemaItem, openapi, openapiPath] = useMemo(() => {
|
|
108
99
|
for (const [pathname, openapi] of Object.entries(openapisMap)) {
|
|
109
100
|
if (openapiPath_ && pathname !== openapiPath_) {
|
|
110
101
|
continue;
|
|
111
102
|
}
|
|
112
|
-
const schemaItem = openapi
|
|
103
|
+
const schemaItem = resolveRef(openapi, schema);
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
113
105
|
if (schemaItem) {
|
|
114
106
|
return [schemaItem, openapi, pathname];
|
|
115
107
|
}
|
|
@@ -125,6 +117,6 @@ export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, isCommonRef = tr
|
|
|
125
117
|
console.error(`No OpenAPI schema definition found for ${schema}\n`);
|
|
126
118
|
return null;
|
|
127
119
|
}
|
|
128
|
-
return (_jsxs(
|
|
120
|
+
return (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slug: schema, level: 2, children: modelName(schema) }), _jsx(Markdown, { children: schemaItem.description }), schemaItem.properties && (_jsx(OpenAPIProperties, { properties: schemaItem.properties, openapi: openapi })), refs?.map((schema) => (_jsx(OpenAPIRef, { schema: schema, openapiPath: openapiPath, collectRefs: false }, schema)))] }));
|
|
129
121
|
};
|
|
130
122
|
export default OpenAPIRef;
|
|
@@ -2,10 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import BananaSlug from 'github-slugger';
|
|
3
3
|
import { Children, useMemo } from 'react';
|
|
4
4
|
import { X } from './_X.js';
|
|
5
|
-
import { useUid } from './_context.js';
|
|
6
5
|
// TODO: use context to simplify the usage of `slugger`
|
|
7
6
|
export const HeadingTitle = ({ slug, slugger, level, children, }) => {
|
|
8
|
-
const uid = useUid();
|
|
9
7
|
const HeadingComponents = useMemo(() => {
|
|
10
8
|
return [null, X.h1, X.h2, X.h3, X.h4, X.h5, X.h6];
|
|
11
9
|
}, []);
|
|
@@ -13,10 +11,9 @@ export const HeadingTitle = ({ slug, slugger, level, children, }) => {
|
|
|
13
11
|
const slugFromChildren = useMemo(() =>
|
|
14
12
|
// eslint-disable-next-line @eslint-react/no-children-to-array
|
|
15
13
|
Children.toArray(children)
|
|
16
|
-
.filter((it) => typeof it === 'string')
|
|
14
|
+
.filter((it) => typeof it === 'string' && !!it.trim())
|
|
17
15
|
.join(''), [children]);
|
|
18
|
-
const id = useMemo(() => [
|
|
19
|
-
|
|
20
|
-
.join('-') || undefined, [uid, slug, slugger, slugFromChildren]);
|
|
16
|
+
const id = useMemo(() => [slug || slugger?.slug(slugFromChildren)].filter(Boolean).join('-') ||
|
|
17
|
+
undefined, [slug, slugger, slugFromChildren]);
|
|
21
18
|
return (_jsxs(HeadingComponent, { id: id, children: [_jsx(X.a, { className: "rp-header-anchor", href: `#${id}`, "aria-hidden": true, children: "#" }), children] }));
|
|
22
19
|
};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { COMMON_REFS, modelName } from '../utils.js';
|
|
3
3
|
import { X } from './_X.js';
|
|
4
|
-
import { useUid } from './_context.js';
|
|
5
4
|
export const RefLink = ({ $ref }) => {
|
|
6
|
-
const uid = useUid();
|
|
7
5
|
if (!$ref) {
|
|
8
6
|
return null;
|
|
9
7
|
}
|
|
10
|
-
|
|
8
|
+
// #/components/schemas/, #/components/requestBodies/, etc.
|
|
9
|
+
const ref = $ref.replace(/^#\/components\/[^/]+\//, '#');
|
|
11
10
|
const plainRef = ref.slice(1);
|
|
12
11
|
const refName = modelName(plainRef);
|
|
13
|
-
return
|
|
12
|
+
return _jsx(X.a, { href: COMMON_REFS[plainRef] || ref, children: refName });
|
|
14
13
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { ComponentProps } from 'react';
|
|
1
2
|
export declare const X: {
|
|
3
|
+
a: (props: ComponentProps<"a">) => import("react/jsx-runtime").JSX.Element;
|
|
2
4
|
h1: (props: React.ComponentProps<"h1">) => import("react/jsx-runtime").JSX.Element;
|
|
3
5
|
h2: (props: React.ComponentProps<"h2">) => import("react/jsx-runtime").JSX.Element;
|
|
4
6
|
h3: (props: React.ComponentProps<"h3">) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -16,7 +18,6 @@ export declare const X: {
|
|
|
16
18
|
p: (props: import("react").ComponentProps<"p">) => import("react/jsx-runtime").JSX.Element;
|
|
17
19
|
blockquote: (props: import("react").ComponentProps<"blockquote">) => import("react/jsx-runtime").JSX.Element;
|
|
18
20
|
strong: (props: import("react").ComponentProps<"strong">) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
-
a: (props: import("react").ComponentProps<"a">) => import("react/jsx-runtime").JSX.Element;
|
|
20
21
|
code: typeof import("@rspress/core/dist/theme/components/DocContent/docComponents/code.js").Code;
|
|
21
22
|
img: (props: import("react").ComponentProps<"img">) => import("react/jsx-runtime").JSX.Element;
|
|
22
23
|
pre: typeof import("@rspress/core/dist/theme/components/DocContent/docComponents/pre.js").ShikiPre;
|
|
@@ -1,2 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { withBase } from '@rspress/core/runtime';
|
|
1
3
|
import { getCustomMDXComponent } from '@rspress/core/theme-original';
|
|
2
|
-
|
|
4
|
+
import { isExternalUrl, parseUrl } from '@rspress/shared';
|
|
5
|
+
import { clsx } from 'clsx';
|
|
6
|
+
const X_ = getCustomMDXComponent();
|
|
7
|
+
const DOWNLOAD_EXTENSIONS = [
|
|
8
|
+
'.ipynb',
|
|
9
|
+
'.zip',
|
|
10
|
+
'.tgz',
|
|
11
|
+
'.tar.gz',
|
|
12
|
+
'.sh',
|
|
13
|
+
'.py',
|
|
14
|
+
'.sql',
|
|
15
|
+
];
|
|
16
|
+
export const X = {
|
|
17
|
+
...X_,
|
|
18
|
+
a: (props) => {
|
|
19
|
+
const { className, href,
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
21
|
+
download, // type-coverage:ignore-line
|
|
22
|
+
...rest } = props;
|
|
23
|
+
if (href) {
|
|
24
|
+
const { url } = parseUrl(href);
|
|
25
|
+
const pathname = url.split('/').at(-1).toLowerCase();
|
|
26
|
+
if (download !== false && // type-coverage:ignore-line
|
|
27
|
+
DOWNLOAD_EXTENSIONS.some((ext) => pathname.endsWith(ext))) {
|
|
28
|
+
return (_jsx("a", { className: clsx('rp-link', className), href: isExternalUrl(href) ? href : withBase(href),
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
30
|
+
download: download ?? true, ...rest }));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return _jsx(X_.a, { ...props });
|
|
34
|
+
},
|
|
35
|
+
};
|
package/lib/shared/helpers.d.ts
CHANGED
|
@@ -5,10 +5,6 @@ export declare const getPdfName: (lang: string, userBase?: string, title?: strin
|
|
|
5
5
|
export declare const isExplicitlyUnversioned: (version?: string) => version is UnversionedVersion;
|
|
6
6
|
export declare const isUnversioned: (version?: string) => version is undefined | "" | UnversionedVersion;
|
|
7
7
|
export declare const getUnversionedVersion: (version?: string) => string | undefined;
|
|
8
|
-
/**
|
|
9
|
-
* hello world {#custom-id} -> { text: 'hello world', id: 'custom-id' }
|
|
10
|
-
*/
|
|
11
|
-
export declare const extractTextAndId: (title: string) => string[];
|
|
12
8
|
export declare const normalizeSlash: (url: string) => string;
|
|
13
9
|
export declare const withoutBase: (path: string, base: string) => string;
|
|
14
10
|
export declare const matchNavbar: (item: NavItemWithLink, currentPathname: string, base: string) => boolean;
|
package/lib/shared/helpers.js
CHANGED
|
@@ -12,18 +12,6 @@ export const getUnversionedVersion = (version) => {
|
|
|
12
12
|
? version.slice(UNVERSIONED_PREFIX.length)
|
|
13
13
|
: version;
|
|
14
14
|
};
|
|
15
|
-
/**
|
|
16
|
-
* hello world {#custom-id} -> { text: 'hello world', id: 'custom-id' }
|
|
17
|
-
*/
|
|
18
|
-
export const extractTextAndId = (title) => {
|
|
19
|
-
const customIdReg = /\\?\{#[^}]*\}/;
|
|
20
|
-
const text = title.replace(customIdReg, '').trimEnd();
|
|
21
|
-
const customId = title.match(customIdReg)?.[0]?.slice(2, -1) || '';
|
|
22
|
-
return [
|
|
23
|
-
text.replace(/\\{2}/g, '').replace(/(^|[^\\])\\([[\]])/g, '$1$2'),
|
|
24
|
-
customId,
|
|
25
|
-
];
|
|
26
|
-
};
|
|
27
15
|
export const normalizeSlash = (url) => removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
|
|
28
16
|
export const withoutBase = (path, base) => addLeadingSlash(path).replace(normalizeSlash(base), '');
|
|
29
17
|
export const matchNavbar = (item, currentPathname, base) => new RegExp(item.activeMatch || item.link).test(withoutBase(currentPathname, base));
|
|
@@ -23,7 +23,6 @@ const VersionsNav_ = () => {
|
|
|
23
23
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
24
24
|
const { nav } = useLocaleSiteData();
|
|
25
25
|
const configNav = useMemo(() => (Array.isArray(nav) ? nav : nav.default), [nav]);
|
|
26
|
-
const originalConfigNav = useMemo(() => [...configNav], [configNav]);
|
|
27
26
|
// hack to rerender nav when configNav is changed
|
|
28
27
|
const forceRender = useForceRender();
|
|
29
28
|
const lang = useLang();
|
|
@@ -72,11 +71,12 @@ const VersionsNav_ = () => {
|
|
|
72
71
|
navList.push({
|
|
73
72
|
text: t('download_pdf'),
|
|
74
73
|
link: downloadLink,
|
|
74
|
+
_hacked: true,
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
if (versionsBase == null) {
|
|
78
78
|
if (version) {
|
|
79
|
-
navList.push({ text: version, items: [] });
|
|
79
|
+
navList.push({ text: version, items: [], _hacked: true });
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
@@ -92,16 +92,17 @@ const VersionsNav_ = () => {
|
|
|
92
92
|
navList.push({
|
|
93
93
|
text: version,
|
|
94
94
|
items: versionItems,
|
|
95
|
+
_hacked: true,
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
return navList;
|
|
98
99
|
}, [downloadLink, t, version, versionsBase, versions]);
|
|
99
100
|
useEffect(() => {
|
|
100
101
|
// eslint-disable-next-line react-hooks/immutability
|
|
101
|
-
configNav.length =
|
|
102
|
+
configNav.length = configNav.filter((item) => !('_hacked' in item && item._hacked === true)).length;
|
|
102
103
|
configNav.push(...navList);
|
|
103
104
|
forceRender();
|
|
104
|
-
}, [configNav, forceRender, navList
|
|
105
|
+
}, [configNav, forceRender, navList]);
|
|
105
106
|
return null;
|
|
106
107
|
};
|
|
107
108
|
export const VersionsNav = () => (_jsx(NoSSR, { children: _jsx(VersionsNav_, {}) }));
|
package/lib/theme/index.d.ts
CHANGED
|
@@ -3,3 +3,26 @@ export { EditLink } from './EditLink.js';
|
|
|
3
3
|
export { Layout } from './Layout.js';
|
|
4
4
|
export { CodeBlock } from './CodeBlock.js';
|
|
5
5
|
export { Search } from './Search.js';
|
|
6
|
+
export declare const getCustomMDXComponent: () => {
|
|
7
|
+
a: (props: import("react").ComponentProps<"a">) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
h1: (props: React.ComponentProps<"h1">) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
h2: (props: React.ComponentProps<"h2">) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
h3: (props: React.ComponentProps<"h3">) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
h4: (props: React.ComponentProps<"h4">) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
h5: (props: React.ComponentProps<"h5">) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
h6: (props: React.ComponentProps<"h6">) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
ul: (props: import("react").ComponentProps<"ul">) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
ol: (props: import("react").ComponentProps<"ol">) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
li: (props: import("react").ComponentProps<"li">) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
table: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").TableHTMLAttributes<HTMLTableElement>, HTMLTableElement>, "ref"> & import("react").RefAttributes<HTMLTableElement>>;
|
|
18
|
+
td: (props: import("react").ComponentProps<"td">) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
th: (props: import("react").ComponentProps<"th">) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
tr: (props: import("react").ComponentProps<"tr">) => import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
hr: (props: import("react").ComponentProps<"hr">) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
p: (props: import("react").ComponentProps<"p">) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
blockquote: (props: import("react").ComponentProps<"blockquote">) => import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
strong: (props: import("react").ComponentProps<"strong">) => import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
code: typeof import("@rspress/core/dist/theme/components/DocContent/docComponents/code.js").Code;
|
|
26
|
+
img: (props: import("react").ComponentProps<"img">) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
pre: typeof import("@rspress/core/dist/theme/components/DocContent/docComponents/pre.js").ShikiPre;
|
|
28
|
+
};
|
package/lib/theme/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-disable import-x/export */
|
|
2
|
+
import { X } from '../runtime/components/_X.js';
|
|
2
3
|
export * from '@rspress/core/theme-original';
|
|
3
4
|
export { EditLink } from './EditLink.js';
|
|
4
5
|
export { Layout } from './Layout.js';
|
|
5
6
|
export { CodeBlock } from './CodeBlock.js';
|
|
6
7
|
export { Search } from './Search.js';
|
|
8
|
+
export const getCustomMDXComponent = () => X;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"eslint": "^9.39.3",
|
|
67
67
|
"eslint-plugin-mdx": "^3.7.0",
|
|
68
68
|
"globals": "^17.4.0",
|
|
69
|
+
"hastscript": "^9.0.1",
|
|
69
70
|
"html-tag-names": "^2.1.0",
|
|
70
71
|
"jsencrypt": "^3.5.4",
|
|
71
72
|
"masonry-layout": "^4.2.2",
|
|
@@ -108,7 +109,7 @@
|
|
|
108
109
|
"unist-util-position": "^5.0.0",
|
|
109
110
|
"unist-util-visit-parents": "^6.0.2",
|
|
110
111
|
"x-fetch": "^0.2.6",
|
|
111
|
-
"yaml": "^2.8.
|
|
112
|
+
"yaml": "^2.8.3",
|
|
112
113
|
"yoctocolors": "^2.1.2"
|
|
113
114
|
}
|
|
114
115
|
}
|
package/styles/global.scss
CHANGED
|
@@ -40,9 +40,7 @@ td {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
@mixin callout {
|
|
44
|
-
counter-increment: callouts;
|
|
45
|
-
content: counter(callouts);
|
|
43
|
+
@mixin callout-base {
|
|
46
44
|
border-radius: 50%;
|
|
47
45
|
background-color: #06c;
|
|
48
46
|
color: #fff;
|
|
@@ -52,6 +50,13 @@ td {
|
|
|
52
50
|
justify-content: center;
|
|
53
51
|
align-items: center;
|
|
54
52
|
margin-left: 4px;
|
|
53
|
+
margin-right: 4px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@mixin callout {
|
|
57
|
+
counter-increment: callouts;
|
|
58
|
+
content: counter(callouts);
|
|
59
|
+
@include callout-base;
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
.has-callouts {
|
|
@@ -94,6 +99,10 @@ td {
|
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
|
|
102
|
+
.doom-callout {
|
|
103
|
+
@include callout-base;
|
|
104
|
+
}
|
|
105
|
+
|
|
97
106
|
.doom-auto-toc {
|
|
98
107
|
@media (min-width: 1280px) {
|
|
99
108
|
display: none;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const PUNCTUATION_REGEX: RegExp;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const PUNCTUATION_REGEX = /\p{P}/u;
|