@alauda/doom 0.14.1 → 0.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/global.d.ts +1 -28
- package/lib/cli/export.js +4 -5
- package/lib/cli/index.js +3 -2
- package/lib/cli/load-config.d.ts +4 -3
- package/lib/cli/load-config.js +26 -23
- package/lib/cli/new.d.ts +1 -1
- package/lib/cli/new.js +1 -2
- package/lib/cli/translate.js +1 -2
- package/lib/config.d.ts +2 -2
- package/lib/global/SiteOverrides/index.d.ts +1 -2
- package/lib/global/SiteOverrides/index.js +1 -1
- package/lib/global/VersionsNav/NavMenuGroup.d.ts +2 -1
- package/lib/global/VersionsNav/NavMenuGroup.js +3 -5
- package/lib/global/VersionsNav/NavMenuSingleItem.d.ts +9 -8
- package/lib/global/VersionsNav/NavMenuSingleItem.js +7 -5
- package/lib/global/VersionsNav/index.d.ts +1 -2
- package/lib/global/VersionsNav/index.js +20 -8
- package/lib/plugins/api/index.d.ts +2 -1
- package/lib/plugins/api/index.js +4 -4
- package/lib/plugins/auto-sidebar/index.d.ts +3 -1
- package/lib/plugins/auto-sidebar/index.js +2 -1
- package/lib/plugins/auto-sidebar/type.d.ts +0 -2
- package/lib/plugins/auto-sidebar/walk.d.ts +2 -2
- package/lib/plugins/auto-sidebar/walk.js +2 -1
- package/lib/plugins/global/index.d.ts +7 -3
- package/lib/plugins/global/index.js +7 -5
- package/lib/plugins/permission/index.d.ts +2 -1
- package/lib/plugins/permission/index.js +3 -3
- package/lib/plugins/replace/index.d.ts +4 -5
- package/lib/plugins/replace/index.js +22 -19
- package/lib/plugins/replace/types.d.ts +1 -1
- package/lib/plugins/replace/utils.d.ts +1 -1
- package/lib/plugins/replace/utils.js +1 -1
- package/lib/runtime/hooks/useTranslation.d.ts +1 -1
- package/lib/runtime/index.js +2 -0
- package/lib/runtime/translation.d.ts +2 -0
- package/lib/runtime/translation.js +2 -0
- package/lib/shared/helpers.d.ts +2 -0
- package/lib/shared/helpers.js +2 -0
- package/lib/types.d.ts +30 -0
- package/lib/utils/helpers.d.ts +1 -2
- package/lib/utils/helpers.js +2 -3
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -1
- package/lib/utils/types.d.ts +14 -13
- package/package.json +3 -2
- package/lib/cli/export-pdf-core/utils/filterRoute.d.ts +0 -8
- package/lib/cli/export-pdf-core/utils/filterRoute.js +0 -11
- package/lib/cli/export-pdf-core/utils/timeTransformer.d.ts +0 -8
- package/lib/cli/export-pdf-core/utils/timeTransformer.js +0 -22
- package/lib/plugins/reference/index.d.ts +0 -10
- package/lib/plugins/reference/index.js +0 -60
- package/lib/plugins/reference/normalize-img-src.d.ts +0 -10
- package/lib/plugins/reference/normalize-img-src.js +0 -59
- package/lib/plugins/reference/parse-toc.d.ts +0 -17
- package/lib/plugins/reference/parse-toc.js +0 -51
- package/lib/plugins/reference/remark-normalize-link.d.ts +0 -12
- package/lib/plugins/reference/remark-normalize-link.js +0 -114
- package/lib/plugins/reference/remark-replace.d.ts +0 -16
- package/lib/plugins/reference/remark-replace.js +0 -172
- package/lib/plugins/reference/remark-toc.d.ts +0 -19
- package/lib/plugins/reference/remark-toc.js +0 -61
- package/lib/plugins/reference/resolve-reference.d.ts +0 -8
- package/lib/plugins/reference/resolve-reference.js +0 -134
- package/lib/plugins/reference/resolve-release.d.ts +0 -2
- package/lib/plugins/reference/resolve-release.js +0 -93
- package/lib/plugins/reference/types.d.ts +0 -32
- package/lib/plugins/reference/utils.d.ts +0 -14
- package/lib/plugins/reference/utils.js +0 -85
- package/lib/plugins/replace/remark-jsx-table.d.ts +0 -3
- package/lib/plugins/replace/remark-jsx-table.js +0 -10
- package/lib/runtime/components/CompanyBrand.d.ts +0 -2
- package/lib/runtime/components/CompanyBrand.js +0 -4
- package/lib/runtime/components/ProductBrand.d.ts +0 -2
- package/lib/runtime/components/ProductBrand.js +0 -4
- package/lib/runtime/components/ProductShortBrand.d.ts +0 -2
- package/lib/runtime/components/ProductShortBrand.js +0 -4
- package/lib/runtime/components/_BrandBase.d.ts +0 -5
- package/lib/runtime/components/_BrandBase.js +0 -7
- package/lib/runtime/components/_Directive.d.ts +0 -10
- package/lib/runtime/components/_Directive.js +0 -16
- package/lib/runtime/hooks/use.d.ts +0 -12
- package/lib/runtime/hooks/use.js +0 -37
- package/lib/runtime/types.d.ts +0 -5
- package/lib/runtime/types.js +0 -1
- package/lib/shared/constants.d.ts +0 -3
- package/lib/shared/constants.js +0 -6
- /package/lib/{plugins/reference/types.js → types.js} +0 -0
|
@@ -3,25 +3,28 @@ import { logger } from '@rspress/shared/logger';
|
|
|
3
3
|
import { remarkExplicitJsx } from './remark-explicit-jsx.js';
|
|
4
4
|
import { MD_RELEASE_COMMENT_PATTERN, MDX_RELEASE_COMMENT_PATTERN, remarkReplace, } from './remark-replace.js';
|
|
5
5
|
import { mdProcessor, mdxProcessor, normalizeReferenceItems } from './utils.js';
|
|
6
|
-
export
|
|
7
|
-
|
|
6
|
+
export * from './normalize-img-src.js';
|
|
7
|
+
export * from './utils.js';
|
|
8
|
+
export const replacePlugin = ({ lang, localBasePath, force, }) => {
|
|
9
|
+
let userConfig;
|
|
10
|
+
let normalizedItems;
|
|
8
11
|
return {
|
|
9
12
|
name: 'doom-replace',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
config(config) {
|
|
14
|
+
config.markdown = config.markdown ?? {};
|
|
15
|
+
config.markdown.remarkPlugins = config.markdown.remarkPlugins ?? [];
|
|
16
|
+
config.markdown.remarkPlugins.push([
|
|
17
|
+
remarkReplace,
|
|
18
|
+
{
|
|
19
|
+
lang,
|
|
20
|
+
localBasePath,
|
|
21
|
+
root: config.root,
|
|
22
|
+
items: (normalizedItems = normalizeReferenceItems(config.reference)),
|
|
23
|
+
releaseNotes: config.releaseNotes,
|
|
24
|
+
force,
|
|
25
|
+
},
|
|
26
|
+
], remarkExplicitJsx);
|
|
27
|
+
return (userConfig = config);
|
|
25
28
|
},
|
|
26
29
|
async modifySearchIndexData(pages) {
|
|
27
30
|
const results = await Promise.allSettled(pages.map(async (page) => {
|
|
@@ -38,10 +41,10 @@ export const replacePlugin = ({ root, lang, localBasePath, items = [], force, re
|
|
|
38
41
|
const compiler = processor().data('pageMeta', {}).use(remarkReplace, {
|
|
39
42
|
lang,
|
|
40
43
|
localBasePath,
|
|
41
|
-
root,
|
|
44
|
+
root: userConfig.root,
|
|
42
45
|
items: normalizedItems,
|
|
43
46
|
force,
|
|
44
|
-
releaseNotes,
|
|
47
|
+
releaseNotes: userConfig.releaseNotes,
|
|
45
48
|
});
|
|
46
49
|
const vfile = await compiler.process({
|
|
47
50
|
path: filepath,
|
|
@@ -6,7 +6,7 @@ import type { NormalizedReferenceSource, ReferenceItem } from './types.js';
|
|
|
6
6
|
* hello world {#custom-id} -> { text: 'hello world', id: 'custom-id' }
|
|
7
7
|
*/
|
|
8
8
|
export declare const extractTextAndId: (title: string) => string[];
|
|
9
|
-
export declare const normalizeReferenceItems: (items
|
|
9
|
+
export declare const normalizeReferenceItems: (items?: ReferenceItem[]) => Record<string, NormalizedReferenceSource>;
|
|
10
10
|
export declare const getASTNodeImport: (name: string, from: string) => MdxjsEsm;
|
|
11
11
|
export declare const stringifySettings: Options;
|
|
12
12
|
export declare const mdProcessor: import("unified").FrozenProcessor<Root, Root, Root, string>;
|
|
@@ -15,7 +15,7 @@ export const extractTextAndId = (title) => {
|
|
|
15
15
|
const customId = title.match(customIdReg)?.[0]?.slice(2, -1) || '';
|
|
16
16
|
return [text, customId];
|
|
17
17
|
};
|
|
18
|
-
export const normalizeReferenceItems = (items) => items.reduce((acc, curr) => {
|
|
18
|
+
export const normalizeReferenceItems = (items = []) => items.reduce((acc, curr) => {
|
|
19
19
|
for (const source of curr.sources) {
|
|
20
20
|
if (source.name in acc) {
|
|
21
21
|
logger.error(`Duplicate source name \`${red(source.name)}\` will be deduplicated`);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type Locale } from '../translation.js';
|
|
2
2
|
export declare const useLocale: () => Locale;
|
|
3
|
-
export declare const useTranslation: () => (key: "function" | "description" | "name" | "delete" | "create" | "update" | "view" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases") => string;
|
|
3
|
+
export declare const useTranslation: () => (key: "function" | "description" | "name" | "delete" | "download" | "create" | "update" | "view" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases") => string;
|
package/lib/runtime/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
|
2
|
+
/// <reference path="../../shim.d.ts" />
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
|
2
4
|
/// <reference path="../../global.d.ts" preserve="true" />
|
|
3
5
|
export * from '../terms.js';
|
|
4
6
|
export * from './components/index.js';
|
|
@@ -15,6 +15,7 @@ export declare const TRANSLATIONS: {
|
|
|
15
15
|
description: string;
|
|
16
16
|
chinese_bad_cases: string;
|
|
17
17
|
english_bad_cases: string;
|
|
18
|
+
download: string;
|
|
18
19
|
};
|
|
19
20
|
zh: {
|
|
20
21
|
collapse_all: string;
|
|
@@ -32,6 +33,7 @@ export declare const TRANSLATIONS: {
|
|
|
32
33
|
description: string;
|
|
33
34
|
chinese_bad_cases: string;
|
|
34
35
|
english_bad_cases: string;
|
|
36
|
+
download: string;
|
|
35
37
|
};
|
|
36
38
|
};
|
|
37
39
|
export type Locale = keyof typeof TRANSLATIONS;
|
|
@@ -14,6 +14,7 @@ const en = {
|
|
|
14
14
|
description: 'Description',
|
|
15
15
|
chinese_bad_cases: 'Chinese Bad Cases',
|
|
16
16
|
english_bad_cases: 'English Bad Cases',
|
|
17
|
+
download: 'Download PDF',
|
|
17
18
|
};
|
|
18
19
|
const zh = {
|
|
19
20
|
collapse_all: '全部收起',
|
|
@@ -31,5 +32,6 @@ const zh = {
|
|
|
31
32
|
description: '描述',
|
|
32
33
|
chinese_bad_cases: '中文反例',
|
|
33
34
|
english_bad_cases: '英文反例',
|
|
35
|
+
download: '下载 PDF',
|
|
34
36
|
};
|
|
35
37
|
export const TRANSLATIONS = { en, zh };
|
package/lib/shared/helpers.d.ts
CHANGED
package/lib/shared/helpers.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
const PLAIN_VERSION_PATTERN = /^(\d+\.)*\d+$/;
|
|
2
2
|
export const normalizeVersion = (version = '') => PLAIN_VERSION_PATTERN.test(version) ? `v${version}` : version;
|
|
3
|
+
export const removeBothEndsSlashes = (str) => str?.replace(/^\/|\/$/g, '') || '';
|
|
4
|
+
export const getPdfName = (lang, userBase, title) => `${removeBothEndsSlashes(userBase) || title || 'exported'}-${lang}.pdf`;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { serve } from '@rspress/core';
|
|
2
|
+
import type { ApiPluginOptions, AutoSidebarPluginOptions, PermissionPluginOptions, ReferenceItem, ReleaseNotesOptions } from './plugins/index.js';
|
|
3
|
+
import type { DoomSite } from './shared/index.js';
|
|
4
|
+
export type BaseServeOptions = Parameters<typeof serve>[0];
|
|
5
|
+
export type ServeOptions = Omit<BaseServeOptions, 'config'>;
|
|
6
|
+
export interface GlobalCliOptions {
|
|
7
|
+
config?: string;
|
|
8
|
+
base?: string;
|
|
9
|
+
prefix?: string;
|
|
10
|
+
v?: string;
|
|
11
|
+
download?: boolean;
|
|
12
|
+
ignore?: boolean;
|
|
13
|
+
force?: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare module '@rspress/shared' {
|
|
16
|
+
interface UserConfig {
|
|
17
|
+
userBase?: string;
|
|
18
|
+
api?: Omit<ApiPluginOptions, 'localBasePath'>;
|
|
19
|
+
sites?: DoomSite[];
|
|
20
|
+
permission?: PermissionPluginOptions;
|
|
21
|
+
reference?: ReferenceItem[];
|
|
22
|
+
sidebar?: Omit<AutoSidebarPluginOptions, 'download' | 'excludeRoutes'>;
|
|
23
|
+
releaseNotes?: ReleaseNotesOptions;
|
|
24
|
+
internalRoutes?: string[];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export type ContentProcessor = {
|
|
28
|
+
type: 'ejsTemplate';
|
|
29
|
+
data?: Record<string, unknown>;
|
|
30
|
+
};
|
package/lib/utils/helpers.d.ts
CHANGED
|
@@ -2,6 +2,5 @@ import type { StringMapper } from '../shared/types.js';
|
|
|
2
2
|
export declare const baseResolve: (...paths: string[]) => string;
|
|
3
3
|
export declare const pkgResolve: (...paths: string[]) => string;
|
|
4
4
|
export declare const resolveStaticConfig: <T = unknown>(filepath: string) => Promise<T>;
|
|
5
|
-
export declare function generateRuntimeModule<T, R = T>(patterns: string[], kind: string, root: string, cwd: string, isProd: boolean, mapper?: (input: T) => R | Promise<R>): Promise<StringMapper>;
|
|
5
|
+
export declare function generateRuntimeModule<T, R = T>(patterns: string[] | undefined, kind: string, root: string, cwd: string, isProd: boolean, mapper?: (input: T) => R | Promise<R>): Promise<StringMapper>;
|
|
6
6
|
export declare const setNodeEnv: (env: "development" | "production") => void;
|
|
7
|
-
export declare const removeBothEndsSlashes: (str: string) => string;
|
package/lib/utils/helpers.js
CHANGED
|
@@ -20,9 +20,9 @@ export const resolveStaticConfig = async (filepath) => {
|
|
|
20
20
|
}
|
|
21
21
|
throw new Error(`Unsupported file extension: ${extname}`);
|
|
22
22
|
};
|
|
23
|
-
export async function generateRuntimeModule(patterns, kind, root, cwd, isProd, mapper) {
|
|
23
|
+
export async function generateRuntimeModule(patterns = [], kind, root, cwd, isProd, mapper) {
|
|
24
24
|
const runtimeModules = {};
|
|
25
|
-
const files = await glob(patterns, { cwd });
|
|
25
|
+
const files = patterns.length ? await glob(patterns, { cwd }) : [];
|
|
26
26
|
for (const file of files) {
|
|
27
27
|
const result = await resolveStaticConfig(path.resolve(cwd, file));
|
|
28
28
|
runtimeModules[`doom-@${kind}/${file}.mjs`] =
|
|
@@ -38,4 +38,3 @@ export async function generateRuntimeModule(patterns, kind, root, cwd, isProd, m
|
|
|
38
38
|
export const setNodeEnv = (env) => {
|
|
39
39
|
process.env.NODE_ENV = env;
|
|
40
40
|
};
|
|
41
|
-
export const removeBothEndsSlashes = (str) => str.replace(/^\/|\/$/g, '');
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
package/lib/utils/types.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type { serve
|
|
2
|
-
import type { ApiPluginOptions } from '../plugins/
|
|
3
|
-
import type { AutoSidebarPluginOptions } from '../plugins/index.js';
|
|
4
|
-
import type { PermissionPluginOptions } from '../plugins/permission/types.js';
|
|
5
|
-
import type { ReferenceItem, ReleaseNotesOptions } from '../plugins/replace/types.js';
|
|
1
|
+
import type { serve } from '@rspress/core';
|
|
2
|
+
import type { ApiPluginOptions, AutoSidebarPluginOptions, PermissionPluginOptions, ReferenceItem, ReleaseNotesOptions } from '../plugins/index.js';
|
|
6
3
|
import type { DoomSite } from '../shared/index.js';
|
|
7
4
|
export type BaseServeOptions = Parameters<typeof serve>[0];
|
|
8
5
|
export type ServeOptions = Omit<BaseServeOptions, 'config'>;
|
|
@@ -11,17 +8,21 @@ export interface GlobalCliOptions {
|
|
|
11
8
|
base?: string;
|
|
12
9
|
prefix?: string;
|
|
13
10
|
v?: string;
|
|
11
|
+
download?: boolean;
|
|
14
12
|
ignore?: boolean;
|
|
15
13
|
force?: boolean;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
declare module '@rspress/shared' {
|
|
16
|
+
interface UserConfig {
|
|
17
|
+
userBase?: string;
|
|
18
|
+
api?: Omit<ApiPluginOptions, 'localBasePath'>;
|
|
19
|
+
sites?: DoomSite[];
|
|
20
|
+
permission?: PermissionPluginOptions;
|
|
21
|
+
reference?: ReferenceItem[];
|
|
22
|
+
sidebar?: Omit<AutoSidebarPluginOptions, 'download' | 'excludeRoutes'>;
|
|
23
|
+
releaseNotes?: ReleaseNotesOptions;
|
|
24
|
+
internalRoutes?: string[];
|
|
25
|
+
}
|
|
25
26
|
}
|
|
26
27
|
export type ContentProcessor = {
|
|
27
28
|
type: 'ejsTemplate';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"exports": {
|
|
16
16
|
"./package.json": "./package.json",
|
|
17
17
|
"./config": "./lib/config.js",
|
|
18
|
-
"./runtime": "./lib/runtime/index.js"
|
|
18
|
+
"./runtime": "./lib/runtime/index.js",
|
|
19
|
+
"./types": "./lib/types.js"
|
|
19
20
|
},
|
|
20
21
|
"files": [
|
|
21
22
|
"assets",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Page } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Filter route by a list of glob patterns.
|
|
4
|
-
* @param pages - List of pages.
|
|
5
|
-
* @param routePatterns - List of glob patterns.
|
|
6
|
-
* @returns - List of pages that match the glob patterns.
|
|
7
|
-
*/
|
|
8
|
-
export declare function filterRoute(pages: Page[], routePatterns: string[]): Page[];
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import multimatch from 'multimatch';
|
|
2
|
-
/**
|
|
3
|
-
* Filter route by a list of glob patterns.
|
|
4
|
-
* @param pages - List of pages.
|
|
5
|
-
* @param routePatterns - List of glob patterns.
|
|
6
|
-
* @returns - List of pages that match the glob patterns.
|
|
7
|
-
*/
|
|
8
|
-
export function filterRoute(pages, routePatterns) {
|
|
9
|
-
const pagePaths = multimatch(pages.map(({ path }) => path), routePatterns);
|
|
10
|
-
return pages.filter(({ path }) => pagePaths.includes(path));
|
|
11
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* get current time in format: YYYY-MM-DD-HH-mm-ss
|
|
3
|
-
* @param timestamp - Timestamp
|
|
4
|
-
* @param lang - Language
|
|
5
|
-
* @param dateOptions - Date options
|
|
6
|
-
* @returns - Date string
|
|
7
|
-
*/
|
|
8
|
-
export declare function timeTransformer(timestamp?: Date, lang?: string, dateOptions?: Intl.DateTimeFormatOptions): string;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const options = {
|
|
2
|
-
year: 'numeric',
|
|
3
|
-
month: '2-digit',
|
|
4
|
-
day: '2-digit',
|
|
5
|
-
hour: '2-digit',
|
|
6
|
-
minute: '2-digit',
|
|
7
|
-
second: '2-digit',
|
|
8
|
-
hour12: false,
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* get current time in format: YYYY-MM-DD-HH-mm-ss
|
|
12
|
-
* @param timestamp - Timestamp
|
|
13
|
-
* @param lang - Language
|
|
14
|
-
* @param dateOptions - Date options
|
|
15
|
-
* @returns - Date string
|
|
16
|
-
*/
|
|
17
|
-
export function timeTransformer(timestamp = new Date(), lang = 'zh-CN', dateOptions = options) {
|
|
18
|
-
return new Date(timestamp)
|
|
19
|
-
.toLocaleString(lang, dateOptions)
|
|
20
|
-
.replaceAll(/(\/|:|)/g, '')
|
|
21
|
-
.replace(/\s/, '-');
|
|
22
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { RspressPlugin } from '@rspress/core';
|
|
2
|
-
import type { ReferenceItem, ReleaseNotesOptions } from './types.js';
|
|
3
|
-
export declare const referencePlugin: ({ root, lang, localBasePath, items, force, releaseNotes, }: {
|
|
4
|
-
root: string;
|
|
5
|
-
lang: string | null;
|
|
6
|
-
localBasePath: string;
|
|
7
|
-
items?: ReferenceItem[];
|
|
8
|
-
force?: boolean;
|
|
9
|
-
releaseNotes?: ReleaseNotesOptions;
|
|
10
|
-
}) => RspressPlugin;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import { logger } from '@rspress/shared/logger';
|
|
3
|
-
import { MD_RELEASE_COMMENT_PATTERN, MDX_RELEASE_COMMENT_PATTERN, remarkReplace, } from './remark-replace.js';
|
|
4
|
-
import { mdProcessor, mdxProcessor, normalizeReferenceItems } from './utils.js';
|
|
5
|
-
export const referencePlugin = ({ root, lang, localBasePath, items = [], force, releaseNotes, }) => {
|
|
6
|
-
const normalizedItems = normalizeReferenceItems(items);
|
|
7
|
-
return {
|
|
8
|
-
name: 'doom-reference',
|
|
9
|
-
markdown: {
|
|
10
|
-
remarkPlugins: [
|
|
11
|
-
[
|
|
12
|
-
remarkReplace,
|
|
13
|
-
{
|
|
14
|
-
lang,
|
|
15
|
-
localBasePath,
|
|
16
|
-
root,
|
|
17
|
-
items: normalizedItems,
|
|
18
|
-
releaseNotes,
|
|
19
|
-
force,
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
async modifySearchIndexData(pages) {
|
|
25
|
-
const results = await Promise.allSettled(pages.map(async (page) => {
|
|
26
|
-
const filepath = page._filepath;
|
|
27
|
-
if (!/\.mdx?$/.test(filepath)) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const isMdx = filepath.endsWith('.mdx');
|
|
31
|
-
const content = await fs.readFile(filepath, 'utf8');
|
|
32
|
-
if (!(isMdx ? MDX_RELEASE_COMMENT_PATTERN : MD_RELEASE_COMMENT_PATTERN).test(content)) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const processor = isMdx ? mdxProcessor : mdProcessor;
|
|
36
|
-
const compiler = processor().data('pageMeta', {}).use(remarkReplace, {
|
|
37
|
-
lang,
|
|
38
|
-
localBasePath,
|
|
39
|
-
root,
|
|
40
|
-
items: normalizedItems,
|
|
41
|
-
force,
|
|
42
|
-
releaseNotes,
|
|
43
|
-
});
|
|
44
|
-
const vfile = await compiler.process({
|
|
45
|
-
path: filepath,
|
|
46
|
-
value: content,
|
|
47
|
-
data: {
|
|
48
|
-
original: true,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
page.content = vfile.toString();
|
|
52
|
-
}));
|
|
53
|
-
for (const result of results) {
|
|
54
|
-
if (result.status === 'rejected') {
|
|
55
|
-
logger.error(result.reason);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Content } from 'mdast';
|
|
2
|
-
import type { NormalizedReferenceSource } from './types.js';
|
|
3
|
-
export declare const normalizeImgSrc: (content: Content, { refSource, localPublicBase, publicBase, sourceBase, targetBase, force, }: {
|
|
4
|
-
refSource: NormalizedReferenceSource;
|
|
5
|
-
localPublicBase: string;
|
|
6
|
-
publicBase: string;
|
|
7
|
-
sourceBase: string;
|
|
8
|
-
targetBase: string;
|
|
9
|
-
force?: boolean;
|
|
10
|
-
}) => Content;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { isExternalUrl, removeLeadingSlash } from '@rspress/core';
|
|
4
|
-
import { cloneDeep } from 'es-toolkit';
|
|
5
|
-
import { visit } from 'unist-util-visit';
|
|
6
|
-
const RELATIVE_URL_PATTERN = /^\.\.?\//;
|
|
7
|
-
export const normalizeImgSrc = (content, { refSource, localPublicBase, publicBase, sourceBase, targetBase, force, }) => {
|
|
8
|
-
content = cloneDeep(content);
|
|
9
|
-
const resolveImgSrc = (src, force) => {
|
|
10
|
-
if (isExternalUrl(src)) {
|
|
11
|
-
return src;
|
|
12
|
-
}
|
|
13
|
-
if (refSource.repo) {
|
|
14
|
-
const targetDir = path.resolve(localPublicBase, '_remotes', refSource.name);
|
|
15
|
-
let sourcePath;
|
|
16
|
-
let targetPath;
|
|
17
|
-
let imageSrc;
|
|
18
|
-
if (RELATIVE_URL_PATTERN.test(src)) {
|
|
19
|
-
sourcePath = path.resolve(sourceBase, src);
|
|
20
|
-
imageSrc = path.relative(sourceBase, sourcePath);
|
|
21
|
-
targetPath = path.resolve(targetDir, imageSrc);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
imageSrc = removeLeadingSlash(src);
|
|
25
|
-
sourcePath = path.resolve(publicBase, imageSrc);
|
|
26
|
-
targetPath = path.resolve(targetDir, imageSrc);
|
|
27
|
-
}
|
|
28
|
-
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
29
|
-
if (force || !fs.existsSync(targetPath)) {
|
|
30
|
-
fs.copyFileSync(sourcePath, targetPath);
|
|
31
|
-
}
|
|
32
|
-
return `/_remotes/${refSource.name}/${imageSrc}`;
|
|
33
|
-
}
|
|
34
|
-
else if (!RELATIVE_URL_PATTERN.test(src)) {
|
|
35
|
-
return src;
|
|
36
|
-
}
|
|
37
|
-
const targetSrc = path.relative(targetBase, path.resolve(sourceBase, src));
|
|
38
|
-
return RELATIVE_URL_PATTERN.test(targetSrc) ? targetSrc : `./${targetSrc}`;
|
|
39
|
-
};
|
|
40
|
-
visit(content, 'image', (node) => {
|
|
41
|
-
node.url = resolveImgSrc(node.url, force);
|
|
42
|
-
});
|
|
43
|
-
visit(content, ['mdxJsxFlowElement', 'mdxJsxTextElement'], (node_) => {
|
|
44
|
-
const node = node_;
|
|
45
|
-
if (node.name !== 'img') {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const srcNode = node.attributes.find((attr) => 'name' in attr && attr.name === 'src');
|
|
49
|
-
if (srcNode?.type !== 'mdxJsxAttribute') {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const src = srcNode.value;
|
|
53
|
-
if (typeof src !== 'string') {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
srcNode.value = resolveImgSrc(src, force);
|
|
57
|
-
});
|
|
58
|
-
return content;
|
|
59
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Root } from 'mdast';
|
|
2
|
-
export interface TocItem {
|
|
3
|
-
id: string;
|
|
4
|
-
text: string;
|
|
5
|
-
depth: number;
|
|
6
|
-
index: number;
|
|
7
|
-
}
|
|
8
|
-
export interface PageMeta {
|
|
9
|
-
toc: TocItem[];
|
|
10
|
-
title: string;
|
|
11
|
-
headingTitle: string;
|
|
12
|
-
frontmatter?: Record<string, unknown>;
|
|
13
|
-
}
|
|
14
|
-
export declare const parseToc: (tree: Root, allDepths?: boolean) => {
|
|
15
|
-
title: string;
|
|
16
|
-
toc: TocItem[];
|
|
17
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import Slugger from 'github-slugger';
|
|
2
|
-
import { visitChildren } from 'unist-util-visit-children';
|
|
3
|
-
import { extractTextAndId } from './utils.js';
|
|
4
|
-
export const parseToc = (tree, allDepths) => {
|
|
5
|
-
let title = '';
|
|
6
|
-
const toc = [];
|
|
7
|
-
const slugger = new Slugger();
|
|
8
|
-
visitChildren((node, index) => {
|
|
9
|
-
if (node.type !== 'heading' || !node.depth || !node.children) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
// Collect h1 ~ h4 by default
|
|
13
|
-
if (allDepths || node.depth < 5) {
|
|
14
|
-
let customId = '';
|
|
15
|
-
const text = node.children
|
|
16
|
-
.map((child) => {
|
|
17
|
-
if (child.type === 'link') {
|
|
18
|
-
return child.children?.map((item) => item.value).join('');
|
|
19
|
-
}
|
|
20
|
-
if (child.type === 'strong') {
|
|
21
|
-
return `**${child.children?.map((item) => item.value).join('')}**`;
|
|
22
|
-
}
|
|
23
|
-
if (child.type === 'text') {
|
|
24
|
-
const [textPart, idPart] = extractTextAndId(child.value);
|
|
25
|
-
customId = idPart;
|
|
26
|
-
return textPart;
|
|
27
|
-
}
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
29
|
-
if (child.type === 'inlineCode') {
|
|
30
|
-
return `\`${child.value}\``;
|
|
31
|
-
}
|
|
32
|
-
return '';
|
|
33
|
-
})
|
|
34
|
-
.join('');
|
|
35
|
-
if (!allDepths && node.depth === 1) {
|
|
36
|
-
if (!title) {
|
|
37
|
-
title = text;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
const id = customId ? customId : slugger.slug(text);
|
|
42
|
-
const { depth } = node;
|
|
43
|
-
toc.push({ id, text, depth, index });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
})(tree);
|
|
47
|
-
return {
|
|
48
|
-
title,
|
|
49
|
-
toc,
|
|
50
|
-
};
|
|
51
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Root } from 'mdast';
|
|
2
|
-
import type { Plugin } from 'unified';
|
|
3
|
-
/**
|
|
4
|
-
* Remark plugin to normalize a link href
|
|
5
|
-
*/
|
|
6
|
-
export declare const remarkPluginNormalizeLink: Plugin<[
|
|
7
|
-
{
|
|
8
|
-
base: string;
|
|
9
|
-
root: string;
|
|
10
|
-
cleanUrls: boolean;
|
|
11
|
-
}
|
|
12
|
-
], Root>;
|