@alauda/doom 1.5.1 → 1.6.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.
@@ -1,5 +1,6 @@
1
1
  import { type PrinterOptions } from '../html-export-pdf/index.js';
2
2
  import type { LaunchOptions, Page, PDFOptions } from './types.js';
3
+ import { type PDFOutline } from './utils/index.js';
3
4
  export interface GeneratePdfOptions {
4
5
  pages: Page[];
5
6
  tempDir: string;
@@ -7,6 +8,8 @@ export interface GeneratePdfOptions {
7
8
  host: string;
8
9
  outFile: string;
9
10
  outDir: string;
11
+ cleanupTempDir?: boolean;
12
+ allOutlines?: PDFOutline[];
10
13
  launchOptions?: LaunchOptions;
11
14
  pdfOptions?: PDFOptions;
12
15
  pdfOutlines?: boolean;
@@ -16,4 +19,7 @@ export interface GeneratePdfOptions {
16
19
  /**
17
20
  * Generate PDF from VuePress or VitePress dev server.
18
21
  */
19
- export declare function generatePdf({ pages, tempDir, port, host, outFile, outDir, urlOrigin, pdfOptions, pdfOutlines, launchOptions, printerOptions, }: GeneratePdfOptions): Promise<string>;
22
+ export declare function generatePdf({ pages, tempDir, port, host, outFile, outDir, cleanupTempDir, allOutlines, urlOrigin, pdfOptions, pdfOutlines, launchOptions, printerOptions, }: GeneratePdfOptions): Promise<{
23
+ exportedPath: string;
24
+ allOutlines: PDFOutline[];
25
+ }>;
@@ -7,7 +7,7 @@ import { getUrlLink, mergePDF, } from './utils/index.js';
7
7
  /**
8
8
  * Generate PDF from VuePress or VitePress dev server.
9
9
  */
10
- export async function generatePdf({ pages, tempDir, port, host, outFile, outDir, urlOrigin, pdfOptions, pdfOutlines = true, launchOptions, printerOptions, }) {
10
+ export async function generatePdf({ pages, tempDir, port, host, outFile, outDir, cleanupTempDir = true, allOutlines = [], urlOrigin, pdfOptions, pdfOutlines = true, launchOptions, printerOptions, }) {
11
11
  await fs.mkdir(tempDir, { recursive: true });
12
12
  const isValidUrlOrigin = isValidUrl(urlOrigin ?? '');
13
13
  if (urlOrigin && !isValidUrlOrigin) {
@@ -29,53 +29,63 @@ export async function generatePdf({ pages, tempDir, port, host, outFile, outDir,
29
29
  pagePath: path.resolve(tempDir, `${page.key}.pdf`),
30
30
  };
31
31
  });
32
- const singleBar = createProgress();
33
- singleBar.start(normalizePages.length);
34
- const printer = new Printer(printerOptions);
35
- const page = await printer.setup(launchOptions);
36
- if (urlOrigin && isValidUrlOrigin) {
37
- await page.route('**/*', (route) => {
38
- const reqUrl = route.request().url();
39
- if (!isValidUrl(reqUrl)) {
40
- return route.continue();
41
- }
42
- // http or https
43
- const parsedUrl = new URL(reqUrl);
44
- if (userURLOrigin === parsedUrl.origin) {
45
- parsedUrl.host = host;
46
- parsedUrl.protocol = 'http:';
47
- parsedUrl.port = `${port}`;
48
- const parsedUrlString = parsedUrl.toString();
49
- return route.continue({
50
- url: parsedUrlString,
51
- headers: Object.assign({}, route.request().headers(), {
52
- refer: parsedUrlString,
53
- // Same origin
54
- // origin: parsedUrl.origin,
55
- // CORS
56
- // host: parsedUrl.host,
57
- }),
58
- });
59
- }
32
+ if (allOutlines.length) {
33
+ const allOutlinesMapping = new Map(allOutlines);
34
+ allOutlines = normalizePages.map(({ location }) => {
35
+ const { link } = getUrlLink(location);
36
+ return [link, allOutlinesMapping.get(link)];
60
37
  });
61
38
  }
62
- const allOutlines = [];
63
- for (const { location, pagePath, title } of normalizePages) {
64
- const { data, outlineNodes } = await printer.pdf(location, {
65
- format: 'A4',
66
- ...pdfOptions,
67
- }, pdfOutlines);
68
- if (pdfOutlines) {
69
- allOutlines.push([getUrlLink(location).link, outlineNodes]);
39
+ else {
40
+ const singleBar = createProgress();
41
+ singleBar.start(normalizePages.length);
42
+ const printer = new Printer(printerOptions);
43
+ const page = await printer.setup(launchOptions);
44
+ if (urlOrigin && isValidUrlOrigin) {
45
+ await page.route('**/*', (route) => {
46
+ const reqUrl = route.request().url();
47
+ if (!isValidUrl(reqUrl)) {
48
+ return route.continue();
49
+ }
50
+ // http or https
51
+ const parsedUrl = new URL(reqUrl);
52
+ if (userURLOrigin === parsedUrl.origin) {
53
+ parsedUrl.host = host;
54
+ parsedUrl.protocol = 'http:';
55
+ parsedUrl.port = `${port}`;
56
+ const parsedUrlString = parsedUrl.toString();
57
+ return route.continue({
58
+ url: parsedUrlString,
59
+ headers: Object.assign({}, route.request().headers(), {
60
+ refer: parsedUrlString,
61
+ // Same origin
62
+ // origin: parsedUrl.origin,
63
+ // CORS
64
+ // host: parsedUrl.host,
65
+ }),
66
+ });
67
+ }
68
+ });
70
69
  }
71
- await writeFileSafe(pagePath, data);
72
- singleBar.increment(1, { headTitle: title || (await page.title()) });
70
+ for (const { location, pagePath, title } of normalizePages) {
71
+ const { data, outlineNodes } = await printer.pdf(location, {
72
+ format: 'A4',
73
+ ...pdfOptions,
74
+ }, pdfOutlines);
75
+ if (pdfOutlines) {
76
+ allOutlines.push([getUrlLink(location).link, outlineNodes]);
77
+ }
78
+ await writeFileSafe(pagePath, data);
79
+ singleBar.increment(1, { headTitle: title || (await page.title()) });
80
+ }
81
+ singleBar.stop();
82
+ await printer.closeBrowser();
73
83
  }
74
- singleBar.stop();
75
- await printer.closeBrowser();
76
84
  const exportedPath = await mergePDF(normalizePages, outFile, outDir, allOutlines);
77
85
  const message = `Exported to ${yellow(exportedPath)}\n`;
78
86
  process.stdout.write(message);
79
- await fs.rm(tempDir, { force: true, recursive: true });
80
- return exportedPath;
87
+ if (cleanupTempDir) {
88
+ await fs.rm(tempDir, { force: true, recursive: true });
89
+ }
90
+ return { exportedPath, allOutlines };
81
91
  }
@@ -1,4 +1,3 @@
1
- import { Buffer } from 'node:buffer';
2
1
  import { PDFArray } from 'pdf-lib';
3
2
  import type { OutlineNode } from '../../html-export-pdf/index.js';
4
3
  export interface NormalizePage {
@@ -1,10 +1,8 @@
1
- import { Buffer } from 'node:buffer';
2
1
  import fs from 'node:fs/promises';
3
- import { join, relative } from 'node:path';
2
+ import path from 'node:path';
4
3
  import process from 'node:process';
5
4
  import { asPDFName, PDFArray, PDFDict, PDFDocument, PDFObject, PDFString, } from 'pdf-lib';
6
5
  import PDFMerger from 'pdf-merger-js';
7
- import { red } from 'yoctocolors';
8
6
  import { mergePDFs } from '../../merge-pdfs/index.js';
9
7
  import { convertPathToPosix } from './convertPathToPosix.js';
10
8
  import { getUrlLink } from './getUrlLink.js';
@@ -106,14 +104,13 @@ export const replaceLinksWithOutline = async (pdfData, pdfOutlines) => {
106
104
  * @returns relativePath - Output relative path
107
105
  */
108
106
  export async function mergePDF(pages, outFile, outDir, pdfOutlines) {
109
- const saveDirPath = join(process.cwd(), outDir);
107
+ const saveDirPath = path.resolve(outDir);
110
108
  if (outDir) {
111
109
  await fs.mkdir(saveDirPath, { recursive: true });
112
110
  }
113
- const saveFilePath = join(saveDirPath, outFile);
111
+ const saveFilePath = path.join(saveDirPath, outFile);
114
112
  if (pages.length === 0) {
115
- process.stderr.write(red('The website has no pages, please check whether the export path is set correctly'));
116
- process.exit(1);
113
+ throw new Error('The website has no pages, please check whether the export path is set correctly');
117
114
  }
118
115
  else if (pages.length === 1) {
119
116
  await fs.rename(pages[0].pagePath, saveFilePath);
@@ -122,7 +119,7 @@ export async function mergePDF(pages, outFile, outDir, pdfOutlines) {
122
119
  let pdfData;
123
120
  if (pdfOutlines.length > 0) {
124
121
  pdfData = await mergePDFs(pages.map(({ pagePath }) => {
125
- const relativePagePath = relative(process.cwd(), pagePath);
122
+ const relativePagePath = path.relative(process.cwd(), pagePath);
126
123
  return convertPathToPosix(relativePagePath);
127
124
  }));
128
125
  pdfData = await replaceLinksWithOutline(pdfData, pdfOutlines);
@@ -136,5 +133,5 @@ export async function mergePDF(pages, outFile, outDir, pdfOutlines) {
136
133
  }
137
134
  await fs.writeFile(saveFilePath, pdfData);
138
135
  }
139
- return relative(process.cwd(), saveFilePath);
136
+ return path.relative(process.cwd(), saveFilePath);
140
137
  }
package/lib/cli/export.js CHANGED
@@ -1,12 +1,31 @@
1
+ import fs from 'node:fs/promises';
1
2
  import path from 'node:path';
2
3
  import { removeLeadingSlash, serve } from '@rspress/core';
3
4
  import { logger } from '@rspress/shared/logger';
4
5
  import { Command } from 'commander';
5
- import { autoSidebar } from '../plugins/index.js';
6
+ import { cyan, yellow } from 'yoctocolors';
7
+ import { autoSidebar, } from '../plugins/index.js';
6
8
  import { getPdfName } from '../shared/index.js';
7
9
  import { pathExists, setNodeEnv } from '../utils/index.js';
8
10
  import { generatePdf, } from './export-pdf-core/index.js';
9
11
  import { loadConfig } from './load-config.js';
12
+ const collectPages = (sidebarItems, base) => {
13
+ const pages = [];
14
+ for (const item of sidebarItems) {
15
+ if ('link' in item && item.link) {
16
+ const link = removeLeadingSlash(item.link);
17
+ pages.push({
18
+ key: link,
19
+ path: base + link + '.html?print',
20
+ title: item.text,
21
+ });
22
+ }
23
+ if ('items' in item) {
24
+ pages.push(...collectPages(item.items, base));
25
+ }
26
+ }
27
+ return pages;
28
+ };
10
29
  export const exportCommand = new Command('export')
11
30
  .description('Export the documentation as PDF, `apis/**` and `*/apis/**` routes will be ignored automatically')
12
31
  .argument('[root]', 'Root directory of the documentation')
@@ -33,25 +52,9 @@ export const exportCommand = new Command('export')
33
52
  const themeConfig = { ...config.themeConfig };
34
53
  logger.start('Serving...');
35
54
  await serve({ config, host, port });
36
- const collectPages = (sidebarItems) => {
37
- const pages = [];
38
- for (const item of sidebarItems) {
39
- if ('link' in item && item.link) {
40
- const link = removeLeadingSlash(item.link);
41
- pages.push({
42
- key: link,
43
- path: config.base + link + '.html?print',
44
- title: item.text,
45
- });
46
- }
47
- if ('items' in item) {
48
- pages.push(...collectPages(item.items));
49
- }
50
- }
51
- return pages;
52
- };
55
+ const tempDir = path.resolve(outDir, '.doom');
53
56
  const commonOptions = {
54
- tempDir: path.resolve(outDir, '.doom'),
57
+ tempDir,
55
58
  port: port,
56
59
  host: host || 'localhost',
57
60
  outDir,
@@ -84,25 +87,64 @@ export const exportCommand = new Command('export')
84
87
  outlineContainerSelector: '.rspress-doc',
85
88
  },
86
89
  };
87
- const exportPdf = async (sidebarItems, lang = config.lang) => {
88
- const pages = collectPages(sidebarItems);
89
- logger.start(`Exporting ${lang} language documents with ${pages.length} pages...`);
90
- await generatePdf({
90
+ const exportPdf = async (sidebarItems, lang = config.lang, options) => {
91
+ const pages = collectPages(sidebarItems, config.base);
92
+ const pdfOptions = {
91
93
  pages,
92
94
  outFile: getPdfName(lang, config.userBase, config.title),
95
+ cleanupTempDir: false,
93
96
  ...commonOptions,
94
- });
97
+ ...options,
98
+ };
99
+ logger.start(`Exporting ${options ? 'custom' : 'all'} ${lang} language documents with ${pages.length} pages into ${yellow(pdfOptions.outFile)}...`);
100
+ return generatePdf(pdfOptions);
101
+ };
102
+ const findEntryFactory = (entry) => function findEntry(sidebarItems) {
103
+ for (const item of sidebarItems) {
104
+ if (!('_fileKey' in item) || !item._fileKey) {
105
+ continue;
106
+ }
107
+ if (entry.includes(item._fileKey)) {
108
+ return item;
109
+ }
110
+ if ('items' in item) {
111
+ const found = findEntry(item.items);
112
+ if (found) {
113
+ return found;
114
+ }
115
+ }
116
+ }
117
+ };
118
+ const exportItems = config.export || [];
119
+ const exportEntries = async (sidebarItems, allOutlines, lang = config.lang) => {
120
+ for (const item of exportItems) {
121
+ // already normalized by `loadConfig`
122
+ const entry = item.entry;
123
+ const findEntry = findEntryFactory(entry);
124
+ const found = findEntry(sidebarItems);
125
+ if (!found) {
126
+ logger.warn(`Cannot find entry \`${cyan(entry.join(', '))}\` for lang ${lang}, skip exporting`);
127
+ continue;
128
+ }
129
+ await exportPdf([found], lang, {
130
+ allOutlines,
131
+ outFile: `${item.name || found.text}-${lang}.pdf`,
132
+ });
133
+ }
95
134
  };
96
135
  if (themeConfig.locales?.length) {
97
136
  for (const { lang, sidebar } of themeConfig.locales) {
98
137
  const sidebarItems = sidebar[config.lang === lang ? '/' : `/${lang}`];
99
- await exportPdf(sidebarItems, lang);
138
+ const { allOutlines } = await exportPdf(sidebarItems, lang);
139
+ await exportEntries(sidebarItems, allOutlines, lang);
100
140
  }
101
141
  }
102
142
  else {
103
143
  const sidebarItems = themeConfig.sidebar['/'];
104
- await exportPdf(sidebarItems);
144
+ const { allOutlines } = await exportPdf(sidebarItems);
145
+ await exportEntries(sidebarItems, allOutlines);
105
146
  }
147
+ await fs.rm(tempDir, { force: true, recursive: true });
106
148
  logger.ready('Closing the server');
107
149
  process.exit(0);
108
150
  });
@@ -11,6 +11,7 @@ import { pluginLlms } from '@rspress/plugin-llms';
11
11
  import { logger } from '@rspress/shared/logger';
12
12
  import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
13
13
  import { difference } from 'es-toolkit';
14
+ import { globSync } from 'tinyglobby';
14
15
  import { cyan } from 'yoctocolors';
15
16
  import { apiPlugin, autoSidebarPlugin, autoTocPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, replacePlugin, sitemapPlugin, } from '../plugins/index.js';
16
17
  import { isExplicitlyUnversioned, UNVERSIONED, } from '../shared/index.js';
@@ -320,6 +321,10 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
320
321
  lang: commonConfig.lang,
321
322
  root: commonConfig.root,
322
323
  });
324
+ mergedConfig.export = config.export?.map((item) => ({
325
+ ...item,
326
+ entry: globSync(item.entry, { cwd: commonConfig.root }),
327
+ }));
323
328
  if (base && prefix) {
324
329
  mergedConfig.base = (mergedConfig.prefix = normalizeSlash(prefix)) + base;
325
330
  }
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { isProduction, NoSSR, removeTrailingSlash, usePageData, } from '@rspress/core/runtime';
2
+ import { isProduction, NoSSR, removeTrailingSlash, usePageData, withBase, } from '@rspress/core/runtime';
3
+ import {} from '@rspress/shared';
3
4
  import virtual from 'doom-@global-virtual';
4
5
  import { noop } from 'es-toolkit';
5
6
  import { useEffect, useMemo, useState } from 'react';
@@ -33,8 +34,8 @@ const VersionsNav_ = () => {
33
34
  if (!virtual.download) {
34
35
  return;
35
36
  }
36
- return siteData.base + getPdfName(lang, virtual.userBase, siteTitle);
37
- }, [lang, siteData.base, siteTitle]);
37
+ return withBase(getPdfName(lang, virtual.userBase, siteTitle));
38
+ }, [lang, siteTitle]);
38
39
  const [versionsBase, version] = useMemo(() => {
39
40
  const unversionedVersion = getUnversionedVersion(virtual.version);
40
41
  if (!unversionedVersion) {
@@ -1,5 +1,6 @@
1
1
  import { type RspressPlugin } from '@rspress/core';
2
2
  import { type DoomSite } from '../../shared/index.js';
3
+ import type { ExportItem } from '../../types.js';
3
4
  export interface GlobalPluginOptions {
4
5
  version?: string;
5
6
  download?: boolean;
@@ -8,5 +9,6 @@ export interface GlobalVirtual extends GlobalPluginOptions {
8
9
  userBase?: string;
9
10
  prefix?: string;
10
11
  sites?: DoomSite[];
12
+ export?: ExportItem[];
11
13
  }
12
14
  export declare const globalPlugin: ({ version, download, }: GlobalPluginOptions) => RspressPlugin;
@@ -35,6 +35,7 @@ export const globalPlugin = ({ version, download, }) => {
35
35
  base: addTrailingSlash(site.base || (site.name === 'acp' ? ACP_BASE : '')),
36
36
  version: site.version,
37
37
  })),
38
+ export: config.export,
38
39
  }, null, isProd ? 0 : 2)}`,
39
40
  };
40
41
  },
@@ -1,3 +1,3 @@
1
1
  import type { Language } from '../../shared/index.js';
2
2
  export declare const useLang: () => Language;
3
- export declare const useTranslation: () => (key: "function" | "name" | "description" | "delete" | "toc" | "create" | "update" | "view" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases" | "download_pdf") => string;
3
+ export declare const useTranslation: () => (key: "function" | "name" | "description" | "delete" | "toc" | "create" | "update" | "collapse_all" | "expand_all" | "crd_no_schema" | "action" | "view" | "chinese" | "english" | "chinese_bad_cases" | "english_bad_cases" | "download_pdf" | "view_docs_as_pdf") => string;
@@ -16,6 +16,7 @@ declare const en: {
16
16
  english_bad_cases: string;
17
17
  download_pdf: string;
18
18
  toc: string;
19
+ view_docs_as_pdf: string;
19
20
  };
20
21
  export type Translation = typeof en;
21
22
  export declare const TRANSLATIONS: {
@@ -37,6 +38,7 @@ export declare const TRANSLATIONS: {
37
38
  english_bad_cases: string;
38
39
  download_pdf: string;
39
40
  toc: string;
41
+ view_docs_as_pdf: string;
40
42
  };
41
43
  zh: {
42
44
  collapse_all: string;
@@ -56,6 +58,7 @@ export declare const TRANSLATIONS: {
56
58
  english_bad_cases: string;
57
59
  download_pdf: string;
58
60
  toc: string;
61
+ view_docs_as_pdf: string;
59
62
  };
60
63
  ru: {
61
64
  collapse_all: string;
@@ -75,6 +78,7 @@ export declare const TRANSLATIONS: {
75
78
  english_bad_cases: string;
76
79
  download_pdf: string;
77
80
  toc: string;
81
+ view_docs_as_pdf: string;
78
82
  };
79
83
  };
80
84
  export {};
@@ -16,6 +16,7 @@ const en = {
16
16
  english_bad_cases: 'English Bad Cases',
17
17
  download_pdf: 'Download PDF',
18
18
  toc: 'TOC',
19
+ view_docs_as_pdf: 'View full docs as PDF',
19
20
  };
20
21
  const zh = {
21
22
  collapse_all: '全部收起',
@@ -35,6 +36,7 @@ const zh = {
35
36
  english_bad_cases: '英文反例',
36
37
  download_pdf: '下载 PDF',
37
38
  toc: '目录',
39
+ view_docs_as_pdf: '以 PDF 格式查看完整文档',
38
40
  };
39
41
  const ru = {
40
42
  collapse_all: 'Свернуть всё',
@@ -54,5 +56,6 @@ const ru = {
54
56
  english_bad_cases: 'Примеры ошибок на английском',
55
57
  download_pdf: 'Скачать PDF',
56
58
  toc: 'Содержание',
59
+ view_docs_as_pdf: 'Просмотреть полную документацию в формате PDF',
57
60
  };
58
61
  export const TRANSLATIONS = { en, zh, ru };
package/lib/theme.d.ts CHANGED
@@ -1,3 +1,10 @@
1
- declare const Search: () => import("react/jsx-runtime").JSX.Element;
1
+ import type { DoomSidebarGroup, DoomSidebarItem } from './plugins/index.js';
2
+ import type { ExportItem } from './types.js';
2
3
  export * from '@rspress/core/theme';
3
- export { Search };
4
+ export interface MatchedSidebar {
5
+ sidebar: DoomSidebarGroup | DoomSidebarItem;
6
+ exportItem: ExportItem;
7
+ depth: number;
8
+ }
9
+ export declare const Layout: () => import("react/jsx-runtime").JSX.Element;
10
+ export declare const Search: () => import("react/jsx-runtime").JSX.Element;
package/lib/theme.js CHANGED
@@ -1,9 +1,77 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useLang } from '@rspress/core/runtime';
3
- import { Search as OriginalSearch } from '@rspress/core/theme';
2
+ import { useLang, usePageData, withBase } from '@rspress/core/runtime';
3
+ import { Search as OriginalSearch, Layout as OriginalLayout, getCustomMDXComponent, } from '@rspress/core/theme';
4
4
  import { Search as AlgoliaSearch, ZH_LOCALES, } from '@rspress/plugin-algolia/runtime';
5
+ import virtual from 'doom-@global-virtual';
5
6
  import { useMemo } from 'react';
6
- const Search = process.env.ALGOLIA_APP_ID &&
7
+ import { useLocation } from 'react-router';
8
+ import classes from '../styles/link.module.scss';
9
+ import { useTranslation } from './runtime/index.js';
10
+ // eslint-disable-next-line import-x/export
11
+ export * from '@rspress/core/theme';
12
+ const X = getCustomMDXComponent();
13
+ const getClosestSidebar_ = (sidebarItems, pathname, exportItem, matched, depth = 0) => {
14
+ for (const sidebar of sidebarItems) {
15
+ if ('_fileKey' in sidebar && sidebar._fileKey) {
16
+ if (exportItem.entry.includes(sidebar._fileKey)) {
17
+ matched = {
18
+ sidebar,
19
+ exportItem,
20
+ depth,
21
+ };
22
+ }
23
+ if (withBase(sidebar.link) ===
24
+ (pathname.endsWith('.html') ? pathname.slice(0, -5) : pathname)) {
25
+ return matched;
26
+ }
27
+ }
28
+ if ('items' in sidebar) {
29
+ const found = getClosestSidebar_(sidebar.items, pathname, exportItem, matched);
30
+ if (found) {
31
+ return found;
32
+ }
33
+ }
34
+ }
35
+ };
36
+ const getClosestSidebar = (sidebarItems, pathname) => {
37
+ let found;
38
+ for (const item of virtual.export) {
39
+ const matched = getClosestSidebar_(sidebarItems, pathname, item);
40
+ if (matched) {
41
+ if (!found || matched.depth >= found.depth) {
42
+ found = matched;
43
+ }
44
+ }
45
+ }
46
+ return found;
47
+ };
48
+ // eslint-disable-next-line import-x/export
49
+ export const Layout = () => {
50
+ const { siteData: { lang: siteLang, themeConfig }, } = usePageData();
51
+ const lang = useLang();
52
+ const t = useTranslation();
53
+ const { pathname } = useLocation();
54
+ const found = useMemo(() => {
55
+ if (!virtual.export?.length) {
56
+ return;
57
+ }
58
+ if (themeConfig.locales?.length) {
59
+ for (const { lang, sidebar } of themeConfig.locales) {
60
+ const sidebarItems = sidebar[siteLang === lang ? '/' : `/${lang}`];
61
+ return getClosestSidebar(sidebarItems, pathname);
62
+ }
63
+ }
64
+ else {
65
+ const sidebarItems = themeConfig.sidebar['/'];
66
+ return getClosestSidebar(sidebarItems, pathname);
67
+ }
68
+ }, [pathname, siteLang, themeConfig]);
69
+ const pdfLink = useMemo(() => found &&
70
+ withBase(`${found.exportItem.name ?? found.sidebar.text}-${lang}.pdf`), [found, lang]);
71
+ return (_jsx(OriginalLayout, { beforeOutline: pdfLink && (_jsx(X.p, { children: _jsx("a", { className: classes.link, href: pdfLink, target: "_blank", rel: "noopener noreferrer", children: t('view_docs_as_pdf') }) })) }));
72
+ };
73
+ // eslint-disable-next-line import-x/export
74
+ export const Search = process.env.ALGOLIA_APP_ID &&
7
75
  process.env.ALGOLIA_API_KEY &&
8
76
  process.env.ALGOLIA_INDEX_NAME
9
77
  ? () => {
@@ -19,7 +87,3 @@ const Search = process.env.ALGOLIA_APP_ID &&
19
87
  return (_jsx(AlgoliaSearch, { docSearchProps: docSearchProps, locales: ZH_LOCALES }));
20
88
  }
21
89
  : OriginalSearch;
22
- // eslint-disable-next-line import-x/export
23
- export * from '@rspress/core/theme';
24
- // eslint-disable-next-line import-x/export
25
- export { Search };
package/lib/types.d.ts CHANGED
@@ -35,6 +35,12 @@ export interface AlgoliaOptions {
35
35
  apiKey: string;
36
36
  indexName: string;
37
37
  }
38
+ export interface ExportItem {
39
+ name?: string;
40
+ entry: string | string[];
41
+ onlyInclude?: string[];
42
+ exclude?: string[];
43
+ }
38
44
  declare module '@rspress/shared' {
39
45
  interface UserConfig {
40
46
  prefix?: string;
@@ -52,6 +58,7 @@ declare module '@rspress/shared' {
52
58
  lint?: LintOptions;
53
59
  algolia?: AlgoliaOptions;
54
60
  siteUrl?: string;
61
+ export?: ExportItem[];
55
62
  }
56
63
  interface SiteData {
57
64
  originalTitle?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "1.5.1",
3
+ "version": "1.6.1",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": "git+https://github.com/alauda/doom.git",