@alauda/doom 0.6.13 → 0.7.0
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/load-config.js +10 -16
- package/lib/global/VersionsNav/index.js +5 -2
- package/lib/plugins/reference/index.d.ts +0 -1
- package/lib/plugins/reference/remark-replace.d.ts +1 -6
- package/lib/plugins/reference/remark-replace.js +29 -254
- package/lib/plugins/reference/resolve-reference.d.ts +8 -0
- package/lib/plugins/reference/resolve-reference.js +134 -0
- package/lib/plugins/reference/resolve-release.d.ts +2 -0
- package/lib/plugins/reference/resolve-release.js +93 -0
- package/lib/runtime/components/ExternalSite.d.ts +1 -1
- package/lib/runtime/components/ExternalSite.js +7 -11
- package/lib/runtime/components/ExternalSiteLink.d.ts +7 -0
- package/lib/runtime/components/ExternalSiteLink.js +23 -0
- package/lib/runtime/components/index.d.ts +1 -0
- package/lib/runtime/components/index.js +1 -0
- package/lib/shared/types.d.ts +4 -3
- package/package.json +1 -1
- package/styles/link.module.scss +25 -0
package/lib/cli/load-config.js
CHANGED
|
@@ -19,19 +19,10 @@ const zhLocaleConfig = {
|
|
|
19
19
|
prevPageText: '上一页',
|
|
20
20
|
nextPageText: '下一页',
|
|
21
21
|
};
|
|
22
|
-
const getCommonConfig = (config, cliRoot,
|
|
22
|
+
const getCommonConfig = (config, cliRoot, configFilePath, version, force) => {
|
|
23
23
|
const fallbackToZh = 'lang' in config && config.lang == null;
|
|
24
24
|
const root = resolveDocRoot(CWD, cliRoot, config.root);
|
|
25
|
-
let base = addLeadingSlash(config.base || '/');
|
|
26
|
-
if (version && version !== 'unversioned') {
|
|
27
|
-
base = removeTrailingSlash(base) + `/${version}`;
|
|
28
|
-
}
|
|
29
|
-
base = addTrailingSlash(base);
|
|
30
|
-
if (prefix) {
|
|
31
|
-
base = normalizeSlash(prefix) + base;
|
|
32
|
-
}
|
|
33
25
|
return {
|
|
34
|
-
base,
|
|
35
26
|
root,
|
|
36
27
|
lang: fallbackToZh ? 'zh' : config.lang,
|
|
37
28
|
route: {
|
|
@@ -72,7 +63,6 @@ const getCommonConfig = (config, cliRoot, prefix, configFilePath, version, force
|
|
|
72
63
|
version,
|
|
73
64
|
}),
|
|
74
65
|
referencePlugin({
|
|
75
|
-
base,
|
|
76
66
|
root,
|
|
77
67
|
lang: fallbackToZh ? null : (config.lang ?? 'en'),
|
|
78
68
|
localBasePath: configFilePath ? path.dirname(configFilePath) : root,
|
|
@@ -166,11 +156,18 @@ export async function loadConfig(root, configFile, prefix, version, force) {
|
|
|
166
156
|
}
|
|
167
157
|
}
|
|
168
158
|
const normalizedVersion = normalizeVersion(version);
|
|
169
|
-
const commonConfig = getCommonConfig(config, root,
|
|
159
|
+
const commonConfig = getCommonConfig(config, root, configFilePath, normalizedVersion, force);
|
|
170
160
|
const mergedConfig = mergeRsbuildConfig(commonConfig, config, {
|
|
171
|
-
base: commonConfig.base,
|
|
172
161
|
root: commonConfig.root,
|
|
173
162
|
});
|
|
163
|
+
let base = addLeadingSlash(mergedConfig.base || '/');
|
|
164
|
+
if (normalizedVersion && normalizedVersion !== 'unversioned') {
|
|
165
|
+
base = removeTrailingSlash(base) + `/${normalizedVersion}`;
|
|
166
|
+
}
|
|
167
|
+
mergedConfig.base = base = addTrailingSlash(base);
|
|
168
|
+
if (prefix) {
|
|
169
|
+
mergedConfig.base = normalizeSlash(prefix) + base;
|
|
170
|
+
}
|
|
174
171
|
let ensureDefaultLogo = false;
|
|
175
172
|
if (!mergedConfig.logo) {
|
|
176
173
|
mergedConfig.logo = DEFAULT_LOGO;
|
|
@@ -201,9 +198,6 @@ export async function loadConfig(root, configFile, prefix, version, force) {
|
|
|
201
198
|
addTrailingSlash(mergedConfig.outDir) + normalizedVersion;
|
|
202
199
|
}
|
|
203
200
|
else {
|
|
204
|
-
const base = prefix
|
|
205
|
-
? mergedConfig.base.replace(normalizeSlash(prefix), '')
|
|
206
|
-
: mergedConfig.base;
|
|
207
201
|
mergedConfig.outDir = `dist${normalizedVersion === 'unversioned' ? `/unversioned${base}` : base}`;
|
|
208
202
|
}
|
|
209
203
|
if (mergedConfig.builderConfig?.server?.open === true) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { isProduction, usePageData } from '@rspress/core/runtime';
|
|
2
|
+
import { isProduction, removeTrailingSlash, usePageData, } from '@rspress/core/runtime';
|
|
3
3
|
import { noop } from 'es-toolkit';
|
|
4
4
|
import { useEffect, useMemo, useState } from 'react';
|
|
5
5
|
import { createPortal } from 'react-dom';
|
|
@@ -11,7 +11,10 @@ export const VersionsNav = () => {
|
|
|
11
11
|
if (!page.v) {
|
|
12
12
|
return [];
|
|
13
13
|
}
|
|
14
|
-
return [
|
|
14
|
+
return [
|
|
15
|
+
removeTrailingSlash(siteData.base).slice(0, -page.v.length - 1),
|
|
16
|
+
page.v,
|
|
17
|
+
];
|
|
15
18
|
}, [siteData.base, page.v]);
|
|
16
19
|
const [navMenu, setNavMenu] = useState();
|
|
17
20
|
const [versions, setVersions] = useState();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { RspressPlugin } from '@rspress/core';
|
|
2
2
|
import type { ReferenceItem, ReleaseNotesOptions } from './types.js';
|
|
3
3
|
export declare const referencePlugin: ({ root, lang, localBasePath, items, force, releaseNotes, }: {
|
|
4
|
-
base: string;
|
|
5
4
|
root: string;
|
|
6
5
|
lang: string | null;
|
|
7
6
|
localBasePath: string;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
2
|
import { type Plugin } from 'unified';
|
|
3
3
|
import type { NormalizedReferenceSource, ReleaseNotesOptions } from './types.js';
|
|
4
|
-
export interface ResolveReferenceResult {
|
|
5
|
-
publicBase: string;
|
|
6
|
-
sourceBase: string;
|
|
7
|
-
contents: Content[];
|
|
8
|
-
}
|
|
9
4
|
export declare const MD_RELEASE_COMMENT_PATTERN: RegExp;
|
|
10
5
|
export declare const MDX_RELEASE_COMMENT_PATTERN: RegExp;
|
|
11
6
|
export declare const maybeHaveRef: (filepath: string, content: string) => boolean | undefined;
|
|
@@ -1,229 +1,13 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
-
import os from 'node:os';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
import { isProduction } from '@rspress/core';
|
|
5
4
|
import { logger } from '@rspress/shared/logger';
|
|
6
|
-
import { render } from 'ejs';
|
|
7
|
-
import { simpleGit } from 'simple-git';
|
|
8
5
|
import { parse, stringify } from 'yaml';
|
|
9
6
|
import { cyan, red } from 'yoctocolors';
|
|
10
7
|
import { normalizeImgSrc } from './normalize-img-src.js';
|
|
11
|
-
import { parseToc } from './parse-toc.js';
|
|
12
8
|
import { getFrontmatterNode, mdProcessor, mdxProcessor } from './utils.js';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const resolveReference_ = async (localBasePath, localPublicBase, items, refName, force) => {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
17
|
-
if (!items[refName]) {
|
|
18
|
-
logger.error(`Reference \`${red(refName)}\` not found`);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const source = items[refName];
|
|
22
|
-
let publicBase;
|
|
23
|
-
let sourcePath = source.path;
|
|
24
|
-
if (source.repo) {
|
|
25
|
-
const repoFolder = path.resolve(remotesFolder, source.slug);
|
|
26
|
-
let created = false;
|
|
27
|
-
try {
|
|
28
|
-
const stat = await fs.stat(path.resolve(repoFolder, '.git'));
|
|
29
|
-
if (stat.isDirectory()) {
|
|
30
|
-
created = true;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
// ignore
|
|
35
|
-
}
|
|
36
|
-
if (!created) {
|
|
37
|
-
await fs.mkdir(repoFolder, { recursive: true });
|
|
38
|
-
}
|
|
39
|
-
const git = simpleGit(repoFolder);
|
|
40
|
-
if (!created) {
|
|
41
|
-
logger.info(`Cloning remote \`${cyan(source.slug)}\` repository...`);
|
|
42
|
-
await git.clone(source.repo, repoFolder, ['--depth', '1']);
|
|
43
|
-
}
|
|
44
|
-
if (force) {
|
|
45
|
-
logger.info(`Pulling latest changes for \`${cyan(source.slug)}\`...`);
|
|
46
|
-
await git.pull([
|
|
47
|
-
'--depth',
|
|
48
|
-
'1',
|
|
49
|
-
'--force',
|
|
50
|
-
'--rebase',
|
|
51
|
-
'--allow-unrelated-histories',
|
|
52
|
-
]);
|
|
53
|
-
}
|
|
54
|
-
publicBase = path.resolve(repoFolder, source.publicBase ?? 'docs/public');
|
|
55
|
-
sourcePath = path.resolve(repoFolder, sourcePath);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
publicBase = localPublicBase;
|
|
59
|
-
sourcePath = path.resolve(localBasePath, sourcePath);
|
|
60
|
-
}
|
|
61
|
-
let found = false;
|
|
62
|
-
try {
|
|
63
|
-
const stat = await fs.stat(sourcePath);
|
|
64
|
-
found = stat.isFile();
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
//
|
|
68
|
-
}
|
|
69
|
-
if (!found) {
|
|
70
|
-
logger.error(`Reference path \`${red(source.path)}\` for \`${red(source.name)}\` not found`);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
let content = await fs.readFile(sourcePath, 'utf8');
|
|
74
|
-
for (const processor of source.processors ?? []) {
|
|
75
|
-
switch (processor.type) {
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
77
|
-
case 'ejsTemplate': {
|
|
78
|
-
content = await render(content, { data: processor.data }, { async: true });
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const processor = (sourcePath.endsWith('.ejs')
|
|
84
|
-
? sourcePath.slice(0, -4)
|
|
85
|
-
: sourcePath).endsWith('.mdx')
|
|
86
|
-
? mdxProcessor
|
|
87
|
-
: mdProcessor;
|
|
88
|
-
const root = processor.parse(content);
|
|
89
|
-
const sourceBase = path.dirname(sourcePath);
|
|
90
|
-
if (!source.anchor) {
|
|
91
|
-
return {
|
|
92
|
-
publicBase,
|
|
93
|
-
sourceBase,
|
|
94
|
-
contents: root.children,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
const frontmatterNode = getFrontmatterNode(root);
|
|
98
|
-
const { toc } = parseToc(root, true);
|
|
99
|
-
const active = toc.find((it) => it.id === source.anchor);
|
|
100
|
-
if (!active) {
|
|
101
|
-
logger.error(`Anchor \`${red(source.anchor)}\` not found in \`${red(source.name)}\``);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const nodes = frontmatterNode ? [frontmatterNode] : [];
|
|
105
|
-
for (let i = active.index, n = root.children.length; i < n; i++) {
|
|
106
|
-
if (i === active.index && (source.ignoreHeading ?? active.depth === 1)) {
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
const node = root.children[i];
|
|
110
|
-
if (node.type === 'heading' &&
|
|
111
|
-
node.depth <= active.depth &&
|
|
112
|
-
i > active.index) {
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
nodes.push(node);
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
publicBase,
|
|
119
|
-
sourceBase,
|
|
120
|
-
contents: nodes,
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
const resolveReference = async (localBasePath, localPublicBase, items, refName, force) => {
|
|
124
|
-
if (refCache.has(refName)) {
|
|
125
|
-
return refCache.get(refName);
|
|
126
|
-
}
|
|
127
|
-
const resolving = resolveReference_(localBasePath, localPublicBase, items, refName, force);
|
|
128
|
-
refCache.set(refName, resolving);
|
|
129
|
-
if (!isProduction()) {
|
|
130
|
-
setTimeout(() => {
|
|
131
|
-
refCache.delete(refName);
|
|
132
|
-
}, 5_000);
|
|
133
|
-
}
|
|
134
|
-
return resolving;
|
|
135
|
-
};
|
|
136
|
-
const releaseCache = new Map();
|
|
137
|
-
const FIELD_MAPPER = {
|
|
138
|
-
zh: 'customfield_13800',
|
|
139
|
-
en: 'customfield_13801',
|
|
140
|
-
};
|
|
141
|
-
const { CI, JIRA_TOKEN, JIRA_USERNAME, JIRA_PASSWORD } = process.env;
|
|
142
|
-
const isCi = CI !== 'false' && !!CI;
|
|
143
|
-
const issuesToMdast = (issues, lang) => {
|
|
144
|
-
return issues
|
|
145
|
-
.map((issue) => {
|
|
146
|
-
const description = ((lang !== 'en' && issue.fields[FIELD_MAPPER[lang]]) ||
|
|
147
|
-
issue.fields[FIELD_MAPPER.en])?.trim();
|
|
148
|
-
if (!description) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
type: 'listItem',
|
|
153
|
-
children: [
|
|
154
|
-
{
|
|
155
|
-
type: 'paragraph',
|
|
156
|
-
children: description
|
|
157
|
-
.split('\n')
|
|
158
|
-
.map((line) => {
|
|
159
|
-
return {
|
|
160
|
-
type: 'text',
|
|
161
|
-
value: line,
|
|
162
|
-
};
|
|
163
|
-
})
|
|
164
|
-
.reduce((acc, curr, index) => {
|
|
165
|
-
if (index === 0) {
|
|
166
|
-
return [curr];
|
|
167
|
-
}
|
|
168
|
-
return acc.concat({ type: 'html', value: '<br>' }, curr);
|
|
169
|
-
}, []),
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
};
|
|
173
|
-
})
|
|
174
|
-
.filter((_) => !!_);
|
|
175
|
-
};
|
|
176
|
-
const resolveRelease_ = async (releaseTemplates, releaseQuery) => {
|
|
177
|
-
const query = new URLSearchParams(releaseQuery);
|
|
178
|
-
const templateName = query.get('template');
|
|
179
|
-
if (!templateName) {
|
|
180
|
-
logger.error(`Release notes template not found for query \`${red(releaseQuery)}\``);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
const template = releaseTemplates[templateName];
|
|
184
|
-
if (!template) {
|
|
185
|
-
logger.error(`Release notes template \`${red(templateName)}\` not found`);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
let Authorization;
|
|
189
|
-
if (JIRA_TOKEN) {
|
|
190
|
-
Authorization = `Bearer ${JIRA_TOKEN}`;
|
|
191
|
-
}
|
|
192
|
-
else if (JIRA_USERNAME && JIRA_PASSWORD) {
|
|
193
|
-
Authorization = `Basic ${Buffer.from(`${JIRA_USERNAME}:${JIRA_PASSWORD}`).toString('base64')}`;
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
throw new Error('`JIRA_TOKEN` or `JIRA_USERNAME` and `JIRA_PASSWORD` environments must be set for fetching Jira issues');
|
|
197
|
-
}
|
|
198
|
-
const data = {};
|
|
199
|
-
for (const [key, value] of query.entries()) {
|
|
200
|
-
if (key === 'template') {
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
data[key] = value;
|
|
204
|
-
}
|
|
205
|
-
const jql = await render(template, data, { async: true });
|
|
206
|
-
logger.info(`Fetching release notes for query \`${cyan(releaseQuery)}\``);
|
|
207
|
-
const res = await fetch(`https://jira.alauda.cn/rest/api/2/search?${new URLSearchParams({ jql })}`, { headers: { Authorization } });
|
|
208
|
-
if (!res.ok) {
|
|
209
|
-
logger.error(`Failed to fetch release notes for query \`${red(releaseQuery)}\` with status \`${res.status}\``);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
const { issues } = (await res.json());
|
|
213
|
-
return ['en', 'zh'].reduce((acc, curr) => Object.assign(acc, {
|
|
214
|
-
[curr]: { type: 'list', children: issuesToMdast(issues, curr) },
|
|
215
|
-
}), {});
|
|
216
|
-
};
|
|
217
|
-
const resolveRelease = async (releaseTemplates, releaseQuery, lang) => {
|
|
218
|
-
if (releaseCache.has(releaseQuery)) {
|
|
219
|
-
const cached = await releaseCache.get(releaseQuery);
|
|
220
|
-
return cached?.[lang] ?? cached?.en;
|
|
221
|
-
}
|
|
222
|
-
const resolving = resolveRelease_(releaseTemplates, releaseQuery);
|
|
223
|
-
releaseCache.set(releaseQuery, resolving);
|
|
224
|
-
const resolved = await resolving;
|
|
225
|
-
return resolved?.[lang] ?? resolved?.en;
|
|
226
|
-
};
|
|
9
|
+
import { resolveReference } from './resolve-reference.js';
|
|
10
|
+
import { resolveRelease } from './resolve-release.js';
|
|
227
11
|
const MD_REF_START_COMMENT_PATTERN = /<!-{2,} *reference-start#(.+) *-{2,}>/;
|
|
228
12
|
const MDX_REF_START_COMMENT_PATTERN = /{\/\*+ *reference-start#(.+) *\*+\/}/;
|
|
229
13
|
const MDX_REF_START_PATTERN = /\/\*+ *reference-start#(.+) *\*+\//;
|
|
@@ -240,6 +24,8 @@ export const maybeHaveRef = (filepath, content) => {
|
|
|
240
24
|
? [MDX_REF_START_COMMENT_PATTERN, MDX_RELEASE_COMMENT_PATTERN]
|
|
241
25
|
: [MD_REF_START_COMMENT_PATTERN, MD_RELEASE_COMMENT_PATTERN]).some((p) => p.test(content));
|
|
242
26
|
};
|
|
27
|
+
const { CI } = process.env;
|
|
28
|
+
const isCi = CI !== 'false' && !!CI;
|
|
243
29
|
export const remarkReplace = function ({ lang, localBasePath, root, items, force, releaseNotes }) {
|
|
244
30
|
return async (ast, vfile) => {
|
|
245
31
|
const filepath = vfile.path;
|
|
@@ -257,46 +43,40 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
|
|
|
257
43
|
const frontmatterNode = getFrontmatterNode(originalAst);
|
|
258
44
|
let frontmatter = frontmatterNode &&
|
|
259
45
|
parse(frontmatterNode.value);
|
|
260
|
-
const newAstChildren = [];
|
|
261
46
|
const newContentChildren = [];
|
|
262
|
-
let
|
|
263
|
-
let start = null;
|
|
47
|
+
let start = false;
|
|
264
48
|
let refName = '';
|
|
265
49
|
let matched;
|
|
266
50
|
let checkContent = false;
|
|
267
51
|
const relativePath = path.relative(root, filepath);
|
|
268
|
-
const
|
|
269
|
-
for (const node of ast.children) {
|
|
270
|
-
index++;
|
|
52
|
+
for (const node of originalAst.children) {
|
|
271
53
|
if (node.type !== (isMdx ? 'mdxFlowExpression' : 'html')) {
|
|
272
54
|
if (node.type === 'yaml') {
|
|
273
55
|
continue;
|
|
274
56
|
}
|
|
275
|
-
|
|
276
|
-
if (start == null) {
|
|
57
|
+
if (!start) {
|
|
277
58
|
newContentChildren.push(node);
|
|
278
59
|
}
|
|
279
60
|
continue;
|
|
280
61
|
}
|
|
281
62
|
if ((matched = node.value.match(isMdx ? MDX_REF_START_PATTERN : MD_REF_START_COMMENT_PATTERN))) {
|
|
282
|
-
if (start
|
|
63
|
+
if (start) {
|
|
283
64
|
logger.warn(`Invalid reference start block ${red(node.value)}, nested reference blocks are not allowed`);
|
|
284
65
|
}
|
|
285
66
|
else {
|
|
286
67
|
checkContent = true;
|
|
287
|
-
start =
|
|
68
|
+
start = true;
|
|
288
69
|
refName = matched[1].trim();
|
|
289
70
|
}
|
|
290
|
-
newAstChildren.push(node);
|
|
291
71
|
newContentChildren.push(node);
|
|
292
72
|
continue;
|
|
293
73
|
}
|
|
294
74
|
if ((isMdx ? MDX_REF_END_PATTERN : MD_REF_END_COMMENT_PATTERN).test(node.value)) {
|
|
295
|
-
if (start
|
|
296
|
-
|
|
75
|
+
if (start) {
|
|
76
|
+
start = false;
|
|
297
77
|
}
|
|
298
78
|
else {
|
|
299
|
-
start
|
|
79
|
+
logger.warn(`Invalid reference end block ${red(node.value)}, no matching start block found`);
|
|
300
80
|
}
|
|
301
81
|
const resolved = await resolveReference(localBasePath, localPublicBase, items, refName, force);
|
|
302
82
|
if (resolved) {
|
|
@@ -336,28 +116,14 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
|
|
|
336
116
|
}
|
|
337
117
|
}
|
|
338
118
|
}
|
|
339
|
-
newAstChildren.push(node);
|
|
340
|
-
newContentChildren.push(node);
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
if ((matched = node.value.match(isMdx ? MDX_RELEASE_PATTERN : MD_RELEASE_COMMENT_PATTERN))) {
|
|
344
|
-
if (start != null) {
|
|
345
|
-
logger.warn(`Invalid release-notes-for-bugs comment ${red(refName)}, nested reference blocks are not allowed`);
|
|
346
|
-
newAstChildren.push(node);
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
const releaseContent = await resolveRelease(releaseNotes?.queryTemplates ?? {}, matched[1].trim(), currLang);
|
|
350
|
-
newAstChildren.push(releaseContent ?? node);
|
|
351
|
-
}
|
|
352
119
|
newContentChildren.push(node);
|
|
353
120
|
continue;
|
|
354
121
|
}
|
|
355
|
-
|
|
356
|
-
if (start == null) {
|
|
122
|
+
if (!start) {
|
|
357
123
|
newContentChildren.push(node);
|
|
358
124
|
}
|
|
359
125
|
}
|
|
360
|
-
if (start
|
|
126
|
+
if (start) {
|
|
361
127
|
logger.warn(`Invalid reference start block ${red(refName)}, no matching end block found, adding for you`);
|
|
362
128
|
newContentChildren.push({
|
|
363
129
|
type: isMdx ? 'mdxFlowExpression' : 'html',
|
|
@@ -371,14 +137,9 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
|
|
|
371
137
|
});
|
|
372
138
|
}
|
|
373
139
|
if (checkContent) {
|
|
374
|
-
const originalImports = originalAst.children
|
|
375
|
-
.filter((it) => it.type === 'mdxjsEsm')
|
|
376
|
-
.map((it) => it.value);
|
|
377
140
|
const newContent = processor.stringify({
|
|
378
141
|
...ast,
|
|
379
|
-
children: newContentChildren
|
|
380
|
-
.flat()
|
|
381
|
-
.filter((n) => n.type !== 'mdxjsEsm' || originalImports.includes(n.value)),
|
|
142
|
+
children: newContentChildren.flat(),
|
|
382
143
|
});
|
|
383
144
|
if (content !== newContent) {
|
|
384
145
|
await fs.writeFile(filepath, newContent);
|
|
@@ -392,6 +153,20 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
|
|
|
392
153
|
return;
|
|
393
154
|
}
|
|
394
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
|
+
}
|
|
395
170
|
ast.children = newAstChildren.flat();
|
|
396
171
|
};
|
|
397
172
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
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>;
|
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
};
|
|
@@ -3,7 +3,7 @@ export interface ExternalSiteProps {
|
|
|
3
3
|
}
|
|
4
4
|
export interface ExternalSiteNoteProps {
|
|
5
5
|
name: string;
|
|
6
|
-
|
|
6
|
+
displayName: string;
|
|
7
7
|
}
|
|
8
8
|
export declare const ExternalSite: ({ name }: ExternalSiteProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
export default ExternalSite;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLang, usePageData } from '@rspress/core/runtime';
|
|
3
|
-
import { addTrailingSlash } from '@rspress/shared';
|
|
4
3
|
import { useMemo } from 'react';
|
|
5
|
-
import { normalizeVersion } from '../../shared/index.js';
|
|
6
4
|
import { handleCJKWhitespaces } from '../utils.js';
|
|
7
5
|
import { Directive } from './_Directive.js';
|
|
6
|
+
import { ExternalSiteLink } from './ExternalSiteLink.js';
|
|
8
7
|
const Notes = {
|
|
9
|
-
en({ name,
|
|
10
|
-
return (_jsxs(_Fragment, { children: ["Because ",
|
|
8
|
+
en({ name, displayName }) {
|
|
9
|
+
return (_jsxs(_Fragment, { children: ["Because ", displayName, " releases on a different cadence from Alauda Container Platform, the ", displayName, " documentation is now available as a separate documentation set at", ' ', _jsx(ExternalSiteLink, { name: name, children: displayName }), "."] }));
|
|
11
10
|
},
|
|
12
|
-
zh({ name,
|
|
13
|
-
const
|
|
14
|
-
return (_jsxs(_Fragment, { children: ["\u56E0\u4E3A",
|
|
11
|
+
zh({ name, displayName }) {
|
|
12
|
+
const displayName_ = handleCJKWhitespaces(displayName);
|
|
13
|
+
return (_jsxs(_Fragment, { children: ["\u56E0\u4E3A", displayName_, "\u7684\u53D1\u7248\u5468\u671F\u4E0E\u7075\u96C0\u4E91\u5BB9\u5668\u5E73\u53F0\u4E0D\u540C\uFF0C\u6240\u4EE5", displayName_, "\u7684\u6587\u6863\u73B0\u5728\u4F5C\u4E3A\u72EC\u7ACB\u7684\u6587\u6863\u7AD9\u70B9\u6258\u7BA1\u5728", displayName_.startsWith(' ') ? ' ' : '', _jsx(ExternalSiteLink, { name: name, children: displayName }), "\u3002"] }));
|
|
15
14
|
},
|
|
16
15
|
};
|
|
17
16
|
export const ExternalSite = ({ name }) => {
|
|
@@ -24,9 +23,6 @@ export const ExternalSite = ({ name }) => {
|
|
|
24
23
|
return (_jsxs(Directive, { type: "danger", children: ["No site with name `", name, "` found, please ensure it's already defined at `sites.yaml`"] }));
|
|
25
24
|
}
|
|
26
25
|
const Note = Notes[lang] || Notes[fallbackLang] || Notes.en;
|
|
27
|
-
|
|
28
|
-
return (_jsx(Directive, { title: "Note", children: _jsx(Note, { name: displayName, href: page.v
|
|
29
|
-
? addTrailingSlash(siteBase + normalizeVersion(site.defaultVersion))
|
|
30
|
-
: siteBase }) }));
|
|
26
|
+
return (_jsx(Directive, { title: "Note", children: _jsx(Note, { name: name, displayName: displayName }) }));
|
|
31
27
|
};
|
|
32
28
|
export default ExternalSite;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnchorHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export interface ExternalSiteLinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
3
|
+
name: string;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare const ExternalSiteLink: ({ name, href, className, ...props }: ExternalSiteLinkProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default ExternalSiteLink;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { usePageData } from '@rspress/core/runtime';
|
|
3
|
+
import { addTrailingSlash, isExternalUrl, removeLeadingSlash, } from '@rspress/shared';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
import { normalizeVersion } from '../../shared/index.js';
|
|
7
|
+
import { Directive } from './_Directive.js';
|
|
8
|
+
import classes from '../../../styles/link.module.scss';
|
|
9
|
+
export const ExternalSiteLink = ({ name, href = '', className, ...props }) => {
|
|
10
|
+
const { page } = usePageData();
|
|
11
|
+
const site = useMemo(() => page.sites?.find((s) => s.name === name), []);
|
|
12
|
+
if (!site) {
|
|
13
|
+
return (_jsxs(Directive, { type: "danger", children: ["No site with name `", name, "` found, please ensure it's already defined at `sites.yaml`"] }));
|
|
14
|
+
}
|
|
15
|
+
if (isExternalUrl(href)) {
|
|
16
|
+
return _jsxs(Directive, { type: "danger", children: ["Invalid href `", href, "` found"] });
|
|
17
|
+
}
|
|
18
|
+
const siteBase = addTrailingSlash(site.base);
|
|
19
|
+
return (_jsx("a", { href: (page.v
|
|
20
|
+
? addTrailingSlash(siteBase + normalizeVersion(site.version))
|
|
21
|
+
: siteBase) + removeLeadingSlash(href), target: "_blank", rel: "noopener noreferrer", className: clsx(classes.link, 'cursor-pointer', className), ...props }));
|
|
22
|
+
};
|
|
23
|
+
export default ExternalSiteLink;
|
package/lib/shared/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.link {
|
|
2
|
+
font-weight: 500;
|
|
3
|
+
transition: opacity 0.2s;
|
|
4
|
+
|
|
5
|
+
&:hover {
|
|
6
|
+
opacity: 0.85;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
&:active {
|
|
10
|
+
opacity: 0.7;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.link,
|
|
15
|
+
:global(summary) .link {
|
|
16
|
+
&:not(:global(.header-anchor)) {
|
|
17
|
+
font-weight: 500;
|
|
18
|
+
color: var(--rp-c-link);
|
|
19
|
+
transition: color 0.25s;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&:hover {
|
|
23
|
+
border-bottom: 1px solid var(--rp-c-brand);
|
|
24
|
+
}
|
|
25
|
+
}
|