@sullux/markdown-docs 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +72 -0
- package/bin/cli.js +37 -0
- package/index.js +4 -0
- package/lib/assets.js +22 -0
- package/lib/config.js +34 -0
- package/lib/layout.js +53 -0
- package/lib/search.js +40 -0
- package/lib/site.js +73 -0
- package/lib/summary.js +57 -0
- package/lib/theme.js +75 -0
- package/lib/toc.js +21 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Charles Sullivan <charles@sullux.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @sullux/markdown-docs
|
|
2
|
+
|
|
3
|
+
A zero-dependency, local-first static documentation website generator compiling GitBook-style Markdown documentation folders into fast, responsive, searchable HTML websites.
|
|
4
|
+
|
|
5
|
+
Built on `@sullux/markdown-compiler` and `@sullux/markdown-html`, `@sullux/markdown-docs` operates as both a standalone CLI application and a Node.js library.
|
|
6
|
+
|
|
7
|
+
## Core Features
|
|
8
|
+
|
|
9
|
+
* **GitBook `SUMMARY.md` Support:** Automatically parses `SUMMARY.md` navigation lists into sidebar navigation menus (with auto-discovery fallback if `SUMMARY.md` is omitted).
|
|
10
|
+
* **Zero Dependencies:** Pure Vanilla JS implementation with zero external packages.
|
|
11
|
+
* **Client-Side Search:** Auto-generates a lightweight JSON search index and embedded client-side search UI.
|
|
12
|
+
* **Responsive Layout:** Clean GitBook-inspired UI with collapsible sidebar navigation, dark/light theme toggle, and mobile support.
|
|
13
|
+
* **Rich Component Support:** Supports all `@sullux/markdown-html` features including code syntax highlighting, callout boxes (`> [!NOTE]`, `{% hint %}`), GFM tables, and custom image dimensions.
|
|
14
|
+
* **Static Asset Copying:** Automatically copies non-markdown assets (PNGs, SVGs, PDFs) directly to the output directory.
|
|
15
|
+
|
|
16
|
+
## Installation & CLI Usage
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# Global installation or via npx
|
|
20
|
+
npm install -g @sullux/markdown-docs
|
|
21
|
+
|
|
22
|
+
# Generate site from a docs directory
|
|
23
|
+
markdown-docs -i ./docs -o ./_site -t "Project Documentation"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### CLI Options
|
|
27
|
+
|
|
28
|
+
| Flag | Long Flag | Description | Default |
|
|
29
|
+
| :--- | :--- | :--- | :--- |
|
|
30
|
+
| `-i` | `--input` | Input Markdown docs directory | Current working directory |
|
|
31
|
+
| `-o` | `--output` | Output directory | `<input>/_site` |
|
|
32
|
+
| `-t` | `--title` | Documentation site title | Directory name |
|
|
33
|
+
| | `--baseUrl` | Base URL prefix for links | `""` |
|
|
34
|
+
| `-h` | `--help` | Display CLI help menu | |
|
|
35
|
+
|
|
36
|
+
## Programmatic API Usage
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
const { generateSite } = require('@sullux/markdown-docs')
|
|
40
|
+
|
|
41
|
+
const result = generateSite({
|
|
42
|
+
input: './docs',
|
|
43
|
+
output: './dist',
|
|
44
|
+
title: 'Sullux API Docs',
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
console.log(`Generated ${result.pageCount} pages at ${result.output}`)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Folder Topography
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
packages/markdown-docs/
|
|
54
|
+
├── bin/
|
|
55
|
+
│ └── cli.js # Executable CLI entrypoint
|
|
56
|
+
├── lib/
|
|
57
|
+
│ ├── config.js # Option and CLI argument parser
|
|
58
|
+
│ ├── summary.js # SUMMARY.md parser and directory scanner
|
|
59
|
+
│ ├── layout.js # Responsive HTML page template generator
|
|
60
|
+
│ ├── theme.js # Embedded GitBook CSS styles
|
|
61
|
+
│ ├── search.js # Client-side search index and JS script
|
|
62
|
+
│ ├── assets.js # Static asset copy utility
|
|
63
|
+
│ └── site.js # Site generation coordinator
|
|
64
|
+
├── index.js # Package API entrypoint
|
|
65
|
+
└── package.json # Package manifest
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Running Unit Tests
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
yarn test
|
|
72
|
+
```
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { parseArgs } = require('../lib/config')
|
|
4
|
+
const { generateSite } = require('../lib/site')
|
|
5
|
+
|
|
6
|
+
const printHelp = () => {
|
|
7
|
+
console.log(`
|
|
8
|
+
Usage: markdown-docs [options]
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
-i, --input <dir> Path to input Markdown docs directory (default: CWD)
|
|
12
|
+
-o, --output <dir> Path to output directory (default: <input>/_site)
|
|
13
|
+
-t, --title <title> Site title
|
|
14
|
+
--baseUrl <url> Base URL prefix for links
|
|
15
|
+
-h, --help Show help documentation
|
|
16
|
+
`)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const main = () => {
|
|
20
|
+
const args = process.argv.slice(2)
|
|
21
|
+
const options = parseArgs(args)
|
|
22
|
+
|
|
23
|
+
if (options.help) {
|
|
24
|
+
printHelp()
|
|
25
|
+
process.exit(0)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const res = generateSite(options)
|
|
30
|
+
console.log(`Successfully generated ${res.pageCount} documentation pages -> ${res.output}`)
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error(`Error generating docs: ${err.message}`)
|
|
33
|
+
process.exit(1)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
main()
|
package/index.js
ADDED
package/lib/assets.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const fs = require('node:fs')
|
|
2
|
+
const path = require('node:path')
|
|
3
|
+
|
|
4
|
+
const copyAssets = (srcDir, destDir) => {
|
|
5
|
+
if (!fs.existsSync(srcDir)) return
|
|
6
|
+
const entries = fs.readdirSync(srcDir, { withFileTypes: true })
|
|
7
|
+
|
|
8
|
+
for (const entry of entries) {
|
|
9
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === '_site') continue
|
|
10
|
+
const srcPath = path.join(srcDir, entry.name)
|
|
11
|
+
const destPath = path.join(destDir, entry.name)
|
|
12
|
+
|
|
13
|
+
if (entry.isDirectory()) {
|
|
14
|
+
copyAssets(srcPath, destPath)
|
|
15
|
+
} else if (entry.isFile() && !entry.name.endsWith('.md')) {
|
|
16
|
+
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true })
|
|
17
|
+
fs.copyFileSync(srcPath, destPath)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = { copyAssets }
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const path = require('node:path')
|
|
2
|
+
|
|
3
|
+
const parseArgs = (args = []) => {
|
|
4
|
+
const options = {}
|
|
5
|
+
for (let i = 0; i < args.length; i++) {
|
|
6
|
+
const arg = args[i]
|
|
7
|
+
if (arg === '-i' || arg === '--input') {
|
|
8
|
+
options.input = args[++i]
|
|
9
|
+
} else if (arg === '-o' || arg === '--output') {
|
|
10
|
+
options.output = args[++i]
|
|
11
|
+
} else if (arg === '-t' || arg === '--title') {
|
|
12
|
+
options.title = args[++i]
|
|
13
|
+
} else if (arg === '--logo') {
|
|
14
|
+
options.logo = args[++i]
|
|
15
|
+
} else if (arg === '--baseUrl') {
|
|
16
|
+
options.baseUrl = args[++i]
|
|
17
|
+
} else if (arg === '-h' || arg === '--help') {
|
|
18
|
+
options.help = true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return options
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const normalizeConfig = (opts = {}) => {
|
|
25
|
+
const input = path.resolve(opts.input || process.cwd())
|
|
26
|
+
const output = path.resolve(opts.output || path.join(input, '_site'))
|
|
27
|
+
const title = opts.title || path.basename(input)
|
|
28
|
+
const baseUrl = opts.baseUrl || ''
|
|
29
|
+
const logo = opts.logo || ''
|
|
30
|
+
|
|
31
|
+
return { input, output, title, baseUrl, logo }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = { parseArgs, normalizeConfig }
|
package/lib/layout.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const { getCss } = require('./theme')
|
|
2
|
+
const { getSearchScript } = require('./search')
|
|
3
|
+
|
|
4
|
+
const renderNavItems = (items, currentHref, baseUrl = '') => {
|
|
5
|
+
if (!items || items.length === 0) return ''
|
|
6
|
+
return `<ul class="nav-list">\n` + items.map((item) => {
|
|
7
|
+
const isActive = item.href === currentHref ? ' active' : ''
|
|
8
|
+
const itemHref = item.href ? `${baseUrl}${item.href.replace(/\.md$/, '.html')}` : '#'
|
|
9
|
+
const subNav = item.children ? renderNavItems(item.children, currentHref, baseUrl) : ''
|
|
10
|
+
return `<li class="nav-item">
|
|
11
|
+
<a href="${itemHref}" class="nav-link${isActive}">${item.title}</a>
|
|
12
|
+
${subNav}
|
|
13
|
+
</li>\n`
|
|
14
|
+
}).join('') + `</ul>\n`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const renderPageLayout = ({ title, navTree, contentHtml, currentHref, baseUrl = '' }) => {
|
|
18
|
+
const sidebarNav = renderNavItems(navTree, currentHref, baseUrl)
|
|
19
|
+
|
|
20
|
+
return `<!DOCTYPE html>
|
|
21
|
+
<html lang="en">
|
|
22
|
+
<head>
|
|
23
|
+
<meta charset="UTF-8" />
|
|
24
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
25
|
+
<title>${title}</title>
|
|
26
|
+
<style>${getCss()}</style>
|
|
27
|
+
</head>
|
|
28
|
+
<body>
|
|
29
|
+
<aside class="app-sidebar">
|
|
30
|
+
<a href="${baseUrl}index.html" class="app-title">${title}</a>
|
|
31
|
+
<div class="search-box">
|
|
32
|
+
<input type="text" id="doc-search" class="search-input" placeholder="Search docs..." />
|
|
33
|
+
<div id="search-results" class="search-results"></div>
|
|
34
|
+
</div>
|
|
35
|
+
<nav class="app-nav">
|
|
36
|
+
${sidebarNav}
|
|
37
|
+
</nav>
|
|
38
|
+
</aside>
|
|
39
|
+
<main class="app-main">
|
|
40
|
+
<header class="app-header">
|
|
41
|
+
<span class="header-title">${title}</span>
|
|
42
|
+
<button class="theme-toggle" onclick="document.body.toggleAttribute('data-theme', document.body.hasAttribute('data-theme') ? '' : 'dark')">Theme</button>
|
|
43
|
+
</header>
|
|
44
|
+
<article class="app-content">
|
|
45
|
+
${contentHtml}
|
|
46
|
+
</article>
|
|
47
|
+
</main>
|
|
48
|
+
${getSearchScript()}
|
|
49
|
+
</body>
|
|
50
|
+
</html>`
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { renderPageLayout }
|
package/lib/search.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const getSearchScript = () => `
|
|
2
|
+
<script>
|
|
3
|
+
(function() {
|
|
4
|
+
var searchInput = document.getElementById('doc-search');
|
|
5
|
+
var resultsContainer = document.getElementById('search-results');
|
|
6
|
+
if (!searchInput || !resultsContainer) return;
|
|
7
|
+
|
|
8
|
+
var index = [];
|
|
9
|
+
fetch('search-index.json')
|
|
10
|
+
.then(function(res) { return res.json(); })
|
|
11
|
+
.then(function(data) { index = data; })
|
|
12
|
+
.catch(function() {});
|
|
13
|
+
|
|
14
|
+
searchInput.addEventListener('input', function(e) {
|
|
15
|
+
var query = e.target.value.toLowerCase().trim();
|
|
16
|
+
if (!query) {
|
|
17
|
+
resultsContainer.style.display = 'none';
|
|
18
|
+
resultsContainer.innerHTML = '';
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var matches = index.filter(function(item) {
|
|
23
|
+
return item.title.toLowerCase().indexOf(query) !== -1 ||
|
|
24
|
+
item.content.toLowerCase().indexOf(query) !== -1;
|
|
25
|
+
}).slice(0, 8);
|
|
26
|
+
|
|
27
|
+
if (matches.length === 0) {
|
|
28
|
+
resultsContainer.innerHTML = '<div class="search-item">No results found</div>';
|
|
29
|
+
} else {
|
|
30
|
+
resultsContainer.innerHTML = matches.map(function(item) {
|
|
31
|
+
return '<a href="' + item.href + '" class="search-item"><strong>' + item.title + '</strong></a>';
|
|
32
|
+
}).join('');
|
|
33
|
+
}
|
|
34
|
+
resultsContainer.style.display = 'block';
|
|
35
|
+
});
|
|
36
|
+
})();
|
|
37
|
+
</script>
|
|
38
|
+
`
|
|
39
|
+
|
|
40
|
+
module.exports = { getSearchScript }
|
package/lib/site.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const fs = require('node:fs')
|
|
2
|
+
const path = require('node:path')
|
|
3
|
+
const { markdownToHtml } = require('@sullux/markdown-html')
|
|
4
|
+
const { normalizeConfig } = require('./config')
|
|
5
|
+
const { getNavigationTree } = require('./summary')
|
|
6
|
+
const { renderPageLayout } = require('./layout')
|
|
7
|
+
const { copyAssets } = require('./assets')
|
|
8
|
+
|
|
9
|
+
const collectMarkdownFiles = (dir, rootDir = dir) => {
|
|
10
|
+
const files = []
|
|
11
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
12
|
+
|
|
13
|
+
for (const entry of entries) {
|
|
14
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === '_site') continue
|
|
15
|
+
const fullPath = path.join(dir, entry.name)
|
|
16
|
+
|
|
17
|
+
if (entry.isDirectory()) {
|
|
18
|
+
files.push(...collectMarkdownFiles(fullPath, rootDir))
|
|
19
|
+
} else if (entry.isFile() && entry.name.endsWith('.md') && entry.name !== 'SUMMARY.md') {
|
|
20
|
+
const relPath = path.relative(rootDir, fullPath)
|
|
21
|
+
files.push({ fullPath, relPath })
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return files
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const generateSite = (options = {}) => {
|
|
29
|
+
const config = normalizeConfig(options)
|
|
30
|
+
if (!fs.existsSync(config.input)) {
|
|
31
|
+
throw new Error(`Input directory does not exist: ${config.input}`)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fs.mkdirSync(config.output, { recursive: true })
|
|
35
|
+
const navTree = getNavigationTree(config.input)
|
|
36
|
+
const mdFiles = collectMarkdownFiles(config.input)
|
|
37
|
+
const searchIndex = []
|
|
38
|
+
|
|
39
|
+
for (const file of mdFiles) {
|
|
40
|
+
const rawMd = fs.readFileSync(file.fullPath, 'utf8')
|
|
41
|
+
const contentHtml = markdownToHtml(rawMd)
|
|
42
|
+
|
|
43
|
+
const relHtmlPath = file.relPath.replace(/\.md$/, '.html')
|
|
44
|
+
const outHtmlPath = path.join(config.output, relHtmlPath)
|
|
45
|
+
|
|
46
|
+
fs.mkdirSync(path.dirname(outHtmlPath), { recursive: true })
|
|
47
|
+
|
|
48
|
+
const pageTitle = `${file.relPath.replace(/\.md$/, '')} - ${config.title}`
|
|
49
|
+
const fullHtml = renderPageLayout({
|
|
50
|
+
title: pageTitle,
|
|
51
|
+
navTree,
|
|
52
|
+
contentHtml,
|
|
53
|
+
currentHref: file.relPath,
|
|
54
|
+
baseUrl: config.baseUrl,
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
fs.writeFileSync(outHtmlPath, fullHtml, 'utf8')
|
|
58
|
+
|
|
59
|
+
const plainText = rawMd.replace(/[#*`_\[\]()\-]/g, ' ').replace(/\s+/g, ' ').trim()
|
|
60
|
+
searchIndex.push({
|
|
61
|
+
title: file.relPath.replace(/\.md$/, ''),
|
|
62
|
+
href: relHtmlPath,
|
|
63
|
+
content: plainText.slice(0, 300),
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fs.writeFileSync(path.join(config.output, 'search-index.json'), JSON.stringify(searchIndex, null, 2))
|
|
68
|
+
copyAssets(config.input, config.output)
|
|
69
|
+
|
|
70
|
+
return { output: config.output, pageCount: mdFiles.length }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = { generateSite }
|
package/lib/summary.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const fs = require('node:fs')
|
|
2
|
+
const path = require('node:path')
|
|
3
|
+
const { parse } = require('@sullux/markdown-compiler')
|
|
4
|
+
|
|
5
|
+
const parseSummaryMd = (content) => {
|
|
6
|
+
const ast = parse(content)
|
|
7
|
+
const items = []
|
|
8
|
+
|
|
9
|
+
for (const block of ast.blocks) {
|
|
10
|
+
if (block.type === 'bulletList' || block.type === 'orderedList') {
|
|
11
|
+
for (const itemNodes of block.items || []) {
|
|
12
|
+
for (const node of itemNodes) {
|
|
13
|
+
if (node.type === 'link') {
|
|
14
|
+
const title = node.children ? node.children.map((c) => c.value || '').join('') : ''
|
|
15
|
+
items.push({ title, href: node.url, children: [] })
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return items
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const scanDir = (dir, rootDir = dir) => {
|
|
26
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
27
|
+
const items = []
|
|
28
|
+
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === '_site') continue
|
|
31
|
+
const fullPath = path.join(dir, entry.name)
|
|
32
|
+
const relPath = path.relative(rootDir, fullPath)
|
|
33
|
+
|
|
34
|
+
if (entry.isDirectory()) {
|
|
35
|
+
const children = scanDir(fullPath, rootDir)
|
|
36
|
+
if (children.length > 0) {
|
|
37
|
+
items.push({ title: entry.name, href: '', children })
|
|
38
|
+
}
|
|
39
|
+
} else if (entry.isFile() && entry.name.endsWith('.md') && entry.name !== 'SUMMARY.md') {
|
|
40
|
+
const title = entry.name.replace(/\.md$/, '')
|
|
41
|
+
items.push({ title, href: relPath, children: [] })
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return items
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const getNavigationTree = (inputDir) => {
|
|
49
|
+
const summaryPath = path.join(inputDir, 'SUMMARY.md')
|
|
50
|
+
if (fs.existsSync(summaryPath)) {
|
|
51
|
+
const content = fs.readFileSync(summaryPath, 'utf8')
|
|
52
|
+
return parseSummaryMd(content)
|
|
53
|
+
}
|
|
54
|
+
return scanDir(inputDir)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = { parseSummaryMd, scanDir, getNavigationTree }
|
package/lib/theme.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const getCss = () => `
|
|
2
|
+
:root {
|
|
3
|
+
--bg-primary: #ffffff;
|
|
4
|
+
--bg-sidebar: #f7f9fa;
|
|
5
|
+
--text-primary: #1c1e21;
|
|
6
|
+
--text-muted: #5c6975;
|
|
7
|
+
--border-color: #e8ecf0;
|
|
8
|
+
--accent-color: #3b82f6;
|
|
9
|
+
--accent-hover: #1d4ed8;
|
|
10
|
+
--code-bg: #f3f4f6;
|
|
11
|
+
--callout-info-bg: #eff6ff;
|
|
12
|
+
--callout-info-border: #3b82f6;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
[data-theme="dark"] {
|
|
16
|
+
--bg-primary: #0f172a;
|
|
17
|
+
--bg-sidebar: #1e293b;
|
|
18
|
+
--text-primary: #f8fafc;
|
|
19
|
+
--text-muted: #94a3b8;
|
|
20
|
+
--border-color: #334155;
|
|
21
|
+
--accent-color: #60a5fa;
|
|
22
|
+
--accent-hover: #93c5fd;
|
|
23
|
+
--code-bg: #1e293b;
|
|
24
|
+
--callout-info-bg: #1e3a8a;
|
|
25
|
+
--callout-info-border: #60a5fa;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
29
|
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--text-primary); background: var(--bg-primary); line-height: 1.6; display: flex; min-height: 100vh; }
|
|
30
|
+
|
|
31
|
+
.app-sidebar { width: 280px; background: var(--bg-sidebar); border-right: 1px solid var(--border-color); padding: 1.5rem; display: flex; flex-direction: column; shrink: 0; }
|
|
32
|
+
.app-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 1rem; color: var(--text-primary); text-decoration: none; display: flex; align-items: center; gap: 0.5rem; }
|
|
33
|
+
.search-box { margin-bottom: 1rem; position: relative; }
|
|
34
|
+
.search-input { width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--border-color); border-radius: 6px; background: var(--bg-primary); color: var(--text-primary); }
|
|
35
|
+
.search-results { position: absolute; top: 100%; left: 0; right: 0; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 6px; max-height: 250px; overflow-y: auto; z-index: 100; display: none; }
|
|
36
|
+
.search-item { padding: 0.5rem; text-decoration: none; color: var(--text-primary); display: block; border-bottom: 1px solid var(--border-color); }
|
|
37
|
+
.search-item:hover { background: var(--code-bg); }
|
|
38
|
+
|
|
39
|
+
.nav-list { list-style: none; }
|
|
40
|
+
.nav-item { margin-bottom: 0.25rem; }
|
|
41
|
+
.nav-link { display: block; padding: 0.4rem 0.6rem; color: var(--text-muted); text-decoration: none; border-radius: 4px; font-size: 0.95rem; }
|
|
42
|
+
.nav-link:hover, .nav-link.active { color: var(--accent-color); font-weight: 600; background: var(--code-bg); }
|
|
43
|
+
.nav-sub { list-style: none; padding-left: 1rem; margin-top: 0.25rem; }
|
|
44
|
+
|
|
45
|
+
.app-main { flex: 1; display: flex; flex-direction: column; overflow-x: hidden; }
|
|
46
|
+
.app-header { padding: 1rem 2rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
|
|
47
|
+
.app-content { flex: 1; padding: 2rem 3rem; max-width: 900px; }
|
|
48
|
+
.theme-toggle { cursor: pointer; background: none; border: 1px solid var(--border-color); padding: 0.4rem 0.8rem; border-radius: 6px; color: var(--text-primary); }
|
|
49
|
+
|
|
50
|
+
pre { background: var(--code-bg); padding: 1rem; border-radius: 8px; overflow-x: auto; margin: 1rem 0; font-family: monospace; }
|
|
51
|
+
code { background: var(--code-bg); padding: 0.2rem 0.4rem; border-radius: 4px; font-size: 0.9em; }
|
|
52
|
+
pre code { background: none; padding: 0; }
|
|
53
|
+
|
|
54
|
+
.callout { border-left: 4px solid var(--callout-info-border); background: var(--callout-info-bg); padding: 1rem; margin: 1rem 0; border-radius: 0 6px 6px 0; }
|
|
55
|
+
.callout-title { font-weight: 700; margin-bottom: 0.5rem; text-transform: uppercase; font-size: 0.85rem; letter-spacing: 0.05em; }
|
|
56
|
+
|
|
57
|
+
table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
|
|
58
|
+
th, td { border: 1px solid var(--border-color); padding: 0.6rem 0.8rem; text-align: left; }
|
|
59
|
+
th { background: var(--code-bg); }
|
|
60
|
+
|
|
61
|
+
.hl-kw { color: #d73a49; font-weight: bold; }
|
|
62
|
+
.hl-str { color: #032f62; }
|
|
63
|
+
.hl-num { color: #005cc5; }
|
|
64
|
+
.hl-cmt { color: #6a737d; font-style: italic; }
|
|
65
|
+
.hl-id { color: #6f42c1; }
|
|
66
|
+
.hl-punc { color: #24292e; }
|
|
67
|
+
|
|
68
|
+
@media (max-width: 768px) {
|
|
69
|
+
body { flex-direction: column; }
|
|
70
|
+
.app-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border-color); }
|
|
71
|
+
.app-content { padding: 1.5rem; }
|
|
72
|
+
}
|
|
73
|
+
`
|
|
74
|
+
|
|
75
|
+
module.exports = { getCss }
|
package/lib/toc.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { slugify } = require('@sullux/markdown-html/lib/markdown-to-html/slugify')
|
|
2
|
+
|
|
3
|
+
const extractToc = (ast) => {
|
|
4
|
+
if (!ast || !ast.blocks) return []
|
|
5
|
+
const usedSlugs = new Set()
|
|
6
|
+
const toc = []
|
|
7
|
+
|
|
8
|
+
for (const block of ast.blocks) {
|
|
9
|
+
if (block.type === 'header' && (block.level === 2 || block.level === 3)) {
|
|
10
|
+
const rawText = block.children
|
|
11
|
+
? block.children.map((c) => (c.type === 'text' ? c.value : '')).join('')
|
|
12
|
+
: ''
|
|
13
|
+
const slug = slugify(rawText, usedSlugs)
|
|
14
|
+
toc.push({ level: block.level, title: rawText, id: slug })
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return toc
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = { extractToc }
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sullux/markdown-docs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A zero-dependency, local-first static documentation site generator compiling GitBook-style Markdown docs.",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"markdown-docs": "./bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"author": "Charles Sullivan <charles@sullux.com>",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/Sullux/markdown.git",
|
|
14
|
+
"directory": "packages/markdown-docs"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/Sullux/markdown/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/Sullux/markdown/tree/main/packages/markdown-docs#readme",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"markdown",
|
|
22
|
+
"docs",
|
|
23
|
+
"gitbook",
|
|
24
|
+
"static-site-generator",
|
|
25
|
+
"documentation",
|
|
26
|
+
"compiler"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18.0.0"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public",
|
|
33
|
+
"registry": "https://registry.npmjs.org/"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@sullux/markdown-compiler": "^1.0.0",
|
|
37
|
+
"@sullux/markdown-html": "^1.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|