@alauda/doom 1.19.1 → 1.20.1

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/export.js CHANGED
@@ -4,6 +4,7 @@ import { generatePdf, } from '@alauda/doom-export';
4
4
  import { logger, serve } from '@rspress/core';
5
5
  import { removeLeadingSlash } from '@rspress/shared';
6
6
  import { Command } from 'commander';
7
+ import { groupBy } from 'es-toolkit';
7
8
  import { cyan, yellow } from 'yoctocolors';
8
9
  import { autoSidebar, } from '../plugins/index.js';
9
10
  import { getPdfName } from '../shared/index.js';
@@ -33,7 +34,7 @@ const collectPages = (sidebarItems, base) => {
33
34
  export const exportCommand = new Command('export')
34
35
  .description('Export the documentation as PDF, `apis/**` and `*/apis/**` routes will be ignored automatically')
35
36
  .argument('[root]', 'Root directory of the documentation')
36
- .option('-H, --host [host]', 'Serve host name')
37
+ .option('-H, --host [host]', 'Serve host name', 'localhost')
37
38
  .option('-P, --port [port]', 'Serve port number', '4173')
38
39
  .action(async function (root) {
39
40
  setNodeEnv('production');
@@ -60,7 +61,7 @@ export const exportCommand = new Command('export')
60
61
  const commonOptions = {
61
62
  tempDir,
62
63
  port: port,
63
- host: host || 'localhost',
64
+ host: host,
64
65
  outDir,
65
66
  pdfOptions: {
66
67
  margin: {
@@ -92,16 +93,55 @@ export const exportCommand = new Command('export')
92
93
  outlineExcludeSelector: '.rp-toc-exclude *',
93
94
  },
94
95
  };
95
- const exportPdf = async (sidebarItems, lang = config.lang, options) => {
96
- const pages = collectPages(sidebarItems, config.base);
96
+ const exportPdf = async (sidebarItems, lang = config.lang, { includeApisPages, overrideOutlines, ...options } = {}) => {
97
+ let pages = collectPages(sidebarItems, config.base);
98
+ if (!includeApisPages) {
99
+ pages = pages.filter((page) => themeConfig.locales?.length
100
+ ? !themeConfig.locales.some((l) => page.key.startsWith(l.lang === config.lang ? 'apis/' : `${l.lang}/apis/`))
101
+ : !page.key.startsWith('apis/'));
102
+ }
97
103
  const pdfOptions = {
98
104
  pages,
99
105
  outFile: getPdfName(lang, config.userBase, config.title),
100
106
  cleanupTempDir: false,
107
+ customOutlines: overrideOutlines
108
+ ? (pages) => {
109
+ const pageMap = new Map();
110
+ let pageIndex = 0;
111
+ for (const page of pages) {
112
+ pageMap.set(page.url.split('?')[0], {
113
+ title: page.title,
114
+ pageIndex,
115
+ });
116
+ pageIndex += page.count;
117
+ }
118
+ const generateOutlinesFromSidebar = (sidebarItems) => {
119
+ const result = [];
120
+ for (const item of sidebarItems) {
121
+ let children;
122
+ if ('items' in item) {
123
+ children = generateOutlinesFromSidebar(item.items);
124
+ }
125
+ if ('link' in item && item.link) {
126
+ const page = pageMap.get(`${item.link}.html`);
127
+ if (page != null) {
128
+ result.push({
129
+ title: page.title || item.text,
130
+ to: page.pageIndex,
131
+ children,
132
+ });
133
+ }
134
+ }
135
+ }
136
+ return result;
137
+ };
138
+ return generateOutlinesFromSidebar(sidebarItems);
139
+ }
140
+ : undefined,
101
141
  ...commonOptions,
102
142
  ...options,
103
143
  };
104
- logger.start(`Exporting ${options ? 'custom' : 'all'} ${lang} language documents with ${pages.length} pages into ${yellow(pdfOptions.outFile)}...`);
144
+ logger.start(`Exporting ${lang} language documents with ${pages.length} pages into ${yellow(pdfOptions.outFile)}...`);
105
145
  return generatePdf(pdfOptions);
106
146
  };
107
147
  const findScopeFactory = (scope) => function findScope(sidebarItems) {
@@ -123,8 +163,12 @@ export const exportCommand = new Command('export')
123
163
  return found;
124
164
  };
125
165
  const exportItems = config.export || [];
166
+ // eslint-disable-next-line @typescript-eslint/no-useless-default-assignment
167
+ const { apis = [], nonApis = [] } = groupBy(exportItems, (item) => item.scope.some((s) => s.startsWith('apis/') || s.startsWith('*/apis/'))
168
+ ? 'apis'
169
+ : 'nonApis');
126
170
  const exportEntries = async (sidebarItems, allOutlines, lang = config.lang) => {
127
- for (const item of exportItems) {
171
+ for (const item of nonApis) {
128
172
  const found = findScopeFactory(item.flattenScope)(sidebarItems);
129
173
  if (!found?.size) {
130
174
  logger.warn(`Cannot find matched scope \`${cyan(item.scope.join(', '))}\` for lang ${lang}, skip exporting`);
@@ -136,17 +180,33 @@ export const exportCommand = new Command('export')
136
180
  outFile: `${item.name || (foundSidebarItems.find((it) => it.link?.endsWith('/index')) ?? foundSidebarItems[0]).text}-${lang}.pdf`,
137
181
  });
138
182
  }
183
+ for (const item of apis) {
184
+ const found = findScopeFactory(item.flattenScope)(sidebarItems);
185
+ if (!found?.size) {
186
+ logger.warn(`Cannot find matched scope \`${cyan(item.scope.join(', '))}\` for lang ${lang}, skip exporting`);
187
+ continue;
188
+ }
189
+ const foundSidebarItems = [...found];
190
+ await exportPdf(foundSidebarItems, lang, {
191
+ includeApisPages: true,
192
+ outFile: `${item.name || (foundSidebarItems.find((it) => it.link?.endsWith('/index')) ?? foundSidebarItems[0]).text}-${lang}.pdf`,
193
+ });
194
+ }
139
195
  };
140
196
  if (themeConfig.locales?.length) {
141
197
  for (const { lang, sidebar } of themeConfig.locales) {
142
198
  const sidebarItems = sidebar[config.lang === lang ? '/' : `/${lang}`];
143
- const { allOutlines } = await exportPdf(sidebarItems, lang);
199
+ const { allOutlines } = await exportPdf(sidebarItems, lang, {
200
+ overrideOutlines: true,
201
+ });
144
202
  await exportEntries(sidebarItems, allOutlines, lang);
145
203
  }
146
204
  }
147
205
  else {
148
206
  const sidebarItems = themeConfig.sidebar['/'];
149
- const { allOutlines } = await exportPdf(sidebarItems);
207
+ const { allOutlines } = await exportPdf(sidebarItems, undefined, {
208
+ overrideOutlines: true,
209
+ });
150
210
  await exportEntries(sidebarItems, allOutlines);
151
211
  }
152
212
  await fs.rm(tempDir, { force: true, recursive: true });
@@ -1,7 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import {} from '@rspress/core';
3
3
  import { addTrailingSlash } from '@rspress/shared';
4
- import { APIS_ROUTES } from "../../shared/index.js";
5
4
  import { combineWalkResult } from "./utils.js";
6
5
  import { walk } from "./walk.js";
7
6
  // Scan all the directories and files in the work directory(such as `docs`), and then generate the nav and sidebar configuration according to the directory structure.
@@ -163,11 +162,6 @@ export const autoSidebar = async (config, { ignore, export: export_ }) => {
163
162
  if (export_ || excludeRoutes.length) {
164
163
  const exclude = (route.exclude ??= []);
165
164
  exclude.push(...excludeRoutes);
166
- // only exclude apis routes for sidebar but not site data to avoid dead links
167
- if (export_ &&
168
- !onlyIncludeRoutes.some((route) => route.startsWith('apis/') || route.startsWith('*/apis/'))) {
169
- excludeRoutes.push(...APIS_ROUTES);
170
- }
171
165
  }
172
166
  config.themeConfig ??= {};
173
167
  config.themeConfig.locales ??= config.locales || [];
@@ -94,7 +94,7 @@ const getRefsForPath = (openapi, path, knownRefs) => {
94
94
  export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathPrefix_, }) => {
95
95
  const { page } = usePage();
96
96
  const pathPrefix = pathPrefix_ ?? (virtual.pathPrefix || '');
97
- const uid = useId();
97
+ const id = useId();
98
98
  const slugger = useMemo(() => new BananaSlug(), []);
99
99
  const [pathItem, openapi, openapiPath, refs] = useMemo(() => {
100
100
  for (const [pathname, openapi] of Object.entries(openapisMap)) {
@@ -117,7 +117,7 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
117
117
  console.error(`No OpenAPI path definition found for ${path}`);
118
118
  return null;
119
119
  }
120
- return (_jsxs(UidProvider, { value: uid, children: [_jsxs(HeadingTitle, { slugger: slugger, level: 2, children: [pathPrefix, path] }), pathItem.parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 3, children: "Common Parameters" }), _jsx(OpenAPIParameters, { parameters: pathItem.parameters, openapi: openapi })] })), Object.values(OpenAPIV3.HttpMethods).map((method) => {
120
+ return (_jsxs(UidProvider, { value: id, children: [_jsxs(HeadingTitle, { slugger: slugger, level: 2, children: [pathPrefix, path] }), pathItem.parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 3, children: "Common Parameters" }), _jsx(OpenAPIParameters, { parameters: pathItem.parameters, openapi: openapi })] })), Object.values(OpenAPIV3.HttpMethods).map((method) => {
121
121
  if (!pathItem[method]) {
122
122
  return null;
123
123
  }
@@ -96,12 +96,12 @@ const getRefsForSchema = (openapi, schema, knownRefs) => {
96
96
  export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, isCommonRef = true, collectRefs = true, }) => {
97
97
  const { page } = usePage();
98
98
  let uid = useUid();
99
- const innerUid = useId();
99
+ const innerId = useId();
100
100
  if (isCommonRef) {
101
101
  uid = ''; // common references do not need a unique ID
102
102
  }
103
103
  else if (!uid) {
104
- uid = innerUid;
104
+ uid = innerId;
105
105
  }
106
106
  // eslint-disable-next-line react-hooks/preserve-manual-memoization
107
107
  const [schemaItem, openapi, openapiPath] = useMemo(() => {
@@ -52,7 +52,7 @@ const fetchSiteOverrides = async (version, acpSite) => {
52
52
  }))
53
53
  .catch(() => ({ terms: namedTerms }))
54
54
  .then(({ terms, ...siteOverrides }) => {
55
- const normalizedSiteOverrides = normalizeOverrides(siteOverrides);
55
+ normalizedSiteOverrides = normalizeOverrides(siteOverrides);
56
56
  const normalizedTerms = normalizeOverrides(terms);
57
57
  return {
58
58
  en: { ...normalizedSiteOverrides.en, terms: normalizedTerms.en },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "1.19.1",
3
+ "version": "1.20.1",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -40,29 +40,29 @@
40
40
  "rspress-plugins"
41
41
  ],
42
42
  "dependencies": {
43
- "@alauda/doom-export": "^0.3.1",
44
- "@cspell/eslint-plugin": "^9.6.3",
45
- "@eslint-react/eslint-plugin": "^2.9.4",
46
- "@inquirer/prompts": "^8.2.0",
43
+ "@alauda/doom-export": "^0.4.0",
44
+ "@cspell/eslint-plugin": "^9.7.0",
45
+ "@eslint-react/eslint-plugin": "^2.13.0",
46
+ "@inquirer/prompts": "^8.3.0",
47
47
  "@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
48
48
  "@rsbuild/plugin-react": "^1.4.5",
49
49
  "@rsbuild/plugin-sass": "^1.5.0",
50
50
  "@rsbuild/plugin-svgr": "^1.3.0",
51
51
  "@rsbuild/plugin-yaml": "^1.0.4",
52
- "@rspress/core": "2.0.2",
53
- "@rspress/plugin-algolia": "2.0.2",
54
- "@rspress/plugin-sitemap": "2.0.2",
55
- "@rspress/shared": "2.0.2",
52
+ "@rspress/core": "2.0.3",
53
+ "@rspress/plugin-algolia": "2.0.3",
54
+ "@rspress/plugin-sitemap": "2.0.3",
55
+ "@rspress/shared": "2.0.3",
56
56
  "@shikijs/transformers": "^3.22.0",
57
57
  "@total-typescript/ts-reset": "^0.6.1",
58
- "@types/react": "^19.2.10",
58
+ "@types/react": "^19.2.14",
59
59
  "ab64": "^0.1.6",
60
60
  "chokidar": "^5.0.0",
61
61
  "clsx": "^2.1.1",
62
62
  "commander": "^14.0.3",
63
63
  "ejs": "^4.0.1",
64
64
  "es-toolkit": "^1.44.0",
65
- "eslint": "^9.39.2",
65
+ "eslint": "^10.0.2",
66
66
  "eslint-plugin-mdx": "^3.6.2",
67
67
  "globals": "^17.3.0",
68
68
  "html-tag-names": "^2.1.0",
@@ -73,8 +73,8 @@
73
73
  "mdast-util-phrasing": "^4.1.0",
74
74
  "mdast-util-to-markdown": "^2.1.2",
75
75
  "mdast-util-to-string": "^4.0.0",
76
- "mermaid": "^11.12.2",
77
- "openai": "^6.17.0",
76
+ "mermaid": "^11.12.3",
77
+ "openai": "^6.24.0",
78
78
  "openapi-types": "^12.1.3",
79
79
  "p-ratelimit": "^1.0.1",
80
80
  "picomatch": "^4.0.3",
@@ -96,13 +96,13 @@
96
96
  "remark-message-control": "^8.0.0",
97
97
  "remark-stringify": "^11.0.0",
98
98
  "shiki": "^3.22.0",
99
- "simple-git": "^3.30.0",
100
- "string-width": "^8.1.1",
99
+ "simple-git": "^3.32.2",
100
+ "string-width": "^8.2.0",
101
101
  "swagger2openapi": "^7.0.8",
102
102
  "tinyglobby": "^0.2.15",
103
- "type-fest": "^5.4.3",
103
+ "type-fest": "^5.4.4",
104
104
  "typescript": "^5.9.3",
105
- "typescript-eslint": "^8.54.0",
105
+ "typescript-eslint": "^8.56.1",
106
106
  "unified": "^11.0.5",
107
107
  "unified-lint-rule": "^3.0.1",
108
108
  "unist-util-position": "^5.0.0",
@@ -69,7 +69,7 @@ td {
69
69
  margin-bottom: 1rem;
70
70
  line-height: 1.75rem;
71
71
 
72
- > .rp-list-decimal {
72
+ > ol {
73
73
  counter-reset: callouts;
74
74
  list-style-type: none;
75
75