Skip to content

Commit ab50c99

Browse files
feat: prettier & compress
1 parent 788873b commit ab50c99

10 files changed

Lines changed: 1753 additions & 327 deletions

File tree

.prettierignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# build output
2+
dist/
3+
# generated types
4+
.astro/
5+
6+
# dependencies
7+
node_modules/
8+
9+
# logs
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
pnpm-debug.log*
14+
15+
16+
# environment variables
17+
.env
18+
.env.production
19+
20+
# macOS-specific files
21+
.DS_Store
22+
23+
src/content/docs/

.prettierrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"useTabs": false,
3+
"tabWidth": 2,
4+
"singleQuote": true,
5+
"trailingComma": "none",
6+
"printWidth": 1000000,
7+
"plugins": ["prettier-plugin-astro"],
8+
"overrides": [
9+
{
10+
"files": "*.astro",
11+
"options": {
12+
"parser": "astro"
13+
}
14+
}
15+
]
16+
}

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editor.tabSize": 2,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"editor.formatOnSave": true
5+
}

astro.config.mjs

Lines changed: 87 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -3,100 +3,98 @@ import { defineConfig } from 'astro/config';
33
import starlight from '@astrojs/starlight';
44
import starlightLinksValidatorPlugin from 'starlight-links-validator';
55
import starlightSidebarTopicsPlugin from 'starlight-sidebar-topics';
6-
import astroD2 from 'astro-d2'
6+
import astroD2 from 'astro-d2';
77
import { walkDocsRecursive } from './listSidebar';
88
import starlightLlmsTxt from 'starlight-llms-txt';
99
import starlightScrollToTop from 'starlight-scroll-to-top';
10+
import playformCompress from '@playform/compress';
1011

11-
const prod = process.env.NODE_ENV === "production";
12+
const prod = process.env.NODE_ENV === 'production';
1213

1314
// https://astro.build/config
1415
export default defineConfig({
15-
site: "https://docs.daxa.dev",
16-
integrations: [
17-
astroD2({
18-
skipGeneration: !prod,
19-
}),
20-
starlight({
21-
title: 'Docs',
22-
favicon: '/favicon.png',
23-
logo: {
24-
src: './src/assets/daxa-logo-64p.png',
25-
replacesTitle: false
26-
},
27-
social: [
28-
{
29-
icon: 'github',
30-
label: 'GitHub',
31-
href: 'https://github.com/Ipotrick/Daxa'
32-
},
33-
{
34-
icon: "discord",
35-
label: "Discord",
36-
href: "https://discord.gg/mZrUeJfxB8"
37-
},
38-
],
39-
expressiveCode: {
40-
frames: {
41-
extractFileNameFromCode: false,
42-
},
43-
emitExternalStylesheet: false,
44-
},
45-
plugins: [
46-
starlightScrollToTop(),
47-
starlightLlmsTxt(),
48-
starlightLinksValidatorPlugin(),
49-
starlightSidebarTopicsPlugin(
50-
[
51-
{
52-
id: 'tutorial',
53-
label: 'Tutorial',
54-
link: '/tutorial/',
55-
icon: 'document',
56-
items: walkDocsRecursive('src/content/docs/tutorial/')
57-
},
58-
{
59-
id: 'wiki',
60-
label: 'Wiki',
61-
link: '/wiki/',
62-
icon: 'open-book',
63-
items: walkDocsRecursive('src/content/docs/wiki/')
64-
}
65-
],
66-
{
67-
topics: {
68-
69-
}
70-
}
71-
)
72-
],
73-
components: {
74-
Sidebar: './src/components/Sidebar.astro',
75-
Head: './src/components/Head.astro',
76-
},
77-
lastUpdated: true,
78-
editLink: {
79-
baseUrl: "https://github.com/learndaxa/docs/edit/main/",
80-
},
81-
customCss: [
82-
'./src/custom.css'
83-
],
84-
head: [
85-
{
86-
tag: 'meta',
87-
attrs: {
88-
name: 'theme-color',
89-
content: '#8467b6'
90-
}
91-
}
92-
]
93-
}),
94-
],
95-
build: {
96-
inlineStylesheets: "always",
97-
},
98-
image: {
99-
responsiveStyles: true,
100-
layout: "constrained",
101-
}
16+
site: 'https://docs.daxa.dev',
17+
integrations: [
18+
astroD2({
19+
skipGeneration: !prod
20+
}),
21+
starlight({
22+
title: 'Docs',
23+
favicon: '/favicon.png',
24+
logo: {
25+
src: './src/assets/daxa-logo-64p.png',
26+
replacesTitle: false
27+
},
28+
social: [
29+
{
30+
icon: 'github',
31+
label: 'GitHub',
32+
href: 'https://github.com/Ipotrick/Daxa'
33+
},
34+
{
35+
icon: 'discord',
36+
label: 'Discord',
37+
href: 'https://discord.gg/mZrUeJfxB8'
38+
}
39+
],
40+
expressiveCode: {
41+
frames: {
42+
extractFileNameFromCode: false
43+
},
44+
emitExternalStylesheet: false
45+
},
46+
plugins: [
47+
starlightScrollToTop(),
48+
starlightLlmsTxt(),
49+
starlightLinksValidatorPlugin(),
50+
starlightSidebarTopicsPlugin(
51+
[
52+
{
53+
id: 'tutorial',
54+
label: 'Tutorial',
55+
link: '/tutorial/',
56+
icon: 'document',
57+
items: walkDocsRecursive('src/content/docs/tutorial/')
58+
},
59+
{
60+
id: 'wiki',
61+
label: 'Wiki',
62+
link: '/wiki/',
63+
icon: 'open-book',
64+
items: walkDocsRecursive('src/content/docs/wiki/')
65+
}
66+
],
67+
{
68+
topics: {}
69+
}
70+
)
71+
],
72+
components: {
73+
Sidebar: './src/components/Sidebar.astro',
74+
Head: './src/components/Head.astro'
75+
},
76+
lastUpdated: true,
77+
editLink: {
78+
baseUrl: 'https://github.com/learndaxa/docs/edit/main/'
79+
},
80+
customCss: ['./src/custom.css'],
81+
head: [
82+
{
83+
tag: 'meta',
84+
attrs: {
85+
name: 'theme-color',
86+
content: '#8467b6'
87+
}
88+
}
89+
]
90+
}),
91+
playformCompress()
92+
],
93+
build: {
94+
inlineStylesheets: 'always'
95+
},
96+
image: {
97+
responsiveStyles: true,
98+
layout: 'constrained'
99+
}
102100
});

