@alauda/doom 0.6.0 → 0.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.
package/lib/cli/load-config.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { type RspressPlugin } from '@rspress/core';
|
|
2
|
-
export
|
|
2
|
+
export interface AutoSidebarPluginOptions {
|
|
3
|
+
collapsed?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const autoSidebarPlugin: ({ collapsed, }?: AutoSidebarPluginOptions) => RspressPlugin;
|
|
@@ -141,21 +141,21 @@ import { walk } from './walk.js';
|
|
|
141
141
|
// }
|
|
142
142
|
// ]
|
|
143
143
|
// ```
|
|
144
|
-
function processLocales(langs, versions, root, defaultLang, defaultVersion, extensions) {
|
|
144
|
+
function processLocales(langs, versions, root, defaultLang, defaultVersion, extensions, collapsed) {
|
|
145
145
|
return Promise.all(langs.map(async (lang) => {
|
|
146
146
|
const walks = versions.length
|
|
147
147
|
? await Promise.all(versions.map((version) => {
|
|
148
148
|
const routePrefix = addTrailingSlash(`${version === defaultVersion ? '' : `/${version}`}${lang === defaultLang ? '' : `/${lang}`}`);
|
|
149
|
-
return walk(path.join(root, version, lang), routePrefix, root, extensions);
|
|
149
|
+
return walk(path.join(root, version, lang), routePrefix, root, extensions, collapsed);
|
|
150
150
|
}))
|
|
151
151
|
: [
|
|
152
|
-
await walk(path.join(root, lang), addTrailingSlash(lang === defaultLang ? '' : `/${lang}`), root, extensions),
|
|
152
|
+
await walk(path.join(root, lang), addTrailingSlash(lang === defaultLang ? '' : `/${lang}`), root, extensions, collapsed),
|
|
153
153
|
];
|
|
154
154
|
return combineWalkResult(walks, versions);
|
|
155
155
|
}));
|
|
156
156
|
}
|
|
157
157
|
const defaultExtensions = ['.mdx', '.md', '.tsx', '.jsx', '.ts', '.js'];
|
|
158
|
-
export const autoSidebarPlugin = () => {
|
|
158
|
+
export const autoSidebarPlugin = ({ collapsed, } = {}) => {
|
|
159
159
|
return {
|
|
160
160
|
name: 'doom-auto-sidebar',
|
|
161
161
|
async config(config, utils) {
|
|
@@ -171,7 +171,7 @@ export const autoSidebarPlugin = () => {
|
|
|
171
171
|
const { default: defaultVersion = '' } = config.multiVersion || {};
|
|
172
172
|
const { extensions = defaultExtensions } = config.route || {};
|
|
173
173
|
if (hasLocales) {
|
|
174
|
-
const metaInfo = await processLocales(langs, versions, config.root, defaultLang, defaultVersion, extensions);
|
|
174
|
+
const metaInfo = await processLocales(langs, versions, config.root, defaultLang, defaultVersion, extensions, collapsed);
|
|
175
175
|
config.themeConfig.locales = config.themeConfig.locales.map((item, index) => ({
|
|
176
176
|
...item,
|
|
177
177
|
...metaInfo[index],
|
|
@@ -188,9 +188,9 @@ export const autoSidebarPlugin = () => {
|
|
|
188
188
|
const walks = versions.length
|
|
189
189
|
? await Promise.all(versions.map((version) => {
|
|
190
190
|
const routePrefix = addTrailingSlash(version === defaultVersion ? '' : `/${version}`);
|
|
191
|
-
return walk(path.join(config.root, version), routePrefix, config.root, extensions);
|
|
191
|
+
return walk(path.join(config.root, version), routePrefix, config.root, extensions, collapsed);
|
|
192
192
|
}))
|
|
193
|
-
: [await walk(config.root, '/', config.root, extensions)];
|
|
193
|
+
: [await walk(config.root, '/', config.root, extensions, collapsed)];
|
|
194
194
|
const combined = combineWalkResult(walks, versions);
|
|
195
195
|
config.themeConfig = { ...config.themeConfig, ...combined };
|
|
196
196
|
}
|
|
@@ -11,7 +11,7 @@ export declare function scanSideMeta(workDir: string, rootDir: string, docsDir:
|
|
|
11
11
|
index?: DoomSidebarItem;
|
|
12
12
|
others: DoomSidebar[];
|
|
13
13
|
}>;
|
|
14
|
-
export declare function walk(workDir: string, routePrefix: string | undefined, docsDir: string, extensions: string[]): Promise<{
|
|
14
|
+
export declare function walk(workDir: string, routePrefix: string | undefined, docsDir: string, extensions: string[], collapsed?: boolean): Promise<{
|
|
15
15
|
nav: never[];
|
|
16
16
|
sidebar: {
|
|
17
17
|
[x: string]: DoomSidebar[];
|
|
@@ -161,12 +161,14 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
|
|
|
161
161
|
}
|
|
162
162
|
// Start walking from the doc directory, scan the `_meta.json` file in each subdirectory
|
|
163
163
|
// and generate the nav and sidebar config
|
|
164
|
-
export async function walk(workDir, routePrefix = '/', docsDir, extensions) {
|
|
164
|
+
export async function walk(workDir, routePrefix = '/', docsDir, extensions, collapsed) {
|
|
165
165
|
const { index, others } = await scanSideMeta(workDir, workDir, docsDir, routePrefix, extensions, ['assets', 'public', 'shared']);
|
|
166
166
|
const sidebars = index ? [index, ...others] : others;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
sidebarItem.
|
|
167
|
+
if (collapsed != null) {
|
|
168
|
+
for (const sidebarItem of sidebars) {
|
|
169
|
+
if ('items' in sidebarItem && sidebarItem.items.length) {
|
|
170
|
+
sidebarItem.collapsed = collapsed;
|
|
171
|
+
}
|
|
170
172
|
}
|
|
171
173
|
}
|
|
172
174
|
// Every sub dir will represent a group of sidebar
|
package/lib/utils/types.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { UserConfig } from '@rspress/core';
|
|
2
2
|
import type { ApiPluginOptions } from '../plugins/api/types.js';
|
|
3
|
+
import type { AutoSidebarPluginOptions } from '../plugins/index.js';
|
|
3
4
|
import type { ReferenceItem } from '../plugins/reference/types.js';
|
|
4
5
|
import type { DoomSite } from '../shared/index.js';
|
|
5
6
|
export interface DoomConfig extends UserConfig {
|
|
6
7
|
api?: ApiPluginOptions;
|
|
7
8
|
sites?: DoomSite[];
|
|
8
9
|
reference?: ReferenceItem[];
|
|
10
|
+
sidebar?: AutoSidebarPluginOptions;
|
|
9
11
|
}
|