@alauda/doom 1.19.1 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/cli/export.js +42 -4
  2. package/package.json +2 -2
package/lib/cli/export.js CHANGED
@@ -33,7 +33,7 @@ const collectPages = (sidebarItems, base) => {
33
33
  export const exportCommand = new Command('export')
34
34
  .description('Export the documentation as PDF, `apis/**` and `*/apis/**` routes will be ignored automatically')
35
35
  .argument('[root]', 'Root directory of the documentation')
36
- .option('-H, --host [host]', 'Serve host name')
36
+ .option('-H, --host [host]', 'Serve host name', 'localhost')
37
37
  .option('-P, --port [port]', 'Serve port number', '4173')
38
38
  .action(async function (root) {
39
39
  setNodeEnv('production');
@@ -60,7 +60,7 @@ export const exportCommand = new Command('export')
60
60
  const commonOptions = {
61
61
  tempDir,
62
62
  port: port,
63
- host: host || 'localhost',
63
+ host: host,
64
64
  outDir,
65
65
  pdfOptions: {
66
66
  margin: {
@@ -98,6 +98,40 @@ export const exportCommand = new Command('export')
98
98
  pages,
99
99
  outFile: getPdfName(lang, config.userBase, config.title),
100
100
  cleanupTempDir: false,
101
+ customOutlines: options?.overrideOutlines
102
+ ? (pages) => {
103
+ const pageMap = new Map();
104
+ let pageIndex = 0;
105
+ for (const page of pages) {
106
+ pageMap.set(page.url.split('?')[0], {
107
+ title: page.title,
108
+ pageIndex,
109
+ });
110
+ pageIndex += page.count;
111
+ }
112
+ const generateOutlinesFromSidebar = (sidebarItems) => {
113
+ const result = [];
114
+ for (const item of sidebarItems) {
115
+ let children;
116
+ if ('items' in item) {
117
+ children = generateOutlinesFromSidebar(item.items);
118
+ }
119
+ if ('link' in item && item.link) {
120
+ const page = pageMap.get(`${item.link}.html`);
121
+ if (page != null) {
122
+ result.push({
123
+ title: page.title || item.text,
124
+ to: page.pageIndex,
125
+ children,
126
+ });
127
+ }
128
+ }
129
+ }
130
+ return result;
131
+ };
132
+ return generateOutlinesFromSidebar(sidebarItems);
133
+ }
134
+ : undefined,
101
135
  ...commonOptions,
102
136
  ...options,
103
137
  };
@@ -140,13 +174,17 @@ export const exportCommand = new Command('export')
140
174
  if (themeConfig.locales?.length) {
141
175
  for (const { lang, sidebar } of themeConfig.locales) {
142
176
  const sidebarItems = sidebar[config.lang === lang ? '/' : `/${lang}`];
143
- const { allOutlines } = await exportPdf(sidebarItems, lang);
177
+ const { allOutlines } = await exportPdf(sidebarItems, lang, {
178
+ overrideOutlines: true,
179
+ });
144
180
  await exportEntries(sidebarItems, allOutlines, lang);
145
181
  }
146
182
  }
147
183
  else {
148
184
  const sidebarItems = themeConfig.sidebar['/'];
149
- const { allOutlines } = await exportPdf(sidebarItems);
185
+ const { allOutlines } = await exportPdf(sidebarItems, undefined, {
186
+ overrideOutlines: true,
187
+ });
150
188
  await exportEntries(sidebarItems, allOutlines);
151
189
  }
152
190
  await fs.rm(tempDir, { force: true, recursive: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "1.19.1",
3
+ "version": "1.20.0",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -40,7 +40,7 @@
40
40
  "rspress-plugins"
41
41
  ],
42
42
  "dependencies": {
43
- "@alauda/doom-export": "^0.3.1",
43
+ "@alauda/doom-export": "^0.4.0",
44
44
  "@cspell/eslint-plugin": "^9.6.3",
45
45
  "@eslint-react/eslint-plugin": "^2.9.4",
46
46
  "@inquirer/prompts": "^8.2.0",