listSidebar.ts

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,54 @@ import fs from 'fs';
33
import matter from 'gray-matter';
44

55
interface StarlightSidebarFolder {
6-
label: string;
7-
items: StarlightSidebarList;
8-
collapsed?: boolean;
6+
label: string;
7+
items: StarlightSidebarList;
8+
collapsed?: boolean;
99
}
1010

1111
type StarlightSidebarFile = string;
1212

1313
export type StarlightSidebarList = Array<StarlightSidebarFile | StarlightSidebarFolder>;
1414

1515
/**
16-
* Recursively walk through a documentation directory and build a sidebar structure.
17-
* Handles both folders (nested sections) and Markdown files.
18-
*/
16+
* Recursively walk through a documentation directory and build a sidebar structure.
17+
* Handles both folders (nested sections) and Markdown files.
18+
*/
1919
export function walkDocsRecursive(dir: string): StarlightSidebarList {
20-
const entries = fs.readdirSync(dir);
21-
const result: StarlightSidebarList = [];
22-
23-
// Sort all entry file (If named index.*, it will be first)
24-
entries.sort((a, b) => {
25-
const aIsIndex = a.startsWith('index.');
26-
const bIsIndex = b.startsWith('index.');
27-
if (aIsIndex && !bIsIndex) return -1;
28-
if (!aIsIndex && bIsIndex) return 1;
29-
return a.localeCompare(b);
30-
});
31-
32-
for(const entry of entries) {
33-
const entryPath = path.join(dir, entry);
34-
const stat = fs.statSync(entryPath);
35-
36-
if (stat.isDirectory()) {
37-
// Clean label by removing numeric prefix (if present)
38-
const label = entry.replace(/^\d+\s+/, ''); // Remove leading numbers and spaces
39-
40-
result.push({
41-
label,
42-
items: walkDocsRecursive(entryPath) // Recurse into subdirectory
43-
});
44-
} else {
45-
// Read file contents and extract frontmatter using gray-matter
46-
const fileContent = fs.readFileSync(entryPath, 'utf8');
47-
const parsed = matter(fileContent);
48-
49-
if(parsed.data.hideInSidebar && parsed.data.hideInSidebar === true) continue;
50-
51-
result.push(String(parsed.data.slug ?? ''));
52-
}
20+
const entries = fs.readdirSync(dir);
21+
const result: StarlightSidebarList = [];
22+
23+
// Sort all entry file (If named index.*, it will be first)
24+
entries.sort((a, b) => {
25+
const aIsIndex = a.startsWith('index.');
26+
const bIsIndex = b.startsWith('index.');
27+
if (aIsIndex && !bIsIndex) return -1;
28+
if (!aIsIndex && bIsIndex) return 1;
29+
return a.localeCompare(b);
30+
});
31+
32+
for (const entry of entries) {
33+
const entryPath = path.join(dir, entry);
34+
const stat = fs.statSync(entryPath);
35+
36+
if (stat.isDirectory()) {
37+
// Clean label by removing numeric prefix (if present)
38+
const label = entry.replace(/^\d+\s+/, ''); // Remove leading numbers and spaces
39+
40+
result.push({
41+
label,
42+
items: walkDocsRecursive(entryPath) // Recurse into subdirectory
43+
});
44+
} else {
45+
// Read file contents and extract frontmatter using gray-matter
46+
const fileContent = fs.readFileSync(entryPath, 'utf8');
47+
const parsed = matter(fileContent);
48+
49+
if (parsed.data.hideInSidebar && parsed.data.hideInSidebar === true) continue;
50+
51+
result.push(String(parsed.data.slug ?? ''));
5352
}
53+
}
5454

55-
return result;
55+
return result;
5656
}
57-

0 commit comments

Comments
 (0)