Skip to content

Commit 244dbbc

Browse files
committed
style: format
1 parent 2d1e379 commit 244dbbc

2 files changed

Lines changed: 47 additions & 26 deletions

File tree

docs/app.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { defineConfig } from "@solidjs/start/config";
33
import arraybuffer from "vite-plugin-arraybuffer";
44

55
import { createWithSolidBase, defineTheme } from "../src/config";
6+
import { SidebarConfig, createFilesystemSidebar } from "../src/config/sidebar";
67
import defaultTheme, { DefaultThemeSidebarItem } from "../src/default-theme";
7-
import { createFilesystemSidebar, SidebarConfig } from "../src/config/sidebar";
88

99
const theme = defineTheme({
1010
componentsPath: import.meta.resolve("./src/solidbase-theme"),
@@ -106,7 +106,6 @@ export default defineConfig(
106106
),
107107
);
108108

109-
110109
function customFSSidebar(route: string, title: string) {
111110
const sidebar = createFilesystemSidebar(route);
112111

@@ -115,6 +114,6 @@ function customFSSidebar(route: string, title: string) {
115114
title,
116115
items: sidebar.filter((i) => !("items" in i)),
117116
},
118-
...sidebar.filter((i) => ("items" in i))
117+
...sidebar.filter((i) => "items" in i),
119118
];
120119
}

src/config/sidebar.ts

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,67 @@ export interface SidebarItemSection<T = {}> {
2525
export type SidebarItemWithMeta<T = {}> = SidebarItem<T> & {
2626
filePath: string;
2727
matterData?: any;
28-
}
28+
};
2929

3030
export interface FilesystemSidebarOptions {
3131
filter?: (item: SidebarItemWithMeta) => boolean;
3232
sort?: (a: SidebarItemWithMeta, b: SidebarItemWithMeta) => number;
3333
}
3434

35-
const ROUTES_FOLDER = import.meta.resolve("./src/routes/").substring("file:".length);
35+
const ROUTES_FOLDER = import.meta
36+
.resolve("./src/routes/")
37+
.substring("file:".length);
3638

37-
export function createFilesystemSidebar<Item = SidebarItem>(route: string, options?: FilesystemSidebarOptions): Item[] {
39+
export function createFilesystemSidebar<Item = SidebarItem>(
40+
route: string,
41+
options?: FilesystemSidebarOptions,
42+
): Item[] {
3843
const folder = path.join(ROUTES_FOLDER, route);
3944

4045
const resolvedOptions: Required<FilesystemSidebarOptions> = {
4146
filter: (item) => {
42-
console.log("AAAAAAAAA", item.matterData)
43-
return item.matterData?.excludeFromSidebar !== true
47+
console.log("AAAAAAAAA", item.matterData);
48+
return item.matterData?.excludeFromSidebar !== true;
4449
},
4550
sort: (a, b) => {
4651
if (stripExtension(a.filePath).endsWith("index")) return -1;
4752
if (a.filePath > b.filePath) return 1;
4853
if (b.filePath > a.filePath) return -1;
4954
return 0;
5055
},
51-
...options
52-
}
53-
54-
const items = readdirSync(folder).flatMap((file) => {
55-
return traverse(path.join(folder, file), folder, resolvedOptions);
56-
}).filter(Boolean) as SidebarItemWithMeta[];
56+
...options,
57+
};
5758

59+
const items = readdirSync(folder)
60+
.flatMap((file) => {
61+
return traverse(path.join(folder, file), folder, resolvedOptions);
62+
})
63+
.filter(Boolean) as SidebarItemWithMeta[];
5864

5965
const transform = (items: SidebarItemWithMeta[]): Item[] => {
60-
return items.filter(resolvedOptions.filter).sort(resolvedOptions.sort).map((item) => {
61-
if ("items" in item) return (stripMeta({ ...item, items: transform(item.items as SidebarItemWithMeta[]) as SidebarItem[]}));
62-
return stripMeta(item);
63-
}) as Item[];
64-
}
66+
return items
67+
.filter(resolvedOptions.filter)
68+
.sort(resolvedOptions.sort)
69+
.map((item) => {
70+
if ("items" in item)
71+
return stripMeta({
72+
...item,
73+
items: transform(
74+
item.items as SidebarItemWithMeta[],
75+
) as SidebarItem[],
76+
});
77+
return stripMeta(item);
78+
}) as Item[];
79+
};
6580

6681
return transform(items);
6782
}
6883

69-
function traverse(filePath: string, baseFolder: string, options: Required<FilesystemSidebarOptions>): SidebarItemWithMeta | SidebarItemWithMeta[] | undefined {
84+
function traverse(
85+
filePath: string,
86+
baseFolder: string,
87+
options: Required<FilesystemSidebarOptions>,
88+
): SidebarItemWithMeta | SidebarItemWithMeta[] | undefined {
7089
const title = formatTitle(path.basename(filePath));
7190

7291
if (title.includes("[...")) return;
@@ -76,16 +95,19 @@ function traverse(filePath: string, baseFolder: string, options: Required<Filesy
7695

7796
return {
7897
title: getMatterData(filePath).title ?? title,
79-
link: `/${removeParenthesesGroups(stripExtension(path.relative(baseFolder, filePath)))}`.replace(/\/index$/, "").replaceAll("//", "/"),
98+
link: `/${removeParenthesesGroups(stripExtension(path.relative(baseFolder, filePath)))}`
99+
.replace(/\/index$/, "")
100+
.replaceAll("//", "/"),
80101
filePath,
81102
matterData,
82103
};
83104
}
84105

85-
const items =
86-
(readdirSync(filePath).flatMap((file) => {
87-
return traverse(path.join(filePath, file), baseFolder, options);
88-
}).filter(Boolean) as SidebarItemWithMeta[]);
106+
const items = readdirSync(filePath)
107+
.flatMap((file) => {
108+
return traverse(path.join(filePath, file), baseFolder, options);
109+
})
110+
.filter(Boolean) as SidebarItemWithMeta[];
89111

90112
if (title === "") {
91113
return items;
@@ -117,7 +139,7 @@ function formatTitle(filePath: string): string {
117139
}
118140

119141
function removeParenthesesGroups(s: string) {
120-
return s.replaceAll(/\((\w|-)+\)/g, "").replaceAll("//", "/");
142+
return s.replaceAll(/\((\w|-|_)+\)/g, "").replaceAll("//", "/");
121143
}
122144

123145
function stripMeta(item: SidebarItemWithMeta): SidebarItem {

0 commit comments

Comments
 (0)