@alauda/doom 0.8.3 → 0.8.5
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 +3 -1
- 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 +10 -4
- 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.d.ts +1 -1
- package/lib/plugins/global/index.js +11 -2
- 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/CompanyBrand.d.ts +2 -0
- package/lib/runtime/components/CompanyBrand.js +4 -0
- package/lib/runtime/components/ExternalSiteLink.js +1 -5
- 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 +7 -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 +74 -0
- package/lib/runtime/types.d.ts +5 -0
- package/lib/runtime/utils.d.ts +1 -1
- package/lib/runtime/utils.js +3 -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/package.json +17 -15
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';
|
|
@@ -27,6 +27,7 @@ const getCommonConfig = (config, cliRoot, configFilePath, version, ignore, force
|
|
|
27
27
|
return {
|
|
28
28
|
root,
|
|
29
29
|
lang: fallbackToZh ? 'zh' : config.lang,
|
|
30
|
+
title: '',
|
|
30
31
|
route: {
|
|
31
32
|
exclude: [
|
|
32
33
|
'dist/**/*',
|
|
@@ -67,6 +68,7 @@ const getCommonConfig = (config, cliRoot, configFilePath, version, ignore, force
|
|
|
67
68
|
...config.sidebar,
|
|
68
69
|
excludeRoutes,
|
|
69
70
|
}),
|
|
71
|
+
directivesPlugin(),
|
|
70
72
|
globalPlugin({
|
|
71
73
|
sites: config.sites,
|
|
72
74
|
version,
|
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,12 @@ 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 = () => {
|
|
9
|
+
if (typeof document === 'undefined') {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return document.querySelector('.rspress-nav-menu');
|
|
13
|
+
};
|
|
8
14
|
export const VersionsNav = () => {
|
|
9
15
|
const { siteData, page } = usePageData();
|
|
10
16
|
const [versionsBase, version] = useMemo(() => {
|
|
@@ -16,7 +22,7 @@ export const VersionsNav = () => {
|
|
|
16
22
|
page.v,
|
|
17
23
|
];
|
|
18
24
|
}, [siteData.base, page.v]);
|
|
19
|
-
const [navMenu, setNavMenu] = useState();
|
|
25
|
+
const [navMenu, setNavMenu] = useState(getNavMenu);
|
|
20
26
|
const [versions, setVersions] = useState();
|
|
21
27
|
useEffect(() => {
|
|
22
28
|
const fetchVersions = async () => {
|
|
@@ -25,7 +31,7 @@ export const VersionsNav = () => {
|
|
|
25
31
|
}
|
|
26
32
|
const res = await fetch(`${isProduction() ? versionsBase : ''}/versions.yaml`);
|
|
27
33
|
const text = await res.text();
|
|
28
|
-
setNavMenu(
|
|
34
|
+
setNavMenu(getNavMenu());
|
|
29
35
|
const versions = parse(text);
|
|
30
36
|
if (version && !versions.includes(version)) {
|
|
31
37
|
versions.unshift(version);
|
|
@@ -41,7 +47,7 @@ export const VersionsNav = () => {
|
|
|
41
47
|
}
|
|
42
48
|
const observer = new MutationObserver((mutations) => {
|
|
43
49
|
if (mutations.some((m) => m.removedNodes.length)) {
|
|
44
|
-
setNavMenu(
|
|
50
|
+
setNavMenu(getNavMenu);
|
|
45
51
|
}
|
|
46
52
|
});
|
|
47
53
|
observer.observe(navMenu, { childList: true });
|
|
@@ -56,6 +62,6 @@ export const VersionsNav = () => {
|
|
|
56
62
|
text: v,
|
|
57
63
|
link: `${versionsBase}/${v}/`,
|
|
58
64
|
activeMatch: v,
|
|
59
|
-
})), pathname: siteData.base }),
|
|
65
|
+
})), pathname: siteData.base }), getNavMenu());
|
|
60
66
|
};
|
|
61
67
|
export default VersionsNav;
|
|
@@ -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,17 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { addTrailingSlash } from '@rspress/core';
|
|
3
4
|
import { baseResolve, pkgResolve } from '../../utils/index.js';
|
|
5
|
+
import { normalizeVersion } from '../../shared/helpers.js';
|
|
6
|
+
const globalComponentsDir = baseResolve('global');
|
|
4
7
|
const componentsDir = baseResolve('runtime/components');
|
|
5
8
|
export const globalPlugin = ({ sites, version, } = {}) => {
|
|
6
9
|
return {
|
|
7
10
|
name: 'doom-global',
|
|
8
11
|
globalStyles: pkgResolve('styles/global.scss'),
|
|
9
|
-
globalUIComponents:
|
|
12
|
+
globalUIComponents: fs
|
|
13
|
+
.readdirSync(globalComponentsDir, 'utf8')
|
|
14
|
+
.map((component) => path.resolve(globalComponentsDir, component, 'index')),
|
|
10
15
|
markdown: {
|
|
11
16
|
globalComponents: fs
|
|
12
17
|
.readdirSync(componentsDir)
|
|
@@ -19,7 +24,11 @@ export const globalPlugin = ({ sites, version, } = {}) => {
|
|
|
19
24
|
.map((file) => path.resolve(componentsDir, file)),
|
|
20
25
|
},
|
|
21
26
|
extendPageData(pageData) {
|
|
22
|
-
pageData.sites = sites
|
|
27
|
+
pageData.sites = sites?.map((site) => ({
|
|
28
|
+
...site,
|
|
29
|
+
base: addTrailingSlash(site.base || (site.name === 'acp' ? '/container-platform' : '')),
|
|
30
|
+
version: normalizeVersion(site.version),
|
|
31
|
+
}));
|
|
23
32
|
pageData.v = version === 'unversioned' ? undefined : version;
|
|
24
33
|
},
|
|
25
34
|
};
|
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
|
};
|
|
@@ -3,7 +3,6 @@ import { useLang, usePageData } from '@rspress/core/runtime';
|
|
|
3
3
|
import { addTrailingSlash, isExternalUrl, removeLeadingSlash, } from '@rspress/shared';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
|
-
import { normalizeVersion } from '../../shared/index.js';
|
|
7
6
|
import { Directive } from './Directive.js';
|
|
8
7
|
import classes from '../../../styles/link.module.scss';
|
|
9
8
|
export const ExternalSiteLink = ({ name, href = '', className, ...props }) => {
|
|
@@ -16,10 +15,7 @@ export const ExternalSiteLink = ({ name, href = '', className, ...props }) => {
|
|
|
16
15
|
if (isExternalUrl(href)) {
|
|
17
16
|
return _jsxs(Directive, { type: "danger", children: ["Invalid href `", href, "` found"] });
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
return (_jsx("a", { href: (page.v
|
|
21
|
-
? addTrailingSlash(siteBase + normalizeVersion(site.version))
|
|
22
|
-
: siteBase) +
|
|
18
|
+
return (_jsx("a", { href: (page.v ? addTrailingSlash(site.base + site.version) : site.base) +
|
|
23
19
|
(lang ? `${lang}/` : '') +
|
|
24
20
|
removeLeadingSlash(href), target: "_blank", rel: "noopener noreferrer", className: clsx(classes.link, 'cursor-pointer', className), ...props }));
|
|
25
21
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useSiteOverrides } from '../hooks/index.js';
|
|
3
|
+
import { handleCJKWhitespaces } from '../utils.js';
|
|
4
|
+
export const BrandBase = ({ type }) => {
|
|
5
|
+
const { brand } = useSiteOverrides();
|
|
6
|
+
return _jsx(_Fragment, { children: handleCJKWhitespaces(brand?.[type]) });
|
|
7
|
+
};
|
|
@@ -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,74 @@
|
|
|
1
|
+
import { isProduction, useLang, usePageData } from '@rspress/core/runtime';
|
|
2
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { parse } from 'yaml';
|
|
4
|
+
const DEFAULT_SITE_BRAND = {
|
|
5
|
+
en: {
|
|
6
|
+
company: 'Alauda',
|
|
7
|
+
product: 'Alauda Container Platform',
|
|
8
|
+
productShort: 'ACP',
|
|
9
|
+
},
|
|
10
|
+
zh: {
|
|
11
|
+
company: '灵雀云',
|
|
12
|
+
product: '灵雀云容器平台',
|
|
13
|
+
productShort: 'ACP',
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
let siteOverrides;
|
|
17
|
+
let promise;
|
|
18
|
+
const fetchSiteOverrides = async (base, version, acpSite) => {
|
|
19
|
+
if (promise) {
|
|
20
|
+
return promise;
|
|
21
|
+
}
|
|
22
|
+
const acpSiteOverridesUrl = acpSite && isProduction()
|
|
23
|
+
? `${acpSite.base}${version ? acpSite.version + '/' : ''}overrides.yaml`
|
|
24
|
+
: null;
|
|
25
|
+
const siteOverridesUrl = `${isProduction() ? base : '/'}overrides.yaml`;
|
|
26
|
+
const urls = [acpSiteOverridesUrl];
|
|
27
|
+
if (acpSiteOverridesUrl !== siteOverridesUrl) {
|
|
28
|
+
urls.push(siteOverridesUrl);
|
|
29
|
+
}
|
|
30
|
+
return (promise = Promise.all(urls.map(async (url) => {
|
|
31
|
+
if (!url) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const res = await fetch(url);
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
return parse(await res.text());
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
//
|
|
43
|
+
}
|
|
44
|
+
})).then(([acpSiteOverrides, siteOverrides]) => (siteOverrides = {
|
|
45
|
+
brand: acpSiteOverrides?.brand ?? DEFAULT_SITE_BRAND,
|
|
46
|
+
...siteOverrides,
|
|
47
|
+
}))).catch(() => ({}));
|
|
48
|
+
};
|
|
49
|
+
export const useSiteOverrides = () => {
|
|
50
|
+
const { siteData, page } = usePageData();
|
|
51
|
+
const [siteOverridesWithLangs, setSiteOverridesWithLangs] = useState(siteOverrides);
|
|
52
|
+
const lang = useLang() || 'zh';
|
|
53
|
+
const acpSite = useMemo(() => page.sites?.find((s) => s.name === 'acp'), []);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (siteOverrides) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
void fetchSiteOverrides(siteData.base, page.v, acpSite).then(setSiteOverridesWithLangs);
|
|
59
|
+
}, []);
|
|
60
|
+
return useMemo(() => {
|
|
61
|
+
if (!siteOverridesWithLangs) {
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
return Object.entries(siteOverridesWithLangs).reduce((acc, [key, value]) => {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
66
|
+
if (!value) {
|
|
67
|
+
return acc;
|
|
68
|
+
}
|
|
69
|
+
// @ts-expect-error - don't waste time on typing
|
|
70
|
+
acc[key] = value[lang] || value.en;
|
|
71
|
+
return acc;
|
|
72
|
+
}, {});
|
|
73
|
+
}, [siteOverridesWithLangs, lang]);
|
|
74
|
+
};
|
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>;
|
package/lib/runtime/utils.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export declare const omitRoutePathRefs: (refs: Record<string, string>, routePath
|
|
|
8
8
|
[k: string]: string;
|
|
9
9
|
};
|
|
10
10
|
export declare const CJK_PATTERN: RegExp;
|
|
11
|
-
export declare const handleCJKWhitespaces: (text
|
|
11
|
+
export declare const handleCJKWhitespaces: (text?: string) => string;
|
package/lib/runtime/utils.js
CHANGED
|
@@ -19,6 +19,9 @@ export const DEFAULT_COMMON_REFS = Object.fromEntries(Object.entries(DEFAULT_COM
|
|
|
19
19
|
export const omitRoutePathRefs = (refs, routePath) => Object.fromEntries(Object.entries(refs).filter(([, value]) => routePath !== value.split('#')[0]));
|
|
20
20
|
export const CJK_PATTERN = /\p{sc=Han}/u;
|
|
21
21
|
export const handleCJKWhitespaces = (text) => {
|
|
22
|
+
if (!text) {
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
22
25
|
text = text.at(0)?.match(CJK_PATTERN) ? text : ` ${text}`;
|
|
23
26
|
return text.at(-1)?.match(CJK_PATTERN) ? text : `${text} `;
|
|
24
27
|
};
|
|
@@ -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/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
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,15 +33,15 @@
|
|
|
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",
|
|
@@ -51,35 +51,37 @@
|
|
|
51
51
|
"picomatch": "^4.0.2",
|
|
52
52
|
"react-markdown": "^8.0.7",
|
|
53
53
|
"rehype-raw": "^6.1.1",
|
|
54
|
+
"remark-directive": "^2.0.1",
|
|
54
55
|
"remark-frontmatter": "^4.0.1",
|
|
55
56
|
"remark-gfm": "^3.0.1",
|
|
56
|
-
"shiki": "^1.
|
|
57
|
+
"shiki": "^1.27.2",
|
|
57
58
|
"simple-git": "^3.27.0",
|
|
58
59
|
"swagger2openapi": "^7.0.8",
|
|
59
60
|
"tinyglobby": "^0.2.10",
|
|
60
|
-
"type-fest": "^4.
|
|
61
|
+
"type-fest": "^4.32.0",
|
|
61
62
|
"yaml": "^2.7.0",
|
|
62
63
|
"yoctocolors": "^2.1.1"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
|
-
"@eslint/js": "^9.
|
|
66
|
+
"@eslint/js": "^9.18.0",
|
|
66
67
|
"@swc-node/register": "^1.10.9",
|
|
67
|
-
"@swc/core": "1.10.
|
|
68
|
+
"@swc/core": "1.10.7",
|
|
68
69
|
"@types/ejs": "^3.1.5",
|
|
69
70
|
"@types/eslint__js": "^8.42.3",
|
|
70
71
|
"@types/fs-extra": "^11.0.4",
|
|
71
|
-
"@types/node": "^18.19.
|
|
72
|
+
"@types/node": "^18.19.71",
|
|
72
73
|
"@types/picomatch": "^3.0.1",
|
|
73
74
|
"@types/react-dom": "^18.3.5",
|
|
74
75
|
"@types/swagger2openapi": "^7.0.4",
|
|
75
|
-
"
|
|
76
|
-
"
|
|
76
|
+
"@unts/patch-package": "^8.0.0",
|
|
77
|
+
"eslint": "^9.18.0",
|
|
78
|
+
"lint-staged": "^15.4.1",
|
|
77
79
|
"npm-run-all2": "^7.0.2",
|
|
78
80
|
"prettier": "^3.4.2",
|
|
79
81
|
"prettier-plugin-pkg": "^0.18.1",
|
|
80
82
|
"simple-git-hooks": "^2.11.1",
|
|
81
|
-
"typescript": "^5.7.
|
|
82
|
-
"typescript-eslint": "^8.
|
|
83
|
+
"typescript": "^5.7.3",
|
|
84
|
+
"typescript-eslint": "^8.20.0"
|
|
83
85
|
},
|
|
84
86
|
"publishConfig": {
|
|
85
87
|
"access": "public"
|