@alauda/doom 0.14.2 → 0.14.3
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/global.d.ts +1 -28
- package/lib/cli/export.js +4 -5
- package/lib/cli/index.js +3 -2
- package/lib/cli/load-config.d.ts +4 -3
- package/lib/cli/load-config.js +25 -22
- package/lib/cli/new.d.ts +1 -1
- package/lib/cli/new.js +1 -2
- package/lib/cli/translate.js +1 -2
- package/lib/config.d.ts +2 -2
- package/lib/global/SiteOverrides/index.d.ts +1 -2
- package/lib/global/SiteOverrides/index.js +1 -1
- package/lib/global/VersionsNav/NavMenuGroup.d.ts +2 -1
- package/lib/global/VersionsNav/NavMenuGroup.js +3 -5
- package/lib/global/VersionsNav/NavMenuSingleItem.d.ts +9 -8
- package/lib/global/VersionsNav/NavMenuSingleItem.js +7 -5
- package/lib/global/VersionsNav/index.d.ts +1 -2
- package/lib/global/VersionsNav/index.js +20 -8
- package/lib/plugins/api/index.d.ts +2 -1
- package/lib/plugins/api/index.js +4 -4
- package/lib/plugins/auto-sidebar/index.d.ts +3 -1
- package/lib/plugins/auto-sidebar/index.js +2 -1
- package/lib/plugins/auto-sidebar/type.d.ts +0 -2
- package/lib/plugins/auto-sidebar/walk.d.ts +2 -2
- package/lib/plugins/auto-sidebar/walk.js +2 -1
- package/lib/plugins/global/index.d.ts +7 -3
- package/lib/plugins/global/index.js +7 -5
- package/lib/plugins/permission/index.d.ts +2 -1
- package/lib/plugins/permission/index.js +3 -3
- package/lib/plugins/replace/index.d.ts +4 -5
- package/lib/plugins/replace/index.js +22 -19
- package/lib/plugins/replace/types.d.ts +1 -1
- package/lib/plugins/replace/utils.d.ts +1 -1
- package/lib/plugins/replace/utils.js +1 -1
- package/lib/runtime/hooks/useTranslation.d.ts +1 -1
- package/lib/runtime/index.js +2 -0
- package/lib/runtime/translation.d.ts +2 -0
- package/lib/runtime/translation.js +2 -0
- package/lib/shared/helpers.d.ts +2 -0
- package/lib/shared/helpers.js +2 -0
- package/lib/types.d.ts +30 -0
- package/lib/utils/helpers.d.ts +1 -2
- package/lib/utils/helpers.js +2 -3
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -1
- package/lib/utils/types.d.ts +14 -13
- package/package.json +3 -2
- package/lib/cli/export-pdf-core/utils/filterRoute.d.ts +0 -8
- package/lib/cli/export-pdf-core/utils/filterRoute.js +0 -11
- package/lib/cli/export-pdf-core/utils/timeTransformer.d.ts +0 -8
- package/lib/cli/export-pdf-core/utils/timeTransformer.js +0 -22
- package/lib/plugins/reference/index.d.ts +0 -10
- package/lib/plugins/reference/index.js +0 -60
- package/lib/plugins/reference/normalize-img-src.d.ts +0 -10
- package/lib/plugins/reference/normalize-img-src.js +0 -59
- package/lib/plugins/reference/parse-toc.d.ts +0 -17
- package/lib/plugins/reference/parse-toc.js +0 -51
- package/lib/plugins/reference/remark-normalize-link.d.ts +0 -12
- package/lib/plugins/reference/remark-normalize-link.js +0 -114
- package/lib/plugins/reference/remark-replace.d.ts +0 -16
- package/lib/plugins/reference/remark-replace.js +0 -172
- package/lib/plugins/reference/remark-toc.d.ts +0 -19
- package/lib/plugins/reference/remark-toc.js +0 -61
- package/lib/plugins/reference/resolve-reference.d.ts +0 -8
- package/lib/plugins/reference/resolve-reference.js +0 -134
- package/lib/plugins/reference/resolve-release.d.ts +0 -2
- package/lib/plugins/reference/resolve-release.js +0 -93
- package/lib/plugins/reference/types.d.ts +0 -32
- package/lib/plugins/reference/utils.d.ts +0 -14
- package/lib/plugins/reference/utils.js +0 -85
- package/lib/plugins/replace/remark-jsx-table.d.ts +0 -3
- package/lib/plugins/replace/remark-jsx-table.js +0 -10
- package/lib/runtime/components/CompanyBrand.d.ts +0 -2
- package/lib/runtime/components/CompanyBrand.js +0 -4
- package/lib/runtime/components/ProductBrand.d.ts +0 -2
- package/lib/runtime/components/ProductBrand.js +0 -4
- package/lib/runtime/components/ProductShortBrand.d.ts +0 -2
- package/lib/runtime/components/ProductShortBrand.js +0 -4
- package/lib/runtime/components/_BrandBase.d.ts +0 -5
- package/lib/runtime/components/_BrandBase.js +0 -7
- package/lib/runtime/components/_Directive.d.ts +0 -10
- package/lib/runtime/components/_Directive.js +0 -16
- package/lib/runtime/hooks/use.d.ts +0 -12
- package/lib/runtime/hooks/use.js +0 -37
- package/lib/runtime/types.d.ts +0 -5
- package/lib/runtime/types.js +0 -1
- package/lib/shared/constants.d.ts +0 -3
- package/lib/shared/constants.js +0 -6
- /package/lib/{plugins/reference/types.js → types.js} +0 -0
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
|
|
2
|
-
import { isExternalUrl, normalizeHref, parseUrl, slash } from '@rspress/shared';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { visit } from 'unist-util-visit';
|
|
5
|
-
import { getASTNodeImport } from './utils.js';
|
|
6
|
-
/**
|
|
7
|
-
* Remark plugin to normalize a link href
|
|
8
|
-
*/
|
|
9
|
-
export const remarkPluginNormalizeLink = ({ base, root, cleanUrls }) => (tree, file) => {
|
|
10
|
-
const images = [];
|
|
11
|
-
visit(tree, (node) => node.type === 'link', (node) => {
|
|
12
|
-
if (!node.url) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (node.url.startsWith('#')) {
|
|
16
|
-
node.url = `#${node.url.slice(1)}`;
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
// eslint-disable-next-line prefer-const
|
|
20
|
-
let { url, hash } = parseUrl(node.url);
|
|
21
|
-
if (isExternalUrl(url)) {
|
|
22
|
-
node.url = url + (hash ? `#${hash}` : '');
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const extname = path.extname(url);
|
|
26
|
-
if (extname === '.md' || extname === '.mdx') {
|
|
27
|
-
url = url.replace(extname, '');
|
|
28
|
-
}
|
|
29
|
-
const relativePath = path.relative(root, file.path);
|
|
30
|
-
if (url.startsWith('.')) {
|
|
31
|
-
url = path.posix.join(slash(path.dirname(relativePath)), url);
|
|
32
|
-
}
|
|
33
|
-
url = normalizeHref(url, cleanUrls);
|
|
34
|
-
if (hash) {
|
|
35
|
-
url += `#${hash}`;
|
|
36
|
-
}
|
|
37
|
-
node.url = path.posix.join(base, url);
|
|
38
|
-
});
|
|
39
|
-
const normalizeImageUrl = (imageUrl) => {
|
|
40
|
-
if (isExternalUrl(imageUrl) || imageUrl.startsWith('/')) {
|
|
41
|
-
return '';
|
|
42
|
-
}
|
|
43
|
-
return imageUrl;
|
|
44
|
-
};
|
|
45
|
-
const getMdxSrcAttrbute = (tempVar) => {
|
|
46
|
-
return {
|
|
47
|
-
type: 'mdxJsxAttribute',
|
|
48
|
-
name: 'src',
|
|
49
|
-
value: {
|
|
50
|
-
type: 'mdxJsxAttributeValueExpression',
|
|
51
|
-
value: tempVar,
|
|
52
|
-
data: {
|
|
53
|
-
estree: {
|
|
54
|
-
type: 'Program',
|
|
55
|
-
sourceType: 'module',
|
|
56
|
-
body: [
|
|
57
|
-
{
|
|
58
|
-
type: 'ExpressionStatement',
|
|
59
|
-
expression: {
|
|
60
|
-
type: 'Identifier',
|
|
61
|
-
name: tempVar,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
visit(tree, 'image', (node) => {
|
|
71
|
-
const { url } = node;
|
|
72
|
-
if (!url) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const imagePath = normalizeImageUrl(url);
|
|
76
|
-
if (!imagePath) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
// relative path
|
|
80
|
-
const tempVariableName = `image${images.length}`;
|
|
81
|
-
Object.assign(node, {
|
|
82
|
-
type: 'mdxJsxFlowElement',
|
|
83
|
-
name: 'img',
|
|
84
|
-
children: [],
|
|
85
|
-
attributes: [
|
|
86
|
-
node.alt && {
|
|
87
|
-
type: 'mdxJsxAttribute',
|
|
88
|
-
name: 'alt',
|
|
89
|
-
value: node.alt,
|
|
90
|
-
},
|
|
91
|
-
getMdxSrcAttrbute(tempVariableName),
|
|
92
|
-
].filter(Boolean),
|
|
93
|
-
});
|
|
94
|
-
images.push(getASTNodeImport(tempVariableName, imagePath));
|
|
95
|
-
});
|
|
96
|
-
visit(tree, ['mdxJsxFlowElement', 'mdxJsxTextElement'], (node) => {
|
|
97
|
-
// get all img src
|
|
98
|
-
if (node.name !== 'img') {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const src = node.attributes.find((attr) => attr.name === 'src');
|
|
102
|
-
if (!src?.value || typeof src?.value !== 'string') {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const imagePath = normalizeImageUrl(src.value);
|
|
106
|
-
if (!imagePath) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const tempVariableName = `image${images.length}`;
|
|
110
|
-
Object.assign(src, getMdxSrcAttrbute(tempVariableName));
|
|
111
|
-
images.push(getASTNodeImport(tempVariableName, imagePath));
|
|
112
|
-
});
|
|
113
|
-
tree.children.unshift(...images);
|
|
114
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Root } from 'mdast';
|
|
2
|
-
import { type Plugin } from 'unified';
|
|
3
|
-
import type { NormalizedReferenceSource, ReleaseNotesOptions } from './types.js';
|
|
4
|
-
export declare const MD_RELEASE_COMMENT_PATTERN: RegExp;
|
|
5
|
-
export declare const MDX_RELEASE_COMMENT_PATTERN: RegExp;
|
|
6
|
-
export declare const maybeHaveRef: (filepath: string, content: string) => boolean | undefined;
|
|
7
|
-
export declare const remarkReplace: Plugin<[
|
|
8
|
-
{
|
|
9
|
-
lang: string | null;
|
|
10
|
-
localBasePath: string;
|
|
11
|
-
root: string;
|
|
12
|
-
items: Record<string, NormalizedReferenceSource>;
|
|
13
|
-
force?: boolean;
|
|
14
|
-
releaseNotes?: ReleaseNotesOptions;
|
|
15
|
-
}
|
|
16
|
-
], Root>;
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { isProduction } from '@rspress/core';
|
|
4
|
-
import { logger } from '@rspress/shared/logger';
|
|
5
|
-
import { parse, stringify } from 'yaml';
|
|
6
|
-
import { cyan, red } from 'yoctocolors';
|
|
7
|
-
import { normalizeImgSrc } from './normalize-img-src.js';
|
|
8
|
-
import { getFrontmatterNode, mdProcessor, mdxProcessor } from './utils.js';
|
|
9
|
-
import { resolveReference } from './resolve-reference.js';
|
|
10
|
-
import { resolveRelease } from './resolve-release.js';
|
|
11
|
-
const MD_REF_START_COMMENT_PATTERN = /<!-{2,} *reference-start#(.+) *-{2,}>/;
|
|
12
|
-
const MDX_REF_START_COMMENT_PATTERN = /{\/\*+ *reference-start#(.+) *\*+\/}/;
|
|
13
|
-
const MDX_REF_START_PATTERN = /\/\*+ *reference-start#(.+) *\*+\//;
|
|
14
|
-
const MD_REF_END_COMMENT_PATTERN = /<!-{2,} *reference-end *-{2,}>/;
|
|
15
|
-
const MDX_REF_END_PATTERN = /\/\*+ *reference-end *\*+\//;
|
|
16
|
-
export const MD_RELEASE_COMMENT_PATTERN = /<!-{2,} *release-notes-for-bugs\?(.+) *-{2,}>/;
|
|
17
|
-
export const MDX_RELEASE_COMMENT_PATTERN = /{\/\*+ *release-notes-for-bugs\?(.+) *\*+\/}/;
|
|
18
|
-
const MDX_RELEASE_PATTERN = /\/\*+ *release-notes-for-bugs\?(.+) *\*+\//;
|
|
19
|
-
export const maybeHaveRef = (filepath, content) => {
|
|
20
|
-
if (!/\.mdx?$/.test(filepath)) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
return (filepath.endsWith('.mdx')
|
|
24
|
-
? [MDX_REF_START_COMMENT_PATTERN, MDX_RELEASE_COMMENT_PATTERN]
|
|
25
|
-
: [MD_REF_START_COMMENT_PATTERN, MD_RELEASE_COMMENT_PATTERN]).some((p) => p.test(content));
|
|
26
|
-
};
|
|
27
|
-
const { CI } = process.env;
|
|
28
|
-
const isCi = CI !== 'false' && !!CI;
|
|
29
|
-
export const remarkReplace = function ({ lang, localBasePath, root, items, force, releaseNotes }) {
|
|
30
|
-
return async (ast, vfile) => {
|
|
31
|
-
const filepath = vfile.path;
|
|
32
|
-
let content = vfile.toString();
|
|
33
|
-
if (!maybeHaveRef(filepath, content)) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const localPublicBase = path.resolve(root, 'public');
|
|
37
|
-
const targetBase = path.dirname(filepath);
|
|
38
|
-
const isMdx = filepath.endsWith('.mdx');
|
|
39
|
-
const processor = isMdx ? mdxProcessor : mdProcessor;
|
|
40
|
-
const originalAst = vfile.data.original
|
|
41
|
-
? ast
|
|
42
|
-
: processor.parse((content = await fs.readFile(filepath, 'utf8')));
|
|
43
|
-
const frontmatterNode = getFrontmatterNode(originalAst);
|
|
44
|
-
let frontmatter = frontmatterNode &&
|
|
45
|
-
parse(frontmatterNode.value);
|
|
46
|
-
const newContentChildren = [];
|
|
47
|
-
let start = false;
|
|
48
|
-
let refName = '';
|
|
49
|
-
let matched;
|
|
50
|
-
let checkContent = false;
|
|
51
|
-
const relativePath = path.relative(root, filepath);
|
|
52
|
-
for (const node of originalAst.children) {
|
|
53
|
-
if (node.type !== (isMdx ? 'mdxFlowExpression' : 'html')) {
|
|
54
|
-
if (node.type === 'yaml') {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (!start) {
|
|
58
|
-
newContentChildren.push(node);
|
|
59
|
-
}
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if ((matched = node.value.match(isMdx ? MDX_REF_START_PATTERN : MD_REF_START_COMMENT_PATTERN))) {
|
|
63
|
-
if (start) {
|
|
64
|
-
logger.warn(`Invalid reference start block ${red(node.value)}, nested reference blocks are not allowed`);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
checkContent = true;
|
|
68
|
-
start = true;
|
|
69
|
-
refName = matched[1].trim();
|
|
70
|
-
}
|
|
71
|
-
newContentChildren.push(node);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if ((isMdx ? MDX_REF_END_PATTERN : MD_REF_END_COMMENT_PATTERN).test(node.value)) {
|
|
75
|
-
if (start) {
|
|
76
|
-
start = false;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
logger.warn(`Invalid reference end block ${red(node.value)}, no matching start block found`);
|
|
80
|
-
}
|
|
81
|
-
const resolved = await resolveReference(localBasePath, localPublicBase, items, refName, force);
|
|
82
|
-
if (resolved) {
|
|
83
|
-
const refSource = items[refName];
|
|
84
|
-
const { frontmatterMode } = refSource;
|
|
85
|
-
for (const nodeItem of resolved.contents) {
|
|
86
|
-
if (nodeItem.type !== 'yaml') {
|
|
87
|
-
newContentChildren.push(normalizeImgSrc(nodeItem, {
|
|
88
|
-
refSource,
|
|
89
|
-
localPublicBase,
|
|
90
|
-
targetBase,
|
|
91
|
-
publicBase: resolved.publicBase,
|
|
92
|
-
sourceBase: resolved.sourceBase,
|
|
93
|
-
force,
|
|
94
|
-
}));
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
if (!frontmatterMode || frontmatterMode === 'ignore') {
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
if (frontmatterMode === 'remove') {
|
|
101
|
-
frontmatter = null;
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const data = parse(nodeItem.value);
|
|
105
|
-
if (frontmatterMode === 'merge') {
|
|
106
|
-
if (data) {
|
|
107
|
-
frontmatter = {
|
|
108
|
-
...frontmatter,
|
|
109
|
-
...data,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
113
|
-
}
|
|
114
|
-
else if (frontmatterMode === 'replace') {
|
|
115
|
-
frontmatter = data;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
newContentChildren.push(node);
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (!start) {
|
|
123
|
-
newContentChildren.push(node);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (start) {
|
|
127
|
-
logger.warn(`Invalid reference start block ${red(refName)}, no matching end block found, adding for you`);
|
|
128
|
-
newContentChildren.push({
|
|
129
|
-
type: isMdx ? 'mdxFlowExpression' : 'html',
|
|
130
|
-
value: isMdx ? '/* reference-end */' : '<!-- reference-end -->',
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
if (frontmatter) {
|
|
134
|
-
newContentChildren.unshift({
|
|
135
|
-
type: 'yaml',
|
|
136
|
-
value: stringify(frontmatter).trim(),
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
if (checkContent) {
|
|
140
|
-
const newContent = processor.stringify({
|
|
141
|
-
...ast,
|
|
142
|
-
children: newContentChildren.flat(),
|
|
143
|
-
});
|
|
144
|
-
if (content !== newContent) {
|
|
145
|
-
await fs.writeFile(filepath, newContent);
|
|
146
|
-
if (!vfile.data.original && isProduction()) {
|
|
147
|
-
const message = `Reference block in \`${cyan(relativePath)}\` has been updated, please commit the changes`;
|
|
148
|
-
if (isCi) {
|
|
149
|
-
process.env.__DOOM_REBUILD__ = 'true';
|
|
150
|
-
}
|
|
151
|
-
logger.warn(message);
|
|
152
|
-
}
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
const newAstChildren = [];
|
|
157
|
-
const currLang = lang === null ? 'zh' : relativePath.split('/')[0];
|
|
158
|
-
for (const node of ast.children) {
|
|
159
|
-
if (node.type !== (isMdx ? 'mdxFlowExpression' : 'html')) {
|
|
160
|
-
newAstChildren.push(node);
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
if ((matched = node.value.match(isMdx ? MDX_RELEASE_PATTERN : MD_RELEASE_COMMENT_PATTERN))) {
|
|
164
|
-
const releaseContent = await resolveRelease(releaseNotes?.queryTemplates ?? {}, matched[1].trim(), currLang);
|
|
165
|
-
newAstChildren.push(releaseContent ?? node);
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
newAstChildren.push(node);
|
|
169
|
-
}
|
|
170
|
-
ast.children = newAstChildren.flat();
|
|
171
|
-
};
|
|
172
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Root } from 'mdast';
|
|
2
|
-
import type { Plugin } from 'unified';
|
|
3
|
-
export interface TocItem {
|
|
4
|
-
id: string;
|
|
5
|
-
text: string;
|
|
6
|
-
depth: number;
|
|
7
|
-
index: number;
|
|
8
|
-
}
|
|
9
|
-
export interface PageMeta {
|
|
10
|
-
toc: TocItem[];
|
|
11
|
-
title: string;
|
|
12
|
-
headingTitle: string;
|
|
13
|
-
frontmatter?: Record<string, unknown>;
|
|
14
|
-
}
|
|
15
|
-
export declare const parseToc: (tree: Root, allDepths?: boolean) => {
|
|
16
|
-
title: string;
|
|
17
|
-
toc: TocItem[];
|
|
18
|
-
};
|
|
19
|
-
export declare const remarkPluginToc: Plugin<[], Root>;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import Slugger from 'github-slugger';
|
|
2
|
-
import { visitChildren } from 'unist-util-visit-children';
|
|
3
|
-
import { extractTextAndId } from './utils.js';
|
|
4
|
-
export const parseToc = (tree, allDepths) => {
|
|
5
|
-
let title = '';
|
|
6
|
-
const toc = [];
|
|
7
|
-
const slugger = new Slugger();
|
|
8
|
-
visitChildren((node, index) => {
|
|
9
|
-
if (node.type !== 'heading' || !node.depth || !node.children) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
// Collect h1 ~ h4 by default
|
|
13
|
-
if (allDepths || node.depth < 5) {
|
|
14
|
-
let customId = '';
|
|
15
|
-
const text = node.children
|
|
16
|
-
.map((child) => {
|
|
17
|
-
if (child.type === 'link') {
|
|
18
|
-
return child.children?.map((item) => item.value).join('');
|
|
19
|
-
}
|
|
20
|
-
if (child.type === 'strong') {
|
|
21
|
-
return `**${child.children?.map((item) => item.value).join('')}**`;
|
|
22
|
-
}
|
|
23
|
-
if (child.type === 'text') {
|
|
24
|
-
const [textPart, idPart] = extractTextAndId(child.value);
|
|
25
|
-
customId = idPart;
|
|
26
|
-
return textPart;
|
|
27
|
-
}
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
29
|
-
if (child.type === 'inlineCode') {
|
|
30
|
-
return `\`${child.value}\``;
|
|
31
|
-
}
|
|
32
|
-
return '';
|
|
33
|
-
})
|
|
34
|
-
.join('');
|
|
35
|
-
if (!allDepths && node.depth === 1) {
|
|
36
|
-
if (!title) {
|
|
37
|
-
title = text;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
const id = customId ? customId : slugger.slug(text);
|
|
42
|
-
const { depth } = node;
|
|
43
|
-
toc.push({ id, text, depth, index });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
})(tree);
|
|
47
|
-
return {
|
|
48
|
-
title,
|
|
49
|
-
toc,
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
export const remarkPluginToc = function () {
|
|
53
|
-
const data = this.data();
|
|
54
|
-
return (tree) => {
|
|
55
|
-
const { toc, title } = parseToc(tree);
|
|
56
|
-
data.pageMeta.toc = toc;
|
|
57
|
-
if (title) {
|
|
58
|
-
data.pageMeta.title = title;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Content } from 'mdast';
|
|
2
|
-
import type { NormalizedReferenceSource } from './types.js';
|
|
3
|
-
export interface ResolveReferenceResult {
|
|
4
|
-
publicBase: string;
|
|
5
|
-
sourceBase: string;
|
|
6
|
-
contents: Content[];
|
|
7
|
-
}
|
|
8
|
-
export declare const resolveReference: (localBasePath: string, localPublicBase: string, items: Record<string, NormalizedReferenceSource>, refName: string, force?: boolean) => Promise<ResolveReferenceResult | undefined>;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { isProduction } from '@rspress/core';
|
|
5
|
-
import { logger } from '@rspress/shared/logger';
|
|
6
|
-
import { render } from 'ejs';
|
|
7
|
-
import { simpleGit } from 'simple-git';
|
|
8
|
-
import { cyan, red } from 'yoctocolors';
|
|
9
|
-
import { parseToc } from './parse-toc.js';
|
|
10
|
-
import { getFrontmatterNode, mdProcessor, mdxProcessor } from './utils.js';
|
|
11
|
-
const remotesFolder = path.resolve(os.homedir(), '.doom/remotes');
|
|
12
|
-
const refCache = new Map();
|
|
13
|
-
const resolveReference_ = async (localBasePath, localPublicBase, items, refName, force) => {
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
15
|
-
if (!items[refName]) {
|
|
16
|
-
logger.error(`Reference \`${red(refName)}\` not found`);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const source = items[refName];
|
|
20
|
-
let publicBase;
|
|
21
|
-
let sourcePath = source.path;
|
|
22
|
-
if (source.repo) {
|
|
23
|
-
const repoFolder = path.resolve(remotesFolder, source.slug);
|
|
24
|
-
let created = false;
|
|
25
|
-
try {
|
|
26
|
-
const stat = await fs.stat(path.resolve(repoFolder, '.git'));
|
|
27
|
-
if (stat.isDirectory()) {
|
|
28
|
-
created = true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
// ignore
|
|
33
|
-
}
|
|
34
|
-
if (!created) {
|
|
35
|
-
await fs.mkdir(repoFolder, { recursive: true });
|
|
36
|
-
}
|
|
37
|
-
const git = simpleGit(repoFolder);
|
|
38
|
-
if (!created) {
|
|
39
|
-
logger.info(`Cloning remote \`${cyan(source.slug)}\` repository...`);
|
|
40
|
-
await git.clone(source.repo, repoFolder, ['--depth', '1']);
|
|
41
|
-
}
|
|
42
|
-
if (force) {
|
|
43
|
-
logger.info(`Pulling latest changes for \`${cyan(source.slug)}\`...`);
|
|
44
|
-
await git.pull([
|
|
45
|
-
'--depth',
|
|
46
|
-
'1',
|
|
47
|
-
'--force',
|
|
48
|
-
'--rebase',
|
|
49
|
-
'--allow-unrelated-histories',
|
|
50
|
-
]);
|
|
51
|
-
}
|
|
52
|
-
publicBase = path.resolve(repoFolder, source.publicBase ?? 'docs/public');
|
|
53
|
-
sourcePath = path.resolve(repoFolder, sourcePath);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
publicBase = localPublicBase;
|
|
57
|
-
sourcePath = path.resolve(localBasePath, sourcePath);
|
|
58
|
-
}
|
|
59
|
-
let found = false;
|
|
60
|
-
try {
|
|
61
|
-
const stat = await fs.stat(sourcePath);
|
|
62
|
-
found = stat.isFile();
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
//
|
|
66
|
-
}
|
|
67
|
-
if (!found) {
|
|
68
|
-
logger.error(`Reference path \`${red(source.path)}\` for \`${red(source.name)}\` not found`);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
let content = await fs.readFile(sourcePath, 'utf8');
|
|
72
|
-
for (const processor of source.processors ?? []) {
|
|
73
|
-
switch (processor.type) {
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
75
|
-
case 'ejsTemplate': {
|
|
76
|
-
content = await render(content, { data: processor.data }, { async: true });
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const processor = (sourcePath.endsWith('.ejs')
|
|
82
|
-
? sourcePath.slice(0, -4)
|
|
83
|
-
: sourcePath).endsWith('.mdx')
|
|
84
|
-
? mdxProcessor
|
|
85
|
-
: mdProcessor;
|
|
86
|
-
const root = processor.parse(content);
|
|
87
|
-
const sourceBase = path.dirname(sourcePath);
|
|
88
|
-
if (!source.anchor) {
|
|
89
|
-
return {
|
|
90
|
-
publicBase,
|
|
91
|
-
sourceBase,
|
|
92
|
-
contents: root.children,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
const frontmatterNode = getFrontmatterNode(root);
|
|
96
|
-
const { toc } = parseToc(root, true);
|
|
97
|
-
const active = toc.find((it) => it.id === source.anchor) ??
|
|
98
|
-
toc.find((it) => it.text === source.anchor);
|
|
99
|
-
if (!active) {
|
|
100
|
-
logger.error(`Anchor \`${red(source.anchor)}\` not found in \`${red(source.name)}\``);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const nodes = frontmatterNode ? [frontmatterNode] : [];
|
|
104
|
-
for (let i = active.index, n = root.children.length; i < n; i++) {
|
|
105
|
-
if (i === active.index && (source.ignoreHeading ?? active.depth === 1)) {
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
const node = root.children[i];
|
|
109
|
-
if (node.type === 'heading' &&
|
|
110
|
-
node.depth <= active.depth &&
|
|
111
|
-
i > active.index) {
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
nodes.push(node);
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
publicBase,
|
|
118
|
-
sourceBase,
|
|
119
|
-
contents: nodes,
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
export const resolveReference = async (localBasePath, localPublicBase, items, refName, force) => {
|
|
123
|
-
if (refCache.has(refName)) {
|
|
124
|
-
return refCache.get(refName);
|
|
125
|
-
}
|
|
126
|
-
const resolving = resolveReference_(localBasePath, localPublicBase, items, refName, force);
|
|
127
|
-
refCache.set(refName, resolving);
|
|
128
|
-
if (!isProduction()) {
|
|
129
|
-
setTimeout(() => {
|
|
130
|
-
refCache.delete(refName);
|
|
131
|
-
}, 5_000);
|
|
132
|
-
}
|
|
133
|
-
return resolving;
|
|
134
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { logger } from '@rspress/shared/logger';
|
|
2
|
-
import { render } from 'ejs';
|
|
3
|
-
import { cyan, red } from 'yoctocolors';
|
|
4
|
-
const releaseCache = new Map();
|
|
5
|
-
const FIELD_MAPPER = {
|
|
6
|
-
zh: 'customfield_13800',
|
|
7
|
-
en: 'customfield_13801',
|
|
8
|
-
};
|
|
9
|
-
const { JIRA_TOKEN, JIRA_USERNAME, JIRA_PASSWORD } = process.env;
|
|
10
|
-
const issuesToMdast = (issues, lang) => {
|
|
11
|
-
return issues
|
|
12
|
-
.map((issue) => {
|
|
13
|
-
const description = ((lang !== 'en' && issue.fields[FIELD_MAPPER[lang]]) ||
|
|
14
|
-
issue.fields[FIELD_MAPPER.en])?.trim();
|
|
15
|
-
if (!description) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
type: 'listItem',
|
|
20
|
-
children: [
|
|
21
|
-
{
|
|
22
|
-
type: 'paragraph',
|
|
23
|
-
children: description
|
|
24
|
-
.split('\n')
|
|
25
|
-
.map((line) => {
|
|
26
|
-
return {
|
|
27
|
-
type: 'text',
|
|
28
|
-
value: line,
|
|
29
|
-
};
|
|
30
|
-
})
|
|
31
|
-
.reduce((acc, curr, index) => {
|
|
32
|
-
if (index === 0) {
|
|
33
|
-
return [curr];
|
|
34
|
-
}
|
|
35
|
-
return acc.concat({ type: 'html', value: '<br>' }, curr);
|
|
36
|
-
}, []),
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
};
|
|
40
|
-
})
|
|
41
|
-
.filter((_) => !!_);
|
|
42
|
-
};
|
|
43
|
-
const resolveRelease_ = async (releaseTemplates, releaseQuery) => {
|
|
44
|
-
const query = new URLSearchParams(releaseQuery);
|
|
45
|
-
const templateName = query.get('template');
|
|
46
|
-
if (!templateName) {
|
|
47
|
-
logger.error(`Release notes template not found for query \`${red(releaseQuery)}\``);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const template = releaseTemplates[templateName];
|
|
51
|
-
if (!template) {
|
|
52
|
-
logger.error(`Release notes template \`${red(templateName)}\` not found`);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
let Authorization;
|
|
56
|
-
if (JIRA_TOKEN) {
|
|
57
|
-
Authorization = `Bearer ${JIRA_TOKEN}`;
|
|
58
|
-
}
|
|
59
|
-
else if (JIRA_USERNAME && JIRA_PASSWORD) {
|
|
60
|
-
Authorization = `Basic ${Buffer.from(`${JIRA_USERNAME}:${JIRA_PASSWORD}`).toString('base64')}`;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
throw new Error('`JIRA_TOKEN` or `JIRA_USERNAME` and `JIRA_PASSWORD` environments must be set for fetching Jira issues');
|
|
64
|
-
}
|
|
65
|
-
const data = {};
|
|
66
|
-
for (const [key, value] of query.entries()) {
|
|
67
|
-
if (key === 'template') {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
data[key] = value;
|
|
71
|
-
}
|
|
72
|
-
const jql = await render(template, data, { async: true });
|
|
73
|
-
logger.info(`Fetching release notes for query \`${cyan(releaseQuery)}\``);
|
|
74
|
-
const res = await fetch(`https://jira.alauda.cn/rest/api/2/search?${new URLSearchParams({ jql })}`, { headers: { Authorization } });
|
|
75
|
-
if (!res.ok) {
|
|
76
|
-
logger.error(`Failed to fetch release notes for query \`${red(releaseQuery)}\` with status \`${res.status}\``);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const { issues } = (await res.json());
|
|
80
|
-
return ['en', 'zh'].reduce((acc, curr) => Object.assign(acc, {
|
|
81
|
-
[curr]: { type: 'list', children: issuesToMdast(issues, curr) },
|
|
82
|
-
}), {});
|
|
83
|
-
};
|
|
84
|
-
export const resolveRelease = async (releaseTemplates, releaseQuery, lang) => {
|
|
85
|
-
if (releaseCache.has(releaseQuery)) {
|
|
86
|
-
const cached = await releaseCache.get(releaseQuery);
|
|
87
|
-
return cached?.[lang] ?? cached?.en;
|
|
88
|
-
}
|
|
89
|
-
const resolving = resolveRelease_(releaseTemplates, releaseQuery);
|
|
90
|
-
releaseCache.set(releaseQuery, resolving);
|
|
91
|
-
const resolved = await resolving;
|
|
92
|
-
return resolved?.[lang] ?? resolved?.en;
|
|
93
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ContentProcessor } from '../../utils/types.js';
|
|
2
|
-
export interface ReferenceItemSource {
|
|
3
|
-
name: string;
|
|
4
|
-
path: string;
|
|
5
|
-
ignoreHeading?: boolean;
|
|
6
|
-
/**
|
|
7
|
-
* @default 'ignore'
|
|
8
|
-
*/
|
|
9
|
-
frontmatterMode?: 'ignore' | 'merge' | 'remove' | 'replace';
|
|
10
|
-
processors?: ContentProcessor[];
|
|
11
|
-
}
|
|
12
|
-
export interface ReferenceItem {
|
|
13
|
-
repo?: string;
|
|
14
|
-
publicBase?: string;
|
|
15
|
-
sources: ReferenceItemSource[];
|
|
16
|
-
}
|
|
17
|
-
export interface NormalizedReferenceSource extends ReferenceItemSource {
|
|
18
|
-
repo?: string;
|
|
19
|
-
publicBase?: string;
|
|
20
|
-
slug?: string;
|
|
21
|
-
anchor?: string;
|
|
22
|
-
}
|
|
23
|
-
export interface ReleaseNotesOptions {
|
|
24
|
-
queryTemplates: Record<string, string>;
|
|
25
|
-
}
|
|
26
|
-
export interface JiraIssue {
|
|
27
|
-
expand: string;
|
|
28
|
-
id: string;
|
|
29
|
-
self: string;
|
|
30
|
-
key: string;
|
|
31
|
-
fields: Partial<Record<string, string>>;
|
|
32
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Root, YAML } from 'mdast';
|
|
2
|
-
import type { MdxjsEsm } from 'mdast-util-mdxjs-esm';
|
|
3
|
-
import { type Options } from 'remark-stringify';
|
|
4
|
-
import type { NormalizedReferenceSource, ReferenceItem } from './types.js';
|
|
5
|
-
/**
|
|
6
|
-
* hello world {#custom-id} -> { text: 'hello world', id: 'custom-id' }
|
|
7
|
-
*/
|
|
8
|
-
export declare const extractTextAndId: (title: string) => string[];
|
|
9
|
-
export declare const normalizeReferenceItems: (items: ReferenceItem[]) => Record<string, NormalizedReferenceSource>;
|
|
10
|
-
export declare const getASTNodeImport: (name: string, from: string) => MdxjsEsm;
|
|
11
|
-
export declare const stringifySettings: Options;
|
|
12
|
-
export declare const mdProcessor: import("unified").FrozenProcessor<Root, Root, Root, string>;
|
|
13
|
-
export declare const mdxProcessor: import("unified").FrozenProcessor<Root, Root, Root, string>;
|
|
14
|
-
export declare const getFrontmatterNode: (ast: Root) => YAML | undefined;
|