@alauda/doom 0.8.2 → 0.8.4
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/index.js +12 -11
- package/lib/cli/load-config.d.ts +2 -2
- package/lib/cli/load-config.js +12 -5
- package/lib/cli/new.js +14 -57
- package/lib/global/SiteOverrides/index.d.ts +3 -0
- package/lib/global/SiteOverrides/index.js +65 -0
- package/lib/global/VersionsNav/index.d.ts +2 -1
- package/lib/global/VersionsNav/index.js +5 -4
- package/lib/plugins/auto-sidebar/index.d.ts +2 -1
- package/lib/plugins/auto-sidebar/index.js +8 -7
- package/lib/plugins/auto-sidebar/walk.d.ts +2 -2
- package/lib/plugins/auto-sidebar/walk.js +39 -18
- package/lib/plugins/directives/index.d.ts +2 -0
- package/lib/plugins/directives/index.js +10 -0
- package/lib/plugins/directives/remark-directives.d.ts +3 -0
- package/lib/plugins/directives/remark-directives.js +22 -0
- package/lib/plugins/global/index.js +4 -1
- package/lib/plugins/index.d.ts +1 -0
- package/lib/plugins/index.js +1 -0
- package/lib/plugins/replace/remark-replace.d.ts +1 -1
- package/lib/plugins/replace/resolve-reference.js +5 -32
- package/lib/plugins/replace/types.d.ts +5 -5
- package/lib/plugins/replace/utils.js +4 -9
- package/lib/runtime/components/Callouts.js +1 -1
- package/lib/runtime/components/CompanyBrand.d.ts +2 -0
- package/lib/runtime/components/CompanyBrand.js +4 -0
- package/lib/runtime/components/ExternalSiteLink.js +1 -1
- package/lib/runtime/components/ProductBrand.d.ts +2 -0
- package/lib/runtime/components/ProductBrand.js +4 -0
- package/lib/runtime/components/ProductShortBrand.d.ts +2 -0
- package/lib/runtime/components/ProductShortBrand.js +4 -0
- package/lib/runtime/components/_BrandBase.d.ts +5 -0
- package/lib/runtime/components/_BrandBase.js +6 -0
- package/lib/runtime/components/index.d.ts +3 -0
- package/lib/runtime/components/index.js +3 -0
- package/lib/runtime/hooks/index.d.ts +1 -0
- package/lib/runtime/hooks/index.js +1 -0
- package/lib/runtime/hooks/useSiteOverrides.d.ts +10 -0
- package/lib/runtime/hooks/useSiteOverrides.js +64 -0
- package/lib/runtime/types.d.ts +5 -0
- package/lib/utils/git.d.ts +1 -0
- package/lib/utils/git.js +73 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/types.d.ts +8 -0
- package/package.json +19 -15
- package/styles/global.scss +4 -0
package/lib/cli/index.js
CHANGED
|
@@ -26,22 +26,23 @@ program
|
|
|
26
26
|
.configureHelp({
|
|
27
27
|
showGlobalOptions: true,
|
|
28
28
|
})
|
|
29
|
-
.option('-c, --config
|
|
29
|
+
.option('-c, --config <config>', 'Specify the path to the config file')
|
|
30
30
|
.option('-v <version>', 'Specify the version of the documentation')
|
|
31
31
|
.option('-p, --prefix <prefix>', 'Specify the prefix of the documentation base')
|
|
32
32
|
.option('-f, --force [boolean]', 'Force to fetch latest reference remotes or scaffolding templates, otherwise use local cache', (value) => !!value && value !== 'false', false)
|
|
33
|
+
.option('-i, --ignore [boolean]', 'Ignore internal routes', (value) => !!value && value !== 'false', false)
|
|
33
34
|
.command('dev', { isDefault: true })
|
|
34
35
|
.description('Start the development server')
|
|
35
36
|
.argument('[root]', 'Root directory of the documentation')
|
|
36
|
-
.option('--port [port]', 'Port number')
|
|
37
37
|
.option('--host [host]', 'Host name')
|
|
38
|
+
.option('--port [port]', 'Port number')
|
|
38
39
|
.action(async function (root) {
|
|
39
40
|
setNodeEnv('development');
|
|
40
41
|
let devServer;
|
|
41
42
|
let cliWatcher;
|
|
42
|
-
const {
|
|
43
|
+
const { port, host, ...globalOptions } = this.optsWithGlobals();
|
|
43
44
|
const startDevServer = async () => {
|
|
44
|
-
const { config, filepath } = await loadConfig(root,
|
|
45
|
+
const { config, filepath } = await loadConfig(root, globalOptions);
|
|
45
46
|
const docDirectory = config.root;
|
|
46
47
|
try {
|
|
47
48
|
devServer = await dev({
|
|
@@ -49,7 +50,7 @@ program
|
|
|
49
50
|
appDirectory: CWD,
|
|
50
51
|
docDirectory,
|
|
51
52
|
extraBuilderConfig: {
|
|
52
|
-
server,
|
|
53
|
+
server: { host, port },
|
|
53
54
|
},
|
|
54
55
|
});
|
|
55
56
|
}
|
|
@@ -104,8 +105,7 @@ program
|
|
|
104
105
|
.argument('[root]', 'Root directory of the documentation')
|
|
105
106
|
.action(async function (root) {
|
|
106
107
|
setNodeEnv('production');
|
|
107
|
-
const { config
|
|
108
|
-
const { config } = await loadConfig(root, configFile, prefix, version, force);
|
|
108
|
+
const { config } = await loadConfig(root, this.optsWithGlobals());
|
|
109
109
|
const docDirectory = config.root;
|
|
110
110
|
const runBuild = () => build({
|
|
111
111
|
config,
|
|
@@ -123,15 +123,16 @@ program
|
|
|
123
123
|
.alias('serve')
|
|
124
124
|
.description('Preview the built documentation')
|
|
125
125
|
.argument('[root]', 'Root directory of the documentation')
|
|
126
|
-
.option('--port [port]', 'Port number', '4173')
|
|
127
126
|
.option('--host [host]', 'Host name')
|
|
127
|
+
.option('--port [port]', 'Port number', '4173')
|
|
128
128
|
.action(async function (root) {
|
|
129
129
|
setNodeEnv('production');
|
|
130
|
-
const {
|
|
131
|
-
const { config } = await loadConfig(root,
|
|
130
|
+
const { port, host, ...globalOptions } = this.optsWithGlobals();
|
|
131
|
+
const { config } = await loadConfig(root, globalOptions);
|
|
132
132
|
await serve({
|
|
133
133
|
config,
|
|
134
|
-
|
|
134
|
+
host,
|
|
135
|
+
port,
|
|
135
136
|
});
|
|
136
137
|
});
|
|
137
138
|
program.addCommand(newCommand);
|
package/lib/cli/load-config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type DoomConfig } from '../utils/index.js';
|
|
2
|
-
export declare function loadConfig(root?: string, configFile
|
|
1
|
+
import { type DoomConfig, GlobalCliOptions } from '../utils/index.js';
|
|
2
|
+
export declare function loadConfig(root?: string, { config: configFile, prefix, v: version, ignore, force, }?: GlobalCliOptions): Promise<{
|
|
3
3
|
config: DoomConfig;
|
|
4
4
|
filepath?: string;
|
|
5
5
|
}>;
|
package/lib/cli/load-config.js
CHANGED
|
@@ -5,7 +5,7 @@ import { addLeadingSlash, addTrailingSlash, normalizeSlash, removeLeadingSlash,
|
|
|
5
5
|
import { logger } from '@rspress/shared/logger';
|
|
6
6
|
import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
|
|
7
7
|
import rehypeRaw from 'rehype-raw';
|
|
8
|
-
import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, globalPlugin, shikiPlugin, } from '../plugins/index.js';
|
|
8
|
+
import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, shikiPlugin, } from '../plugins/index.js';
|
|
9
9
|
import { normalizeVersion } from '../shared/index.js';
|
|
10
10
|
import { pkgResolve, resolveStaticConfig, } from '../utils/index.js';
|
|
11
11
|
import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, SITES_FILE, YAML_EXTENSIONS, } from './constants.js';
|
|
@@ -19,13 +19,15 @@ const zhLocaleConfig = {
|
|
|
19
19
|
prevPageText: '上一页',
|
|
20
20
|
nextPageText: '下一页',
|
|
21
21
|
};
|
|
22
|
-
const getCommonConfig = (config, cliRoot, configFilePath, version, force) => {
|
|
22
|
+
const getCommonConfig = (config, cliRoot, configFilePath, version, ignore, force) => {
|
|
23
23
|
const fallbackToZh = 'lang' in config && config.lang == null;
|
|
24
24
|
const root = resolveDocRoot(CWD, cliRoot, config.root);
|
|
25
25
|
const localBasePath = configFilePath ? path.dirname(configFilePath) : root;
|
|
26
|
+
const excludeRoutes = (ignore && config.internalRoutes) || [];
|
|
26
27
|
return {
|
|
27
28
|
root,
|
|
28
29
|
lang: fallbackToZh ? 'zh' : config.lang,
|
|
30
|
+
title: '',
|
|
29
31
|
route: {
|
|
30
32
|
exclude: [
|
|
31
33
|
'dist/**/*',
|
|
@@ -34,6 +36,7 @@ const getCommonConfig = (config, cliRoot, configFilePath, version, force) => {
|
|
|
34
36
|
'doom.config.*',
|
|
35
37
|
'**/assets/**/*',
|
|
36
38
|
'**/*.d.ts',
|
|
39
|
+
...excludeRoutes,
|
|
37
40
|
],
|
|
38
41
|
},
|
|
39
42
|
markdown: {
|
|
@@ -61,7 +64,11 @@ const getCommonConfig = (config, cliRoot, configFilePath, version, force) => {
|
|
|
61
64
|
...config.api,
|
|
62
65
|
localBasePath,
|
|
63
66
|
}),
|
|
64
|
-
autoSidebarPlugin(
|
|
67
|
+
autoSidebarPlugin({
|
|
68
|
+
...config.sidebar,
|
|
69
|
+
excludeRoutes,
|
|
70
|
+
}),
|
|
71
|
+
directivesPlugin(),
|
|
65
72
|
globalPlugin({
|
|
66
73
|
sites: config.sites,
|
|
67
74
|
version,
|
|
@@ -110,7 +117,7 @@ const getCommonConfig = (config, cliRoot, configFilePath, version, force) => {
|
|
|
110
117
|
const findConfig = (basePath) => {
|
|
111
118
|
return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
|
|
112
119
|
};
|
|
113
|
-
export async function loadConfig(root, configFile, prefix, version, force) {
|
|
120
|
+
export async function loadConfig(root, { config: configFile, prefix, v: version, ignore, force, } = {}) {
|
|
114
121
|
let configFilePath;
|
|
115
122
|
if (configFile) {
|
|
116
123
|
configFilePath = path.resolve(configFile);
|
|
@@ -160,7 +167,7 @@ export async function loadConfig(root, configFile, prefix, version, force) {
|
|
|
160
167
|
}
|
|
161
168
|
}
|
|
162
169
|
const normalizedVersion = normalizeVersion(version);
|
|
163
|
-
const commonConfig = getCommonConfig(config, root, configFilePath, normalizedVersion, force);
|
|
170
|
+
const commonConfig = getCommonConfig(config, root, configFilePath, normalizedVersion, ignore, force);
|
|
164
171
|
const mergedConfig = mergeRsbuildConfig(commonConfig, config, {
|
|
165
172
|
root: commonConfig.root,
|
|
166
173
|
});
|
package/lib/cli/new.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
-
import os from 'node:os';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
import * as prompts from '@inquirer/prompts';
|
|
5
4
|
import { logger } from '@rsbuild/core';
|
|
6
5
|
import { Command } from 'commander';
|
|
7
6
|
import { render } from 'ejs';
|
|
8
|
-
import { simpleGit } from 'simple-git';
|
|
9
7
|
import { glob } from 'tinyglobby';
|
|
10
8
|
import { cyan, magenta } from 'yoctocolors';
|
|
11
9
|
import { resolveStaticConfig } from '../utils/helpers.js';
|
|
10
|
+
import { resolveRepo } from '../utils/index.js';
|
|
12
11
|
export const DEFAULT_PATH = 'templates/scaffolding.yaml';
|
|
13
12
|
const scaffoldingTemplates = {
|
|
14
13
|
'product-doc': {
|
|
15
14
|
repo: 'alauda-public/product-doc-guide',
|
|
16
15
|
},
|
|
17
16
|
};
|
|
18
|
-
const
|
|
19
|
-
const getScaffoldings = async (repoFolder, scaffoldingPath, branch) => {
|
|
17
|
+
const getScaffoldings = async (repoFolder, scaffoldingPath) => {
|
|
20
18
|
const scaffoldingFile = path.resolve(repoFolder, scaffoldingPath);
|
|
21
19
|
try {
|
|
22
20
|
const stat = await fs.stat(scaffoldingFile);
|
|
@@ -28,7 +26,7 @@ const getScaffoldings = async (repoFolder, scaffoldingPath, branch) => {
|
|
|
28
26
|
catch (err_) {
|
|
29
27
|
const err = err_;
|
|
30
28
|
if (err.name === 'YAMLParseError') {
|
|
31
|
-
logger.error(`Failed to parse \`${magenta(scaffoldingPath)}
|
|
29
|
+
logger.error(`Failed to parse \`${magenta(scaffoldingPath)}\`: ${err.message}`);
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
};
|
|
@@ -39,58 +37,14 @@ const resolveScaffoldings = async (name, force) => {
|
|
|
39
37
|
.join(', ')}`);
|
|
40
38
|
return;
|
|
41
39
|
}
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
const stat = await fs.stat(path.resolve(repoFolder, '.git'));
|
|
48
|
-
if (stat.isDirectory()) {
|
|
49
|
-
created = true;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
// ignore
|
|
54
|
-
}
|
|
55
|
-
if (!created) {
|
|
56
|
-
await fs.mkdir(repoFolder, { recursive: true });
|
|
57
|
-
}
|
|
58
|
-
const git = simpleGit(repoFolder);
|
|
59
|
-
if (!created) {
|
|
60
|
-
logger.info(`Cloning scaffolding template \`${cyan(name)}\` repository...`);
|
|
61
|
-
await git.clone(/^((\w+):)?\/\//.test(repo)
|
|
62
|
-
? repo
|
|
63
|
-
: `https://gitlab-ce.alauda.cn/${repo}`, repoFolder, ['--depth', '1']);
|
|
40
|
+
const { repo, scaffoldingPath = 'templates/scaffolding.yaml' } = scaffoldingTemplates[name];
|
|
41
|
+
const repoFolder = await resolveRepo(repo, force);
|
|
42
|
+
if (!repoFolder) {
|
|
43
|
+
return;
|
|
64
44
|
}
|
|
65
|
-
let currentBranch = (await git.raw(['branch', '--show-current'])).trim();
|
|
66
|
-
let scaffoldings;
|
|
67
45
|
const base = path.resolve(repoFolder, scaffoldingPath, '..');
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return { base, scaffoldings };
|
|
71
|
-
}
|
|
72
|
-
if (!branches?.length) {
|
|
73
|
-
const defaultBranch = (await git.raw(['rev-parse', '--abbrev-ref', 'origin/HEAD']))
|
|
74
|
-
.trim()
|
|
75
|
-
.replace('origin/', '');
|
|
76
|
-
branches = [defaultBranch];
|
|
77
|
-
}
|
|
78
|
-
const options = ['--depth', '1', '--force'];
|
|
79
|
-
for (const branch of branches) {
|
|
80
|
-
if (branch === currentBranch) {
|
|
81
|
-
logger.info(`Pulling latest changes from branch \`${cyan(branch)}\`...`);
|
|
82
|
-
await git.pull([...options, '--rebase', '--allow-unrelated-histories']);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
logger.info(`Switching to branch \`${cyan(branch)}\`...`);
|
|
86
|
-
await git.fetch('origin', `${branch}:${branch}`, options);
|
|
87
|
-
await git.checkout((currentBranch = branch));
|
|
88
|
-
}
|
|
89
|
-
const scaffoldings = await getScaffoldings(repoFolder, scaffoldingPath, branch);
|
|
90
|
-
if (scaffoldings) {
|
|
91
|
-
return { base, scaffoldings };
|
|
92
|
-
}
|
|
93
|
-
}
|
|
46
|
+
const scaffoldings = await getScaffoldings(repoFolder, scaffoldingPath);
|
|
47
|
+
return { base, scaffoldings, repoFolder };
|
|
94
48
|
};
|
|
95
49
|
const handleTemplateFile = async ({ source, target, processors, parameters, writeMode = 'write', }) => {
|
|
96
50
|
let content = await fs.readFile(source, 'utf-8');
|
|
@@ -111,6 +65,7 @@ const handleTemplateFile = async ({ source, target, processors, parameters, writ
|
|
|
111
65
|
await fs[`${writeMode}File`](target, content);
|
|
112
66
|
};
|
|
113
67
|
export const newCommand = new Command('new')
|
|
68
|
+
.description('Generate scaffolding from templates')
|
|
114
69
|
.argument('[template]', 'Scaffolding template name, format: `[name][:type]`')
|
|
115
70
|
.action(async function (template = '') {
|
|
116
71
|
let [name, type] = template.split(':');
|
|
@@ -118,9 +73,11 @@ export const newCommand = new Command('new')
|
|
|
118
73
|
name = 'product-doc';
|
|
119
74
|
}
|
|
120
75
|
const { force } = this.optsWithGlobals();
|
|
121
|
-
const { base, scaffoldings } = (await resolveScaffoldings(name, force)) || {};
|
|
76
|
+
const { base, repoFolder, scaffoldings } = (await resolveScaffoldings(name, force)) || {};
|
|
122
77
|
if (!scaffoldings) {
|
|
123
|
-
|
|
78
|
+
if (repoFolder) {
|
|
79
|
+
logger.error(`Unable to resolve any scaffoldings, if you are sure the template \`${magenta(name)}\` exists, try to use the \`--force\` option, or event remove the local cache at ${magenta(repoFolder)} and try again`);
|
|
80
|
+
}
|
|
124
81
|
return;
|
|
125
82
|
}
|
|
126
83
|
if (!type) {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { usePageData } from '@rspress/core/runtime';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useSiteOverrides } from '../../runtime/hooks/index.js';
|
|
4
|
+
const setNavBarSpans = (logoText) => {
|
|
5
|
+
const navBarLinks = document.querySelectorAll('[class^=navBarTitle] > a');
|
|
6
|
+
if (!navBarLinks.length) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
for (const navBarLink of navBarLinks) {
|
|
10
|
+
const navBarSpan = navBarLink.querySelector('span') ||
|
|
11
|
+
navBarLink.appendChild(document.createElement('span'));
|
|
12
|
+
navBarSpan.innerText = logoText;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const concatTitle = (title, suffix) => {
|
|
16
|
+
if (!suffix) {
|
|
17
|
+
return title;
|
|
18
|
+
}
|
|
19
|
+
title = title.trim();
|
|
20
|
+
suffix = suffix.trim();
|
|
21
|
+
if (!suffix.startsWith('-') && !suffix.startsWith('|')) {
|
|
22
|
+
return `${title} - ${suffix}`;
|
|
23
|
+
}
|
|
24
|
+
return `${title} ${suffix}`;
|
|
25
|
+
};
|
|
26
|
+
export const SiteOverrides = () => {
|
|
27
|
+
const { siteData, page } = usePageData();
|
|
28
|
+
const { pageType,
|
|
29
|
+
// Inject by remark-plugin-toc
|
|
30
|
+
title: articleTitle, frontmatter = {}, } = page;
|
|
31
|
+
const { title, logoText } = useSiteOverrides();
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!title) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
siteData.title = title;
|
|
37
|
+
let newTitle = frontmatter.title || articleTitle;
|
|
38
|
+
if (newTitle && pageType === 'doc') {
|
|
39
|
+
// append main title as a suffix
|
|
40
|
+
newTitle = concatTitle(newTitle, frontmatter.titleSuffix || title);
|
|
41
|
+
}
|
|
42
|
+
else if (pageType === 'home') {
|
|
43
|
+
newTitle = concatTitle(title, frontmatter.titleSuffix);
|
|
44
|
+
}
|
|
45
|
+
else if (pageType === '404') {
|
|
46
|
+
newTitle = concatTitle('404', title);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
newTitle = title;
|
|
50
|
+
}
|
|
51
|
+
requestAnimationFrame(() => {
|
|
52
|
+
document.title = newTitle;
|
|
53
|
+
});
|
|
54
|
+
}, [title]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!logoText) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
requestAnimationFrame(() => {
|
|
60
|
+
setNavBarSpans(logoText);
|
|
61
|
+
});
|
|
62
|
+
}, [logoText]);
|
|
63
|
+
return null;
|
|
64
|
+
};
|
|
65
|
+
export default SiteOverrides;
|
|
@@ -5,6 +5,7 @@ import { useEffect, useMemo, useState } from 'react';
|
|
|
5
5
|
import { createPortal } from 'react-dom';
|
|
6
6
|
import { parse } from 'yaml';
|
|
7
7
|
import { NavMenuGroup } from './NavMenuGroup.js';
|
|
8
|
+
const getNavMenu = () => document.querySelector('.rspress-nav-menu');
|
|
8
9
|
export const VersionsNav = () => {
|
|
9
10
|
const { siteData, page } = usePageData();
|
|
10
11
|
const [versionsBase, version] = useMemo(() => {
|
|
@@ -16,7 +17,7 @@ export const VersionsNav = () => {
|
|
|
16
17
|
page.v,
|
|
17
18
|
];
|
|
18
19
|
}, [siteData.base, page.v]);
|
|
19
|
-
const [navMenu, setNavMenu] = useState();
|
|
20
|
+
const [navMenu, setNavMenu] = useState(getNavMenu);
|
|
20
21
|
const [versions, setVersions] = useState();
|
|
21
22
|
useEffect(() => {
|
|
22
23
|
const fetchVersions = async () => {
|
|
@@ -25,7 +26,7 @@ export const VersionsNav = () => {
|
|
|
25
26
|
}
|
|
26
27
|
const res = await fetch(`${isProduction() ? versionsBase : ''}/versions.yaml`);
|
|
27
28
|
const text = await res.text();
|
|
28
|
-
setNavMenu(
|
|
29
|
+
setNavMenu(getNavMenu());
|
|
29
30
|
const versions = parse(text);
|
|
30
31
|
if (version && !versions.includes(version)) {
|
|
31
32
|
versions.unshift(version);
|
|
@@ -41,7 +42,7 @@ export const VersionsNav = () => {
|
|
|
41
42
|
}
|
|
42
43
|
const observer = new MutationObserver((mutations) => {
|
|
43
44
|
if (mutations.some((m) => m.removedNodes.length)) {
|
|
44
|
-
setNavMenu(
|
|
45
|
+
setNavMenu(getNavMenu);
|
|
45
46
|
}
|
|
46
47
|
});
|
|
47
48
|
observer.observe(navMenu, { childList: true });
|
|
@@ -56,6 +57,6 @@ export const VersionsNav = () => {
|
|
|
56
57
|
text: v,
|
|
57
58
|
link: `${versionsBase}/${v}/`,
|
|
58
59
|
activeMatch: v,
|
|
59
|
-
})), pathname: siteData.base }),
|
|
60
|
+
})), pathname: siteData.base }), getNavMenu());
|
|
60
61
|
};
|
|
61
62
|
export default VersionsNav;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type RspressPlugin } from '@rspress/core';
|
|
2
2
|
export interface AutoSidebarPluginOptions {
|
|
3
|
+
excludeRoutes?: string[];
|
|
3
4
|
collapsed?: boolean;
|
|
4
5
|
}
|
|
5
|
-
export declare const autoSidebarPlugin: ({ collapsed, }?: AutoSidebarPluginOptions) => RspressPlugin;
|
|
6
|
+
export declare const autoSidebarPlugin: ({ excludeRoutes, collapsed, }?: AutoSidebarPluginOptions) => RspressPlugin;
|
|
@@ -141,21 +141,21 @@ import { walk } from './walk.js';
|
|
|
141
141
|
// }
|
|
142
142
|
// ]
|
|
143
143
|
// ```
|
|
144
|
-
function processLocales(langs, versions, root, defaultLang, defaultVersion, extensions, collapsed) {
|
|
144
|
+
function processLocales(langs, versions, root, defaultLang, defaultVersion, extensions, excludeRoutes, collapsed) {
|
|
145
145
|
return Promise.all(langs.map(async (lang) => {
|
|
146
146
|
const walks = versions.length
|
|
147
147
|
? await Promise.all(versions.map((version) => {
|
|
148
148
|
const routePrefix = addTrailingSlash(`${version === defaultVersion ? '' : `/${version}`}${lang === defaultLang ? '' : `/${lang}`}`);
|
|
149
|
-
return walk(path.join(root, version, lang), routePrefix, root, extensions, collapsed);
|
|
149
|
+
return walk(path.join(root, version, lang), routePrefix, root, extensions, excludeRoutes, collapsed);
|
|
150
150
|
}))
|
|
151
151
|
: [
|
|
152
|
-
await walk(path.join(root, lang), addTrailingSlash(lang === defaultLang ? '' : `/${lang}`), root, extensions, collapsed),
|
|
152
|
+
await walk(path.join(root, lang), addTrailingSlash(lang === defaultLang ? '' : `/${lang}`), root, extensions, excludeRoutes, collapsed),
|
|
153
153
|
];
|
|
154
154
|
return combineWalkResult(walks, versions);
|
|
155
155
|
}));
|
|
156
156
|
}
|
|
157
157
|
const defaultExtensions = ['.mdx', '.md', '.tsx', '.jsx', '.ts', '.js'];
|
|
158
|
-
export const autoSidebarPlugin = ({ collapsed, } = {}) => {
|
|
158
|
+
export const autoSidebarPlugin = ({ excludeRoutes, collapsed, } = {}) => {
|
|
159
159
|
return {
|
|
160
160
|
name: 'doom-auto-sidebar',
|
|
161
161
|
async config(config, utils) {
|
|
@@ -163,6 +163,7 @@ export const autoSidebarPlugin = ({ collapsed, } = {}) => {
|
|
|
163
163
|
config.themeConfig = config.themeConfig || {};
|
|
164
164
|
config.themeConfig.locales =
|
|
165
165
|
config.themeConfig.locales || config.locales || [];
|
|
166
|
+
const root = config.root;
|
|
166
167
|
const langs = config.themeConfig.locales.map((locale) => locale.lang);
|
|
167
168
|
const hasLocales = langs.length > 0;
|
|
168
169
|
const hasLang = Boolean(config.lang);
|
|
@@ -171,7 +172,7 @@ export const autoSidebarPlugin = ({ collapsed, } = {}) => {
|
|
|
171
172
|
const { default: defaultVersion = '' } = config.multiVersion || {};
|
|
172
173
|
const { extensions = defaultExtensions } = config.route || {};
|
|
173
174
|
if (hasLocales) {
|
|
174
|
-
const metaInfo = await processLocales(langs, versions,
|
|
175
|
+
const metaInfo = await processLocales(langs, versions, root, defaultLang, defaultVersion, extensions, excludeRoutes, collapsed);
|
|
175
176
|
config.themeConfig.locales = config.themeConfig.locales.map((item, index) => ({
|
|
176
177
|
...item,
|
|
177
178
|
...metaInfo[index],
|
|
@@ -188,9 +189,9 @@ export const autoSidebarPlugin = ({ collapsed, } = {}) => {
|
|
|
188
189
|
const walks = versions.length
|
|
189
190
|
? await Promise.all(versions.map((version) => {
|
|
190
191
|
const routePrefix = addTrailingSlash(version === defaultVersion ? '' : `/${version}`);
|
|
191
|
-
return walk(path.join(
|
|
192
|
+
return walk(path.join(root, version), routePrefix, config.root, extensions, excludeRoutes, collapsed);
|
|
192
193
|
}))
|
|
193
|
-
: [await walk(
|
|
194
|
+
: [await walk(root, '/', root, extensions, excludeRoutes, collapsed)];
|
|
194
195
|
const combined = combineWalkResult(walks, versions);
|
|
195
196
|
config.themeConfig = { ...config.themeConfig, ...combined };
|
|
196
197
|
}
|
|
@@ -7,11 +7,11 @@ export interface DoomSidebarGroup extends Omit<SidebarGroup, 'items'> {
|
|
|
7
7
|
items: DoomSidebar[];
|
|
8
8
|
weight?: number;
|
|
9
9
|
}
|
|
10
|
-
export declare function scanSideMeta(workDir: string, rootDir: string, docsDir: string, routePrefix: string, extensions: string[], ignoredDirs: string[]): Promise<{
|
|
10
|
+
export declare function scanSideMeta(workDir: string, rootDir: string, docsDir: string, routePrefix: string, extensions: string[], ignoredDirs: string[], excludeRoutes: string[]): Promise<{
|
|
11
11
|
index?: DoomSidebarItem;
|
|
12
12
|
others: DoomSidebar[];
|
|
13
13
|
}>;
|
|
14
|
-
export declare function walk(workDir: string, routePrefix: string | undefined, docsDir: string, extensions: string[], collapsed?: boolean): Promise<{
|
|
14
|
+
export declare function walk(workDir: string, routePrefix: string | undefined, docsDir: string, extensions: string[], excludeRoutes?: string[], collapsed?: boolean): Promise<{
|
|
15
15
|
nav: never[];
|
|
16
16
|
sidebar: {
|
|
17
17
|
[x: string]: DoomSidebar[];
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
1
2
|
import { isExternalUrl, removeLeadingSlash, removeTrailingSlash, slash, withBase, } from '@rspress/shared';
|
|
2
3
|
import fs from '@rspress/shared/fs-extra';
|
|
3
4
|
import { logger } from '@rspress/shared/logger';
|
|
4
|
-
import
|
|
5
|
+
import { unset } from 'es-toolkit/compat';
|
|
6
|
+
import picomatch from 'picomatch';
|
|
5
7
|
import { detectFilePath, extractInfoFromFrontmatter } from './utils.js';
|
|
6
8
|
const sidebarSorter = (a, b) => {
|
|
7
9
|
const aWeight = 'weight' in a && a.weight != null ? a.weight : 100;
|
|
@@ -9,19 +11,29 @@ const sidebarSorter = (a, b) => {
|
|
|
9
11
|
return aWeight - bWeight;
|
|
10
12
|
};
|
|
11
13
|
/**
|
|
12
|
-
* Split sideMeta into two parts: `index` and `others` and sort `others` by weight
|
|
14
|
+
* 1. Split sideMeta into two parts: `index` and `others` and sort `others` by weight
|
|
15
|
+
* 2. filter out `excludeRoutes`
|
|
13
16
|
*/
|
|
14
|
-
const
|
|
17
|
+
const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
|
|
15
18
|
const result = sideMeta.reduce((acc, curr) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(
|
|
21
|
-
|
|
19
|
+
if (!curr) {
|
|
20
|
+
return acc;
|
|
21
|
+
}
|
|
22
|
+
if (!('_fileKey' in curr) || !curr._fileKey || 'items' in curr) {
|
|
23
|
+
acc.others.push(curr);
|
|
24
|
+
return acc;
|
|
25
|
+
}
|
|
26
|
+
const ignored = excludeRoutes.some((glob) => picomatch.isMatch(curr._fileKey, glob));
|
|
27
|
+
let filePart;
|
|
28
|
+
if (!acc.index &&
|
|
29
|
+
(filePart = curr._fileKey.split('/').at(-1)) &&
|
|
30
|
+
extensions.some((ext) => filePart === `index${ext}`)) {
|
|
22
31
|
acc.index = curr;
|
|
32
|
+
if (ignored) {
|
|
33
|
+
curr.link = '';
|
|
34
|
+
}
|
|
23
35
|
}
|
|
24
|
-
else {
|
|
36
|
+
else if (!ignored) {
|
|
25
37
|
acc.others.push(curr);
|
|
26
38
|
}
|
|
27
39
|
return acc;
|
|
@@ -29,7 +41,7 @@ const splitSideMeta = (sideMeta, extensions) => {
|
|
|
29
41
|
result.others.sort(sidebarSorter);
|
|
30
42
|
return result;
|
|
31
43
|
};
|
|
32
|
-
export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, extensions, ignoredDirs) {
|
|
44
|
+
export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, extensions, ignoredDirs, excludeRoutes) {
|
|
33
45
|
if (!(await fs.exists(workDir))) {
|
|
34
46
|
logger.error('[plugin-auto-sidebar]', `Generate sidebar meta error: ${workDir} not exists`);
|
|
35
47
|
}
|
|
@@ -125,7 +137,7 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
|
|
|
125
137
|
}
|
|
126
138
|
if (type === 'dir') {
|
|
127
139
|
const subDir = path.resolve(workDir, name);
|
|
128
|
-
const { index, others: subSidebar } = await scanSideMeta(subDir, rootDir, docsDir, routePrefix, extensions, ['assets']);
|
|
140
|
+
const { index, others: subSidebar } = await scanSideMeta(subDir, rootDir, docsDir, routePrefix, extensions, ['assets'], excludeRoutes);
|
|
129
141
|
const realPath = await detectFilePath(subDir, extensions);
|
|
130
142
|
const group = {
|
|
131
143
|
text: label,
|
|
@@ -138,7 +150,15 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
|
|
|
138
150
|
context,
|
|
139
151
|
_fileKey: realPath ? path.relative(docsDir, realPath) : '',
|
|
140
152
|
};
|
|
141
|
-
|
|
153
|
+
const sidebarItem = index ? { ...group, ...index } : group;
|
|
154
|
+
if (!subSidebar.length) {
|
|
155
|
+
if (index) {
|
|
156
|
+
unset(sidebarItem, 'items');
|
|
157
|
+
return sidebarItem;
|
|
158
|
+
}
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
return sidebarItem;
|
|
142
162
|
}
|
|
143
163
|
if (type === 'divider') {
|
|
144
164
|
return {
|
|
@@ -157,12 +177,12 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
|
|
|
157
177
|
tag,
|
|
158
178
|
};
|
|
159
179
|
}));
|
|
160
|
-
return
|
|
180
|
+
return processSideMeta(sidebarFromMeta, extensions, excludeRoutes);
|
|
161
181
|
}
|
|
162
182
|
// Start walking from the doc directory, scan the `_meta.json` file in each subdirectory
|
|
163
183
|
// and generate the nav and sidebar config
|
|
164
|
-
export async function walk(workDir, routePrefix = '/', docsDir, extensions, collapsed) {
|
|
165
|
-
const { index, others } = await scanSideMeta(workDir, workDir, docsDir, routePrefix, extensions, ['assets', 'public', 'shared']);
|
|
184
|
+
export async function walk(workDir, routePrefix = '/', docsDir, extensions, excludeRoutes = [], collapsed) {
|
|
185
|
+
const { index, others } = await scanSideMeta(workDir, workDir, docsDir, routePrefix, extensions, ['assets', 'public', 'shared'], excludeRoutes);
|
|
166
186
|
const sidebars = index ? [index, ...others] : others;
|
|
167
187
|
if (collapsed != null) {
|
|
168
188
|
for (const sidebarItem of sidebars) {
|
|
@@ -175,8 +195,9 @@ export async function walk(workDir, routePrefix = '/', docsDir, extensions, coll
|
|
|
175
195
|
const sidebarConfig = {
|
|
176
196
|
[routePrefix]: sidebars,
|
|
177
197
|
};
|
|
178
|
-
|
|
179
|
-
|
|
198
|
+
const simpleRoutePrefix = removeTrailingSlash(routePrefix);
|
|
199
|
+
if (simpleRoutePrefix) {
|
|
200
|
+
sidebarConfig[simpleRoutePrefix] = sidebars;
|
|
180
201
|
}
|
|
181
202
|
return {
|
|
182
203
|
nav: [],
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import remarkDirective from 'remark-directive';
|
|
2
|
+
import { remarkDirectives } from './remark-directives.js';
|
|
3
|
+
export const directivesPlugin = () => {
|
|
4
|
+
return {
|
|
5
|
+
name: 'doom-directives',
|
|
6
|
+
markdown: {
|
|
7
|
+
remarkPlugins: [remarkDirective, remarkDirectives],
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
export const remarkDirectives = function () {
|
|
3
|
+
return (root) => {
|
|
4
|
+
visit(root, (node) => {
|
|
5
|
+
if (node.type !== 'containerDirective' &&
|
|
6
|
+
node.type !== 'leafDirective' &&
|
|
7
|
+
node.type !== 'textDirective') {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const data = node.data || (node.data = {});
|
|
11
|
+
switch (node.name) {
|
|
12
|
+
case 'callouts': {
|
|
13
|
+
data.hProperties = { className: 'doom-callouts' };
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
default: {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { baseResolve, pkgResolve } from '../../utils/index.js';
|
|
4
|
+
const globalComponentsDir = baseResolve('global');
|
|
4
5
|
const componentsDir = baseResolve('runtime/components');
|
|
5
6
|
export const globalPlugin = ({ sites, version, } = {}) => {
|
|
6
7
|
return {
|
|
7
8
|
name: 'doom-global',
|
|
8
9
|
globalStyles: pkgResolve('styles/global.scss'),
|
|
9
|
-
globalUIComponents:
|
|
10
|
+
globalUIComponents: fs
|
|
11
|
+
.readdirSync(globalComponentsDir, 'utf8')
|
|
12
|
+
.map((component) => path.resolve(globalComponentsDir, component, 'index')),
|
|
10
13
|
markdown: {
|
|
11
14
|
globalComponents: fs
|
|
12
15
|
.readdirSync(componentsDir)
|
package/lib/plugins/index.d.ts
CHANGED
package/lib/plugins/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Root } from 'mdast';
|
|
2
|
-
import {
|
|
2
|
+
import type { Plugin } from 'unified';
|
|
3
3
|
import type { NormalizedReferenceSource, ReleaseNotesOptions } from './types.js';
|
|
4
4
|
export declare const MD_RELEASE_COMMENT_PATTERN: RegExp;
|
|
5
5
|
export declare const MDX_RELEASE_COMMENT_PATTERN: RegExp;
|
|
@@ -1,14 +1,12 @@
|
|
|
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
5
|
import { render } from 'ejs';
|
|
7
|
-
import {
|
|
8
|
-
import { cyan, red } from 'yoctocolors';
|
|
6
|
+
import { red } from 'yoctocolors';
|
|
9
7
|
import { parseToc } from './parse-toc.js';
|
|
10
8
|
import { getFrontmatterNode, mdProcessor, mdxProcessor } from './utils.js';
|
|
11
|
-
|
|
9
|
+
import { resolveRepo } from '../../utils/index.js';
|
|
12
10
|
const refCache = new Map();
|
|
13
11
|
const resolveReference_ = async (localBasePath, localPublicBase, items, refName, force) => {
|
|
14
12
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -20,34 +18,9 @@ const resolveReference_ = async (localBasePath, localPublicBase, items, refName,
|
|
|
20
18
|
let publicBase;
|
|
21
19
|
let sourcePath = source.path;
|
|
22
20
|
if (source.repo) {
|
|
23
|
-
const repoFolder =
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
]);
|
|
21
|
+
const repoFolder = await resolveRepo(source.repo, force, source.branch);
|
|
22
|
+
if (!repoFolder) {
|
|
23
|
+
return;
|
|
51
24
|
}
|
|
52
25
|
publicBase = path.resolve(repoFolder, source.publicBase ?? 'docs/public');
|
|
53
26
|
sourcePath = path.resolve(repoFolder, sourcePath);
|
|
@@ -9,15 +9,15 @@ export interface ReferenceItemSource {
|
|
|
9
9
|
frontmatterMode?: 'ignore' | 'merge' | 'remove' | 'replace';
|
|
10
10
|
processors?: ContentProcessor[];
|
|
11
11
|
}
|
|
12
|
-
export interface
|
|
12
|
+
export interface ReferenceItemRemote {
|
|
13
13
|
repo?: string;
|
|
14
|
+
branch?: string;
|
|
14
15
|
publicBase?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ReferenceItem extends ReferenceItemRemote {
|
|
15
18
|
sources: ReferenceItemSource[];
|
|
16
19
|
}
|
|
17
|
-
export interface NormalizedReferenceSource extends ReferenceItemSource {
|
|
18
|
-
repo?: string;
|
|
19
|
-
publicBase?: string;
|
|
20
|
-
slug?: string;
|
|
20
|
+
export interface NormalizedReferenceSource extends ReferenceItemRemote, ReferenceItemSource {
|
|
21
21
|
anchor?: string;
|
|
22
22
|
}
|
|
23
23
|
export interface ReleaseNotesOptions {
|
|
@@ -20,18 +20,13 @@ export const normalizeReferenceItems = (items) => items.reduce((acc, curr) => {
|
|
|
20
20
|
if (source.name in acc) {
|
|
21
21
|
logger.error(`Duplicate source name \`${red(source.name)}\` will be deduplicated`);
|
|
22
22
|
}
|
|
23
|
-
const repo = curr
|
|
24
|
-
const extra = {};
|
|
25
|
-
if (repo) {
|
|
26
|
-
const url = new URL(repo, 'https://gitlab-ce.alauda.cn');
|
|
27
|
-
extra.repo = url.toString();
|
|
28
|
-
extra.slug = url.pathname.slice(1);
|
|
29
|
-
}
|
|
23
|
+
const { repo, branch, publicBase } = curr;
|
|
30
24
|
const [path, anchor] = source.path.split('#');
|
|
31
25
|
acc[source.name] = {
|
|
32
26
|
...source,
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
repo,
|
|
28
|
+
branch,
|
|
29
|
+
publicBase,
|
|
35
30
|
path,
|
|
36
31
|
anchor,
|
|
37
32
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
export const Callouts = ({ children }) => {
|
|
3
|
-
return _jsx("div", { className: "
|
|
3
|
+
return _jsx("div", { className: "doom-callouts", children: children });
|
|
4
4
|
};
|
|
5
5
|
export default Callouts;
|
|
@@ -16,7 +16,7 @@ export const ExternalSiteLink = ({ name, href = '', className, ...props }) => {
|
|
|
16
16
|
if (isExternalUrl(href)) {
|
|
17
17
|
return _jsxs(Directive, { type: "danger", children: ["Invalid href `", href, "` found"] });
|
|
18
18
|
}
|
|
19
|
-
const siteBase = addTrailingSlash(site.base);
|
|
19
|
+
const siteBase = addTrailingSlash(site.base || (site.name === 'acp' ? '/container-platform' : ''));
|
|
20
20
|
return (_jsx("a", { href: (page.v
|
|
21
21
|
? addTrailingSlash(siteBase + normalizeVersion(site.version))
|
|
22
22
|
: siteBase) +
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useSiteOverrides } from '../hooks/index.js';
|
|
3
|
+
export const BrandBase = ({ type }) => {
|
|
4
|
+
const { brand } = useSiteOverrides();
|
|
5
|
+
return _jsx(_Fragment, { children: brand?.[type] });
|
|
6
|
+
};
|
|
@@ -2,6 +2,7 @@ export * from './AcpApisOverview.js';
|
|
|
2
2
|
export * from './Badge.js';
|
|
3
3
|
export * from './Callouts.js';
|
|
4
4
|
export * from './Card.js';
|
|
5
|
+
export * from './CompanyBrand.js';
|
|
5
6
|
export * from './Directive.js';
|
|
6
7
|
export * from './ExternalApisOverview.js';
|
|
7
8
|
export * from './ExternalSite.js';
|
|
@@ -13,6 +14,8 @@ export * from './Overview.js';
|
|
|
13
14
|
export * from './OpenAPIRef.js';
|
|
14
15
|
export * from './OpenAPIPath.js';
|
|
15
16
|
export * from './PackageManagerTabs.js';
|
|
17
|
+
export * from './ProductBrand.js';
|
|
18
|
+
export * from './ProductShortBrand.js';
|
|
16
19
|
export * from './QuickNav.js';
|
|
17
20
|
export * from './Steps.js';
|
|
18
21
|
export * from './Tab.js';
|
|
@@ -2,6 +2,7 @@ export * from './AcpApisOverview.js';
|
|
|
2
2
|
export * from './Badge.js';
|
|
3
3
|
export * from './Callouts.js';
|
|
4
4
|
export * from './Card.js';
|
|
5
|
+
export * from './CompanyBrand.js';
|
|
5
6
|
export * from './Directive.js';
|
|
6
7
|
export * from './ExternalApisOverview.js';
|
|
7
8
|
export * from './ExternalSite.js';
|
|
@@ -13,6 +14,8 @@ export * from './Overview.js';
|
|
|
13
14
|
export * from './OpenAPIRef.js';
|
|
14
15
|
export * from './OpenAPIPath.js';
|
|
15
16
|
export * from './PackageManagerTabs.js';
|
|
17
|
+
export * from './ProductBrand.js';
|
|
18
|
+
export * from './ProductShortBrand.js';
|
|
16
19
|
export * from './QuickNav.js';
|
|
17
20
|
export * from './Steps.js';
|
|
18
21
|
export * from './Tab.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SiteBrand } from '../types.js';
|
|
2
|
+
export interface SiteOverrides {
|
|
3
|
+
brand?: SiteBrand;
|
|
4
|
+
title?: string;
|
|
5
|
+
logoText?: string;
|
|
6
|
+
}
|
|
7
|
+
export type SiteOverridesWithLangs = {
|
|
8
|
+
[K in keyof SiteOverrides]: Record<string, SiteOverrides[K]>;
|
|
9
|
+
};
|
|
10
|
+
export declare const useSiteOverrides: () => SiteOverrides;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { addTrailingSlash } from '@rspress/shared';
|
|
2
|
+
import { isProduction, useLang, usePageData } from '@rspress/core/runtime';
|
|
3
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
4
|
+
import { parse } from 'yaml';
|
|
5
|
+
import { normalizeVersion } from '../../shared/helpers.js';
|
|
6
|
+
let siteOverrides;
|
|
7
|
+
let promise;
|
|
8
|
+
const fetchSiteOverrides = async (base, version, acpSite) => {
|
|
9
|
+
if (promise) {
|
|
10
|
+
return promise;
|
|
11
|
+
}
|
|
12
|
+
const acpSiteOverridesUrl = acpSite
|
|
13
|
+
? `${addTrailingSlash(acpSite.base || '/container-platform')}${version ? normalizeVersion(acpSite.version) + '/' : ''}overrides.yaml`
|
|
14
|
+
: null;
|
|
15
|
+
const siteOverridesUrl = `${isProduction() ? base : '/'}overrides.yaml`;
|
|
16
|
+
const urls = [acpSiteOverridesUrl];
|
|
17
|
+
if (acpSiteOverridesUrl !== siteOverridesUrl) {
|
|
18
|
+
urls.push(siteOverridesUrl);
|
|
19
|
+
}
|
|
20
|
+
return (promise = Promise.all(urls.map(async (url) => {
|
|
21
|
+
if (!url) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const res = await fetch(url);
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return parse(await res.text());
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
//
|
|
33
|
+
}
|
|
34
|
+
})).then(([acpSiteOverrides, siteOverrides]) => (siteOverrides = {
|
|
35
|
+
brand: acpSiteOverrides?.brand,
|
|
36
|
+
...siteOverrides,
|
|
37
|
+
}))).catch(() => ({}));
|
|
38
|
+
};
|
|
39
|
+
export const useSiteOverrides = () => {
|
|
40
|
+
const { siteData, page } = usePageData();
|
|
41
|
+
const [siteOverridesWithLangs, setSiteOverridesWithLangs] = useState(siteOverrides);
|
|
42
|
+
const lang = useLang() || 'zh';
|
|
43
|
+
const acpSite = useMemo(() => page.sites?.find((s) => s.name === 'acp'), []);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (siteOverrides) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
void fetchSiteOverrides(siteData.base, page.v, acpSite).then(setSiteOverridesWithLangs);
|
|
49
|
+
}, []);
|
|
50
|
+
return useMemo(() => {
|
|
51
|
+
if (!siteOverridesWithLangs) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
return Object.entries(siteOverridesWithLangs).reduce((acc, [key, value]) => {
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
56
|
+
if (!value) {
|
|
57
|
+
return acc;
|
|
58
|
+
}
|
|
59
|
+
// @ts-expect-error - don't waste time on typing
|
|
60
|
+
acc[key] = value[lang] || value.en;
|
|
61
|
+
return acc;
|
|
62
|
+
}, {});
|
|
63
|
+
}, [siteOverridesWithLangs, lang]);
|
|
64
|
+
};
|
package/lib/runtime/types.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import { PageData } from '@rspress/core';
|
|
|
2
2
|
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
3
|
import type { CustomResourceDefinition } from '../plugins/api/types.js';
|
|
4
4
|
import type { DoomSite } from '../shared/types.js';
|
|
5
|
+
export interface SiteBrand {
|
|
6
|
+
company: string;
|
|
7
|
+
product: string;
|
|
8
|
+
productShort: string;
|
|
9
|
+
}
|
|
5
10
|
export interface ExtendedPage {
|
|
6
11
|
crdsMap?: Record<string, CustomResourceDefinition>;
|
|
7
12
|
openapisMap?: Record<string, OpenAPIV3_1.Document>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const resolveRepo: (repo: string, force?: boolean, branch?: string) => Promise<string | undefined>;
|
package/lib/utils/git.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { logger } from '@rspress/shared/logger';
|
|
4
|
+
import { simpleGit } from 'simple-git';
|
|
5
|
+
import { cyan, red } from 'yoctocolors';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
const remotesFolder = path.resolve(os.homedir(), '.doom/remotes');
|
|
8
|
+
const DEFAULT_USERNAME = 'oauth2';
|
|
9
|
+
const { GITHUB_USERNAME = DEFAULT_USERNAME, GITHUB_TOKEN, GITLAB_USERNAME = DEFAULT_USERNAME, GITLAB_TOKEN, } = process.env;
|
|
10
|
+
export const resolveRepo = async (repo, force, branch) => {
|
|
11
|
+
const url = new URL(repo, 'https://gitlab-ce.alauda.cn');
|
|
12
|
+
const slug = url.pathname.slice(1);
|
|
13
|
+
if (!slug) {
|
|
14
|
+
logger.error(`Invalid repository URL: ${red(repo)}`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const repoFolder = path.resolve(remotesFolder, slug);
|
|
18
|
+
let created = false;
|
|
19
|
+
try {
|
|
20
|
+
const stat = await fs.stat(path.resolve(repoFolder, '.git'));
|
|
21
|
+
if (stat.isDirectory()) {
|
|
22
|
+
created = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// ignore
|
|
27
|
+
}
|
|
28
|
+
if (!created) {
|
|
29
|
+
await fs.mkdir(repoFolder, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
const git = simpleGit(repoFolder);
|
|
32
|
+
if (!created) {
|
|
33
|
+
logger.info(`Cloning remote \`${cyan(slug)}\` repository...`);
|
|
34
|
+
switch (url.hostname) {
|
|
35
|
+
case 'github.com': {
|
|
36
|
+
if (GITHUB_TOKEN) {
|
|
37
|
+
url.username = GITHUB_USERNAME;
|
|
38
|
+
url.password = GITHUB_TOKEN;
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case 'gitlab-ce.alauda.cn': {
|
|
43
|
+
if (GITLAB_TOKEN) {
|
|
44
|
+
url.username = GITLAB_USERNAME;
|
|
45
|
+
url.password = GITLAB_TOKEN;
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
default: {
|
|
50
|
+
logger.warn(`Unsupported remote host: ${red(url.hostname)}, use on your own risk`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
await git.clone(url.toString(), repoFolder, ['--depth', '1']);
|
|
54
|
+
}
|
|
55
|
+
const currentBranch = (await git.raw(['branch', '--show-current'])).trim();
|
|
56
|
+
const options = ['--depth', '1', '--force'];
|
|
57
|
+
if (branch && branch !== currentBranch) {
|
|
58
|
+
logger.info(`Switching to branch \`${cyan(branch)}\`...`);
|
|
59
|
+
await git.fetch('origin', `${branch}:${branch}`, options);
|
|
60
|
+
await git.checkout(branch);
|
|
61
|
+
}
|
|
62
|
+
else if (force) {
|
|
63
|
+
logger.info(`Pulling latest changes for \`${cyan(slug)}\`...`);
|
|
64
|
+
const pull = () => git.pull([...options, '--rebase', '--allow-unrelated-histories']);
|
|
65
|
+
try {
|
|
66
|
+
await pull();
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
await pull();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return repoFolder;
|
|
73
|
+
};
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
package/lib/utils/types.d.ts
CHANGED
|
@@ -3,12 +3,20 @@ import type { ApiPluginOptions } from '../plugins/api/types.js';
|
|
|
3
3
|
import type { AutoSidebarPluginOptions } from '../plugins/index.js';
|
|
4
4
|
import type { ReferenceItem, ReleaseNotesOptions } from '../plugins/replace/types.js';
|
|
5
5
|
import type { DoomSite } from '../shared/index.js';
|
|
6
|
+
export interface GlobalCliOptions {
|
|
7
|
+
config?: string;
|
|
8
|
+
prefix?: string;
|
|
9
|
+
v?: string;
|
|
10
|
+
ignore?: boolean;
|
|
11
|
+
force?: boolean;
|
|
12
|
+
}
|
|
6
13
|
export interface DoomConfig extends UserConfig {
|
|
7
14
|
api?: ApiPluginOptions;
|
|
8
15
|
sites?: DoomSite[];
|
|
9
16
|
reference?: ReferenceItem[];
|
|
10
17
|
sidebar?: AutoSidebarPluginOptions;
|
|
11
18
|
releaseNotes?: ReleaseNotesOptions;
|
|
19
|
+
internalRoutes?: string[];
|
|
12
20
|
}
|
|
13
21
|
export type ContentProcessor = {
|
|
14
22
|
type: 'ejsTemplate';
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://gitlab-ce.alauda.cn/idp/Doom.git"
|
|
9
9
|
},
|
|
10
|
-
"packageManager": "yarn@4.
|
|
10
|
+
"packageManager": "yarn@4.6.0",
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=18.17.0 <20 || >=20.1.0"
|
|
13
13
|
},
|
|
@@ -33,51 +33,55 @@
|
|
|
33
33
|
"lint": "run-p 'lint:*'",
|
|
34
34
|
"lint:es": "eslint .",
|
|
35
35
|
"lint:tsc": "tsc -b",
|
|
36
|
-
"prepare": "simple-git-hooks",
|
|
36
|
+
"prepare": "simple-git-hooks && patch-package",
|
|
37
37
|
"prepublishOnly": "yarn build",
|
|
38
38
|
"swc-node": "node --enable-source-maps --import @swc-node/register/esm-register"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@inquirer/prompts": "^7.2.
|
|
41
|
+
"@inquirer/prompts": "^7.2.3",
|
|
42
42
|
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
|
|
43
|
-
"@rspress/core": "1.
|
|
44
|
-
"@shikijs/transformers": "^1.
|
|
43
|
+
"@rspress/core": "1.40.0",
|
|
44
|
+
"@shikijs/transformers": "^1.27.2",
|
|
45
45
|
"chokidar": "^4.0.3",
|
|
46
46
|
"clsx": "^2.1.1",
|
|
47
47
|
"commander": "^12.1.0",
|
|
48
48
|
"ejs": "^3.1.10",
|
|
49
49
|
"es-toolkit": "^1.31.0",
|
|
50
50
|
"openapi-types": "^12.1.3",
|
|
51
|
+
"picomatch": "^4.0.2",
|
|
51
52
|
"react-markdown": "^8.0.7",
|
|
52
53
|
"rehype-raw": "^6.1.1",
|
|
54
|
+
"remark-directive": "^2.0.1",
|
|
53
55
|
"remark-frontmatter": "^4.0.1",
|
|
54
56
|
"remark-gfm": "^3.0.1",
|
|
55
|
-
"shiki": "^1.
|
|
57
|
+
"shiki": "^1.27.2",
|
|
56
58
|
"simple-git": "^3.27.0",
|
|
57
59
|
"swagger2openapi": "^7.0.8",
|
|
58
60
|
"tinyglobby": "^0.2.10",
|
|
59
|
-
"type-fest": "^4.
|
|
61
|
+
"type-fest": "^4.32.0",
|
|
60
62
|
"yaml": "^2.7.0",
|
|
61
63
|
"yoctocolors": "^2.1.1"
|
|
62
64
|
},
|
|
63
65
|
"devDependencies": {
|
|
64
|
-
"@eslint/js": "^9.
|
|
66
|
+
"@eslint/js": "^9.18.0",
|
|
65
67
|
"@swc-node/register": "^1.10.9",
|
|
66
|
-
"@swc/core": "1.10.
|
|
68
|
+
"@swc/core": "1.10.7",
|
|
67
69
|
"@types/ejs": "^3.1.5",
|
|
68
70
|
"@types/eslint__js": "^8.42.3",
|
|
69
71
|
"@types/fs-extra": "^11.0.4",
|
|
70
|
-
"@types/node": "^18.19.
|
|
72
|
+
"@types/node": "^18.19.71",
|
|
73
|
+
"@types/picomatch": "^3.0.1",
|
|
71
74
|
"@types/react-dom": "^18.3.5",
|
|
72
75
|
"@types/swagger2openapi": "^7.0.4",
|
|
73
|
-
"
|
|
74
|
-
"
|
|
76
|
+
"@unts/patch-package": "^8.0.0",
|
|
77
|
+
"eslint": "^9.18.0",
|
|
78
|
+
"lint-staged": "^15.4.0",
|
|
75
79
|
"npm-run-all2": "^7.0.2",
|
|
76
80
|
"prettier": "^3.4.2",
|
|
77
81
|
"prettier-plugin-pkg": "^0.18.1",
|
|
78
82
|
"simple-git-hooks": "^2.11.1",
|
|
79
|
-
"typescript": "^5.7.
|
|
80
|
-
"typescript-eslint": "^8.
|
|
83
|
+
"typescript": "^5.7.3",
|
|
84
|
+
"typescript-eslint": "^8.20.0"
|
|
81
85
|
},
|
|
82
86
|
"publishConfig": {
|
|
83
87
|
"access": "public"
|