Skip to content

Commit 9994b62

Browse files
author
NgocNhi123
committed
fix
1 parent 521ee7e commit 9994b62

File tree

5 files changed

+105
-98
lines changed

5 files changed

+105
-98
lines changed

new-docs/package.json

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
2-
"name": "new-docs",
3-
"version": "0.0.0",
4-
"type": "module",
5-
"scripts": {
6-
"dev": "vocs dev",
7-
"build": "vocs build",
8-
"preview": "vocs preview"
9-
},
10-
"dependencies": {
11-
"@types/react": "latest",
12-
"color": "^4.2.3",
13-
"react": "latest",
14-
"react-dom": "latest",
15-
"typescript": "latest",
16-
"vocs": "latest"
17-
},
18-
"devDependencies": {
19-
"@types/color": "^3.0.6"
20-
}
2+
"name": "new-docs",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"scripts": {
6+
"dev": "vocs dev",
7+
"build": "vocs build",
8+
"preview": "vocs preview"
9+
},
10+
"dependencies": {
11+
"@types/react": "latest",
12+
"color": "^4.2.3",
13+
"react": "latest",
14+
"react-dom": "latest",
15+
"typescript": "latest",
16+
"vocs": "latest"
17+
},
18+
"devDependencies": {
19+
"@types/color": "^3.0.6"
20+
}
2121
}

new-docs/pages/index.mdx

+13-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
layout: landing
33
---
44

5-
import { HomePage } from 'vocs/components'
5+
import { HomePage } from "vocs/components";
66

77
<HomePage.Root>
8-
<HomePage.Logo />
9-
<HomePage.Tagline>A React Component Library, Where Buttons Look Like Buttons.</HomePage.Tagline>
10-
<HomePage.Buttons>
11-
<HomePage.Button href="/intro/quick-start" variant="accent">Quick start</HomePage.Button>
12-
<HomePage.Button href="https://github.com/thien-do/moai">GitHub</HomePage.Button>
13-
</HomePage.Buttons>
8+
<HomePage.Logo />
9+
<HomePage.Tagline>
10+
A React Component Library, Where Buttons Look Like Buttons.
11+
</HomePage.Tagline>
12+
<HomePage.Buttons>
13+
<HomePage.Button href="/intro/quick-start" variant="accent">
14+
Quick start
15+
</HomePage.Button>
16+
<HomePage.Button href="https://github.com/thien-do/moai">
17+
GitHub
18+
</HomePage.Button>
19+
</HomePage.Buttons>
1420
</HomePage.Root>

new-docs/sidebar.ts

+47-46
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
11
import { SidebarItem } from "vocs";
2-
import fs from 'fs';
3-
import path from 'path';
2+
import fs from "fs";
3+
import path from "path";
44

55
function capitalize(text: string): string {
6-
return text.charAt(0).toUpperCase() + text.slice(1)
6+
return text.charAt(0).toUpperCase() + text.slice(1);
77
}
88

