Skip to content

Commit 74d6419

Browse files
committed
Update documentation structure and sync script; remove old guide index, adjust navigation links, and clean up .gitignore
1 parent 750a109 commit 74d6419

File tree

5 files changed

+69
-188
lines changed

5 files changed

+69
-188
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ node_modules
22
.DS_Store
33
dist
44
.cache
5-
.vitepress/cache
6-
.vitepress/dist
7-
5+
docs/.vitepress/cache
6+
docs/.vitepress/dist
7+
docs/**/*.md

docs/.vitepress/config.js

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ export default defineConfig({
1919

2020
nav: [
2121
{ text: 'Home', link: '/' },
22-
{ text: 'Guide', link: '/guide/' },
23-
{ text: 'Examples', link: '/examples/' },
24-
{ text: 'API', link: '/api/' },
22+
{ text: 'Guide', link: '/getting-started/installation' },
23+
{ text: 'Examples', link: '/examples/counter' },
2524
{
2625
text: 'GitHub',
2726
link: 'https://github.com/diffyne/diffyne',
@@ -30,65 +29,54 @@ export default defineConfig({
3029
],
3130

3231
sidebar: {
33-
'/guide/': [
32+
'/': [
3433
{
3534
text: 'Getting Started',
3635
items: [
37-
{ text: 'Introduction', link: '/guide/' },
38-
{ text: 'Installation', link: '/guide/installation' },
39-
{ text: 'Quick Start', link: '/guide/quickstart' },
40-
{ text: 'Your First Component', link: '/guide/first-component' }
36+
{ text: 'Installation', link: '/getting-started/installation' },
37+
{ text: 'Quick Start', link: '/getting-started/quickstart' },
38+
{ text: 'Your First Component', link: '/getting-started/first-component' }
4139
]
4240
},
4341
{
44-
text: 'Core Concepts',
42+
text: 'Features',
4543
items: [
46-
{ text: 'Components', link: '/guide/components' },
47-
{ text: 'Properties & State', link: '/guide/properties' },
48-
{ text: 'Methods & Actions', link: '/guide/methods' },
49-
{ text: 'Lifecycle Hooks', link: '/guide/lifecycle' }
44+
{ text: 'Directives', link: '/features/directives' },
45+
{ text: 'Attributes', link: '/features/attributes' },
46+
{ text: 'Click Events', link: '/features/click-events' },
47+
{ text: 'Data Binding', link: '/features/data-binding' },
48+
{ text: 'Forms', link: '/features/forms' },
49+
{ text: 'Validation', link: '/features/validation' },
50+
{ text: 'Query String Binding', link: '/features/query-string' },
51+
{ text: 'Polling', link: '/features/polling' },
52+
{ text: 'Loading States', link: '/features/loading-states' },
53+
{ text: 'Error Handling', link: '/features/error-handling' },
54+
{ text: 'Component Events', link: '/features/component-events' },
55+
{ text: 'Redirects', link: '/features/redirects' },
56+
{ text: 'Pagination', link: '/features/pagination' }
5057
]
5158
},
5259
{
53-
text: 'Building UIs',
60+
text: 'Advanced',
5461
items: [
55-
{ text: 'Directives', link: '/guide/directives' },
56-
{ text: 'Event Handling', link: '/guide/events' },
57-
{ text: 'Data Binding', link: '/guide/data-binding' },
58-
{ text: 'Forms', link: '/guide/forms' },
59-
{ text: 'Validation', link: '/guide/validation' }
62+
{ text: 'Component State', link: '/advanced/component-state' },
63+
{ text: 'Lifecycle Hooks', link: '/advanced/lifecycle-hooks' },
64+
{ text: 'Virtual DOM', link: '/advanced/virtual-dom' },
65+
{ text: 'Security', link: '/advanced/security' },
66+
{ text: 'Performance', link: '/advanced/performance' },
67+
{ text: 'Testing', link: '/advanced/testing' },
68+
{ text: 'WebSocket Transport', link: '/advanced/websocket' }
6069
]
6170
},
62-
{
63-
text: 'Advanced Features',
64-
items: [
65-
{ text: 'Query String Binding', link: '/guide/query-string' },
66-
{ text: 'Polling & Real-time', link: '/guide/polling' },
67-
{ text: 'Loading States', link: '/guide/loading-states' },
68-
{ text: 'Error Handling', link: '/guide/error-handling' },
69-
{ text: 'Component Events', link: '/guide/component-events' },
70-
{ text: 'Redirects', link: '/guide/redirects' }
71-
]
72-
},
73-
{
74-
text: 'Advanced Topics',
75-
items: [
76-
{ text: 'Security', link: '/guide/security' },
77-
{ text: 'Performance', link: '/guide/performance' },
78-
{ text: 'Testing', link: '/guide/testing' },
79-
{ text: 'WebSocket Transport', link: '/guide/websocket' }
80-
]
81-
}
82-
],
83-
'/examples/': [
8471
{
8572
text: 'Examples',
8673
items: [
8774
{ text: 'Counter', link: '/examples/counter' },
8875
{ text: 'Todo List', link: '/examples/todo-list' },
8976
{ text: 'Contact Form', link: '/examples/contact-form' },
9077
{ text: 'Search', link: '/examples/search' },
91-
{ text: 'Confirmation Modal', link: '/examples/confirmation-modal' }
78+
{ text: 'Confirmation Modal', link: '/examples/confirmation-modal' },
79+
{ text: 'Page Change Logger', link: '/examples/page-change-logger' }
9280
]
9381
}
9482
]
@@ -100,7 +88,7 @@ export default defineConfig({
10088

10189
footer: {
10290
message: 'Released under the MIT License.',
103-
copyright: 'Copyright © 2024 Diffyne'
91+
copyright: 'Copyright © 2025 Diffyne'
10492
},
10593

10694
search: {

docs/guide/index.md

Lines changed: 0 additions & 86 deletions
This file was deleted.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,5 @@ Traditional server-side rendering sends full HTML on every interaction. Diffyne
9999
- **Interactive UIs** without writing JavaScript
100100
- **Real-time apps** with WebSocket support
101101

102-
Ready to get started? [Read the guide →](/guide/)
102+
Ready to get started? [Read the guide →](/getting-started/installation)
103103

scripts/sync-docs.js

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,53 @@
11
#!/usr/bin/env node
22

3-
import { readFileSync, writeFileSync, mkdirSync, readdirSync, statSync, cpSync } from 'fs';
3+
import { readFileSync, writeFileSync, mkdirSync, readdirSync, statSync, cpSync, unlinkSync, rmdirSync } from 'fs';
44
import { join, dirname, relative } from 'path';
55
import { fileURLToPath } from 'url';
66

77
const __filename = fileURLToPath(import.meta.url);
88
const __dirname = dirname(__filename);
99

10-
// Configuration
11-
// Default assumes docs repo is cloned as sibling directory
1210
const DOCS_SOURCE = process.env.DOCS_SOURCE_PATH || join(__dirname, '../../docs');
13-
const DOCS_TARGET = join(__dirname, '../docs/guide');
11+
const DOCS_TARGET = join(__dirname, '../docs');
1412

1513
console.log('📚 Syncing documentation...');
1614
console.log(`Source: ${DOCS_SOURCE}`);
1715
console.log(`Target: ${DOCS_TARGET}`);
1816

19-
// Ensure target directory exists
2017
mkdirSync(DOCS_TARGET, { recursive: true });
2118

22-
// Function to recursively copy and convert markdown files
19+
function clearOldFiles(targetDir, isRoot = false) {
20+
const entries = readdirSync(targetDir, { withFileTypes: true });
21+
22+
for (const entry of entries) {
23+
const entryPath = join(targetDir, entry.name);
24+
25+
if (entry.isDirectory()) {
26+
clearOldFiles(entryPath, false);
27+
try {
28+
const subEntries = readdirSync(entryPath);
29+
if (subEntries.length === 0) {
30+
rmdirSync(entryPath);
31+
}
32+
} catch (e) {
33+
}
34+
} else if (entry.isFile() && entry.name.endsWith('.md')) {
35+
if (isRoot && entry.name === 'index.md') {
36+
continue;
37+
}
38+
unlinkSync(entryPath);
39+
}
40+
}
41+
}
42+
43+
console.log('🧹 Cleaning old files...');
44+
try {
45+
if (readdirSync(DOCS_TARGET).length > 0) {
46+
clearOldFiles(DOCS_TARGET, true);
47+
}
48+
} catch (e) {
49+
}
50+
2351
function syncDirectory(sourceDir, targetDir, basePath = '') {
2452
const entries = readdirSync(sourceDir, { withFileTypes: true });
2553

@@ -28,37 +56,26 @@ function syncDirectory(sourceDir, targetDir, basePath = '') {
2856
const targetPath = join(targetDir, entry.name);
2957

3058
if (entry.isDirectory()) {
31-
// Skip certain directories
3259
if (entry.name === 'node_modules' || entry.name === '.git') {
3360
continue;
3461
}
3562

3663
mkdirSync(targetPath, { recursive: true });
3764
syncDirectory(sourcePath, targetPath, join(basePath, entry.name));
3865
} else if (entry.isFile() && entry.name.endsWith('.md')) {
39-
// Read source file
4066
let content = readFileSync(sourcePath, 'utf-8');
4167

42-
// Add VitePress frontmatter if not present
4368
if (!content.startsWith('---')) {
4469
const frontmatter = generateFrontmatter(entry.name, basePath);
4570
content = frontmatter + '\n\n' + content;
4671
}
4772

48-
// Fix relative links
49-
content = fixLinks(content, basePath);
50-
51-
// Fix syntax highlighting issues
52-
content = fixSyntaxHighlighting(content);
53-
54-
// Write to target
5573
writeFileSync(targetPath, content, 'utf-8');
5674
console.log(`✓ Synced: ${join(basePath, entry.name)}`);
5775
}
5876
}
5977
}
6078

61-
// Generate VitePress frontmatter
6279
function generateFrontmatter(filename, basePath) {
6380
const title = filename
6481
.replace('.md', '')
@@ -72,44 +89,6 @@ description: ${title} - Diffyne Documentation
7289
---`;
7390
}
7491

75-
// Fix relative links in markdown
76-
function fixLinks(content, basePath) {
77-
// Fix ../ links
78-
content = content.replace(/\]\(\.\.\//g, '](/guide/');
79-
80-
// Fix ./ links in same directory
81-
content = content.replace(/\]\(\.\//g, '](/guide/');
82-
83-
// Fix links to other sections
84-
content = content.replace(/\]\(([^)]+\.md)\)/g, (match, path) => {
85-
// Convert relative paths to absolute guide paths
86-
if (path.startsWith('../')) {
87-
const relativePath = path.replace('../', '');
88-
return `](/guide/${relativePath})`;
89-
}
90-
if (path.startsWith('./')) {
91-
const relativePath = path.replace('./', '');
92-
return `](/guide/${basePath}/${relativePath})`;
93-
}
94-
return match;
95-
});
96-
97-
return content;
98-
}
99-
100-
// Fix syntax highlighting issues
101-
function fixSyntaxHighlighting(content) {
102-
// Replace 'env' language with 'bash' (VitePress doesn't support 'env')
103-
content = content.replace(/```env\n/g, '```bash\n');
104-
105-
// Remove any stray HTML closing tags that might break VitePress
106-
// This is a safety measure for malformed markdown
107-
content = content.replace(/^(\s*)<\/[a-z]+>\s*$/gm, '');
108-
109-
return content;
110-
}
111-
112-
// Start sync
11392
try {
11493
syncDirectory(DOCS_SOURCE, DOCS_TARGET);
11594
console.log('\n✅ Documentation sync complete!');

0 commit comments

Comments
 (0)