-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add dev server functionality based on docsify #9347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
483796e
Add dev server functionality based on docsify
ntrogh 8cc5756
Add collapsible nav bar
ntrogh 9015040
Update index.html
ntrogh 3b487e7
Update index.html
ntrogh b2367e6
Merge branch 'main' into ntrogh/docs-dev-server
ntrogh 5f08bad
Add GH alerts and image zoom
ntrogh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| * [Docs](/docs/setup/setup-overview) | ||
| * [Extension API](/api/get-started/your-first-extension) | ||
| * [Blogs](/blogs/) | ||
| * [Release Notes](/release-notes/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Blog Posts | ||
|
|
||
| Select a post from the sidebar to read it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // Generates _sidebar.md from docs/toc.json and api/toc.json | ||
| // Usage: node build/generate-sidebar.js | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const ROOT = path.resolve(__dirname, '..'); | ||
|
|
||
| function loadJSON(filePath) { | ||
| const raw = fs.readFileSync(filePath, 'utf-8'); | ||
| // Strip JS-style comments (// ...) that appear in api/toc.json | ||
| const cleaned = raw.replace(/^\s*\/\/.*$/gm, ''); | ||
| return JSON.parse(cleaned); | ||
| } | ||
|
|
||
| // Extract frontmatter fields from a markdown file | ||
| function parseFrontmatter(filePath) { | ||
| const content = fs.readFileSync(filePath, 'utf-8'); | ||
| const match = content.match(/^---\s*\n([\s\S]*?)\n---/); | ||
| if (!match) return {}; | ||
| const fm = {}; | ||
| for (const line of match[1].split('\n')) { | ||
| const idx = line.indexOf(':'); | ||
| if (idx === -1) continue; | ||
| const key = line.substring(0, idx).trim(); | ||
| const val = line.substring(idx + 1).trim().replace(/^["']|["']$/g, ''); | ||
| fm[key] = val; | ||
| } | ||
| return fm; | ||
| } | ||
|
|
||
| function renderTopics(topics, indent) { | ||
| let md = ''; | ||
| for (const item of topics) { | ||
| // Subsection: ["", "", { name, topics }] | ||
| if (item.length === 3 && typeof item[2] === 'object') { | ||
| const sub = item[2]; | ||
| md += `${indent}- **${sub.name}**\n`; | ||
| md += renderTopics(sub.topics, indent + ' '); | ||
| } else { | ||
| const [title, docPath] = item; | ||
| if (!title || !docPath) continue; | ||
| // Keep leading / so links are always absolute from root | ||
| // (required with relativePath: true to avoid relative resolution) | ||
| md += `${indent}- [${title}](${docPath})\n`; | ||
| } | ||
| } | ||
| return md; | ||
| } | ||
|
|
||
| function buildSidebar() { | ||
| const docsToc = loadJSON(path.join(ROOT, 'docs', 'toc.json')); | ||
| const apiToc = loadJSON(path.join(ROOT, 'api', 'toc.json')); | ||
|
|
||
| // Docs sidebar | ||
| let docsSidebar = ''; | ||
| for (const section of docsToc) { | ||
| docsSidebar += `- **${section.name}**\n`; | ||
| docsSidebar += renderTopics(section.topics, ' '); | ||
| } | ||
| fs.writeFileSync(path.join(ROOT, '_sidebar_docs.md'), docsSidebar, 'utf-8'); | ||
| console.log('Generated _sidebar_docs.md'); | ||
|
|
||
| // API sidebar | ||
| let apiSidebar = ''; | ||
| for (const section of apiToc) { | ||
| apiSidebar += `- **${section.name}**\n`; | ||
| apiSidebar += renderTopics(section.topics, ' '); | ||
| } | ||
| fs.writeFileSync(path.join(ROOT, '_sidebar_api.md'), apiSidebar, 'utf-8'); | ||
| console.log('Generated _sidebar_api.md'); | ||
|
|
||
| // Release Notes sidebar — sorted by Order descending, using TOCTitle | ||
| const rnDir = path.join(ROOT, 'release-notes'); | ||
| const rnEntries = fs.readdirSync(rnDir) | ||
| .filter(f => f.endsWith('.md') && f !== 'README.md') | ||
| .map(f => { | ||
| const fm = parseFrontmatter(path.join(rnDir, f)); | ||
| return { | ||
| file: f.replace(/\.md$/, ''), | ||
| order: parseInt(fm.Order, 10) || 0, | ||
| title: fm.TOCTitle || f.replace(/\.md$/, '') | ||
| }; | ||
| }) | ||
| .sort((a, b) => b.order - a.order); | ||
|
|
||
| let rnSidebar = ''; | ||
| for (const entry of rnEntries) { | ||
| rnSidebar += `- [${entry.title}](/release-notes/${entry.file})\n`; | ||
| } | ||
| fs.writeFileSync(path.join(ROOT, '_sidebar_release-notes.md'), rnSidebar, 'utf-8'); | ||
| console.log('Generated _sidebar_release-notes.md'); | ||
|
|
||
| // Blogs sidebar — sorted by Order descending, using TOCTitle, grouped by year | ||
| const blogsDir = path.join(ROOT, 'blogs'); | ||
| const blogEntries = []; | ||
| const years = fs.readdirSync(blogsDir).filter(d => /^\d{4}$/.test(d)); | ||
| for (const year of years) { | ||
| const yearDir = path.join(blogsDir, year); | ||
| const months = fs.readdirSync(yearDir).filter(d => | ||
| fs.statSync(path.join(yearDir, d)).isDirectory() | ||
| ); | ||
| for (const month of months) { | ||
| const monthDir = path.join(yearDir, month); | ||
| const days = fs.readdirSync(monthDir).filter(d => | ||
| fs.statSync(path.join(monthDir, d)).isDirectory() | ||
| ); | ||
| for (const day of days) { | ||
| const dayDir = path.join(monthDir, day); | ||
| const posts = fs.readdirSync(dayDir).filter(f => f.endsWith('.md')); | ||
| for (const post of posts) { | ||
| const fm = parseFrontmatter(path.join(dayDir, post)); | ||
| blogEntries.push({ | ||
| year, | ||
| path: `/blogs/${year}/${month}/${day}/${post.replace(/\.md$/, '')}`, | ||
| order: parseInt(fm.Order, 10) || 0, | ||
| title: fm.TOCTitle || post.replace(/\.md$/, '').replace(/-/g, ' ') | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| blogEntries.sort((a, b) => b.order - a.order); | ||
|
|
||
| let blogsSidebar = ''; | ||
| let currentYear = ''; | ||
| for (const entry of blogEntries) { | ||
| if (entry.year !== currentYear) { | ||
| currentYear = entry.year; | ||
| blogsSidebar += `- **${currentYear}**\n`; | ||
| } | ||
| blogsSidebar += ` - [${entry.title}](${entry.path})\n`; | ||
| } | ||
| fs.writeFileSync(path.join(ROOT, '_sidebar_blogs.md'), blogsSidebar, 'utf-8'); | ||
| console.log('Generated _sidebar_blogs.md'); | ||
|
|
||
| // Default sidebar (for root page) | ||
| fs.copyFileSync( | ||
| path.join(ROOT, '_sidebar_docs.md'), | ||
| path.join(ROOT, '_sidebar.md') | ||
| ); | ||
| console.log('Generated _sidebar.md (default → docs)'); | ||
| } | ||
|
|
||
| buildSidebar(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.