9-
109
function generateSidebar(dirPath: string, parentDir: string): SidebarItem[] {
11-
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
12-
13-
const items: SidebarItem[] = [];
14-
15-
entries.forEach(entry => {
16-
// If entry is file end with '.stories.mdx', add sidebar item with link
17-
if (entry.isFile() && entry.name.endsWith('.stories.mdx')) {
18-
const fileName = entry.name.replace('.stories.mdx', '')
19-
if (fileName === 'index') {
20-
items.unshift({
21-
text: capitalize(fileName.replace(/-/g, ' ')),
22-
link: parentDir
23-
});
24-
} else {
25-
items.push({
26-
text: capitalize(fileName.replace(/-/g, ' ')),
27-
link: `${parentDir}/${fileName}`
28-
});
29-
}
30-
return
31-
}
32-
33-
// If entry is directory, add collapsable sidebar item
34-
if (entry.isDirectory()) {
35-
const subDirPath = path.join(dirPath, entry.name);
36-
const subItems = generateSidebar(subDirPath, `${parentDir}/${entry.name}`);
37-
if (subItems.length === 0)
38-
return
39-
40-
const item = {
41-
text: capitalize(entry.name),
42-
collapsed: false,
43-
items: subItems
44-
}
45-
items.push(item);
46-
}
47-
});
48-
49-
return items;
10+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
11+
12+
const items: SidebarItem[] = [];
13+
14+
entries.forEach((entry) => {
15+
// If entry is file end with '.stories.mdx', add sidebar item with link
16+
if (entry.isFile() && entry.name.endsWith(".stories.mdx")) {
17+
const fileName = entry.name.replace(".stories.mdx", "");
18+
if (fileName === "index") {
19+
items.unshift({
20+
text: capitalize(fileName.replace(/-/g, " ")),
21+
link: parentDir,
22+
});
23+
} else {
24+
items.push({
25+
text: capitalize(fileName.replace(/-/g, " ")),
26+
link: `${parentDir}/${fileName}`,
27+
});
28+
}
29+
return;
30+
}
31+
32+
// If entry is directory, add collapsable sidebar item
33+
if (entry.isDirectory()) {
34+
const subDirPath = path.join(dirPath, entry.name);
35+
const subItems = generateSidebar(
36+
subDirPath,
37+
`${parentDir}/${entry.name}`,
38+
);
39+
if (subItems.length === 0) return;
40+
41+
const item = {
42+
text: capitalize(entry.name),
43+
collapsed: false,
44+
items: subItems,
45+
};
46+
items.push(item);
47+
}
48+
});
49+
50+
return items;
5051
}
5152

52-
const TOP_LEVEL_ORDER = ['Intro', 'Patterns', 'Components', 'Draft']
53-
export const sidebar = generateSidebar('./pages', '').sort((a, b) => {
54-
return TOP_LEVEL_ORDER.indexOf(a.text) - TOP_LEVEL_ORDER.indexOf(b.text)
53+
const TOP_LEVEL_ORDER = ["Intro", "Patterns", "Components", "Draft"];
54+
export const sidebar = generateSidebar("./pages", "").sort((a, b) => {
55+
return TOP_LEVEL_ORDER.indexOf(a.text) - TOP_LEVEL_ORDER.indexOf(b.text);
5556
});

new-docs/tsconfig.json

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
2-
"compilerOptions": {
3-
"target": "ES2020",
4-
"useDefineForClassFields": true,
5-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
6-
"module": "ESNext",
7-
"skipLibCheck": true,
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"useDefineForClassFields": true,
5+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
6+
"module": "ESNext",
7+
"skipLibCheck": true,
88

9-
/* Bundler mode */
10-
"moduleResolution": "bundler",
11-
"allowImportingTsExtensions": true,
12-
"resolveJsonModule": true,
13-
"isolatedModules": true,
14-
"noEmit": true,
15-
"jsx": "react-jsx",
9+
/* Bundler mode */
10+
"moduleResolution": "bundler",
11+
"allowImportingTsExtensions": true,
12+
"resolveJsonModule": true,
13+
"isolatedModules": true,
14+
"noEmit": true,
15+
"jsx": "react-jsx",
1616

17-
/* Linting */
18-
"strict": true,
19-
"noUnusedLocals": true,
20-
"noUnusedParameters": true,
21-
"noFallthroughCasesInSwitch": true,
22-
},
23-
"include": ["**/*.ts", "**/*.tsx"]
17+
/* Linting */
18+
"strict": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"noFallthroughCasesInSwitch": true
22+
},
23+
"include": ["**/*.ts", "**/*.tsx"]
2424
}

new-docs/vocs.config.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { defineConfig } from 'vocs'
2-
import { sidebar } from './sidebar'
1+
import { defineConfig } from "vocs";
2+
import { sidebar } from "./sidebar";
33

44
export default defineConfig({
5-
rootDir: '.',
6-
title: 'Moai UI Kit',
7-
sidebar: sidebar
8-
})
5+
rootDir: ".",
6+
title: "Moai UI Kit",
7+
sidebar: sidebar,
8+
});

0 commit comments

Comments
 (0)