-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Expose additional vitepress sidebar options
- Loading branch information
Showing
23 changed files
with
305 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"typedoc-vitepress-theme": patch | ||
--- | ||
|
||
- Exposed additional sidebar options |
This file contains 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,35 @@ | ||
name: CI [typedoc-vitepress-theme] | ||
on: | ||
push: | ||
paths: | ||
- 'packages/typedoc-vitepress-theme/**' | ||
- '!packages/typedoc-vitepress-theme/README.md' | ||
- '!packages/typedoc-vitepress-theme/package.json' | ||
pull_request: | ||
paths: | ||
- 'packages/typedoc-vitepress-theme/**' | ||
- '!packages/typedoc-vitepress-theme/README.md' | ||
- '!packages/typedoc-vitepress-theme/package.json' | ||
jobs: | ||
lint-and-test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node: ['18'] | ||
name: Node ${{ matrix.node }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Set up Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
cache: 'npm' | ||
- name: Install | ||
run: npm install | ||
- name: Lint | ||
run: npm run lint --workspace typedoc-vitepress-theme | ||
- name: Build | ||
run: npm run build --workspace typedoc-plugin-markdown --workspace typedoc-vitepress-theme | ||
- name: Test | ||
run: npm run test --workspace typedoc-vitepress-theme |
This file contains 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export const DEFAULT_SIDEBAR_OPTIONS = { | ||
autoConfiguration: true, | ||
format: 'vitepress', | ||
pretty: false, | ||
collapse: true, | ||
}; |
This file contains 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 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
20 changes: 14 additions & 6 deletions
20
packages/typedoc-vitepress-theme/src/sidebars/sidebar.vitepress.ts
This file contains 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 |
---|---|---|
@@ -1,20 +1,28 @@ | ||
import { NavigationItem } from 'typedoc-plugin-markdown'; | ||
import { Sidebar } from '../options/models'; | ||
|
||
export = (navigation: NavigationItem[], basePath: string) => { | ||
export = (navigation: NavigationItem[], basePath: string, options: Sidebar) => { | ||
return navigation.map((navigationItem) => { | ||
return getNavigationItem(navigationItem, basePath); | ||
return getNavigationItem(navigationItem, basePath, options); | ||
}); | ||
}; | ||
|
||
function getNavigationItem(navigationItem: NavigationItem, basePath: string) { | ||
function getNavigationItem( | ||
navigationItem: NavigationItem, | ||
basePath: string, | ||
options: Sidebar, | ||
) { | ||
const hasChildren = navigationItem.children?.length; | ||
return { | ||
text: navigationItem.title, | ||
...(Boolean(navigationItem.url) && { | ||
link: `/${basePath}/${navigationItem.url}`, | ||
}), | ||
collapsed: true, | ||
items: navigationItem.children?.map((group) => { | ||
return getNavigationItem(group, basePath); | ||
...(hasChildren && { collapsed: options.collapse }), | ||
...(hasChildren && { | ||
items: navigationItem.children?.map((group) => | ||
getNavigationItem(group, basePath, options), | ||
), | ||
}), | ||
}; | ||
} |
This file contains 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
47 changes: 47 additions & 0 deletions
47
packages/typedoc-vitepress-theme/test/__scripts__/prepare.ts
This file contains 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,47 @@ | ||
import { spawn } from 'child_process'; | ||
import { consola } from 'consola'; | ||
import * as fs from 'fs-extra'; | ||
|
||
const timeStart = new Date().getTime(); | ||
|
||
consola.start(`Building test fixtures...`); | ||
|
||
// remove output dir | ||
fs.removeSync(`./test/out`); | ||
|
||
const fixtures = [ | ||
{ options: 'typedoc.base.json', outDir: 'default' }, | ||
{ options: 'typedoc.sidebar-options.json', outDir: 'sidebar-options' }, | ||
]; | ||
|
||
// write fixtures | ||
fixtures.forEach((fixture) => { | ||
writeMarkdown(fixture); | ||
}); | ||
|
||
function writeMarkdown(fixture: any) { | ||
spawn( | ||
'typedoc', | ||
[ | ||
...[ | ||
'-options', | ||
`./test/${fixture.options}`, | ||
'-logLevel', | ||
'Info', | ||
'-out', | ||
`./test/out/${fixture.outDir}`, | ||
], | ||
], | ||
{ | ||
stdio: 'inherit', | ||
}, | ||
); | ||
} | ||
process.on('exit', () => { | ||
consola.success( | ||
`Finished building fixtures in ${( | ||
(new Date().getTime() - timeStart) / | ||
1000 | ||
).toFixed(2)} seconds`, | ||
); | ||
}); |
76 changes: 76 additions & 0 deletions
76
packages/typedoc-vitepress-theme/test/specs/__snapshots__/vitepress.spec.ts.snap
This file contains 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,76 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`VitePress should generate typedoc sidebar 1`] = `"[{"text":"module-1","link":"/test/out/default/module-1/index.md","collapsed":true,"items":[{"text":"Classes","collapsed":true,"items":[{"text":"ClassA","link":"/test/out/default/module-1/classes/ClassA.md"},{"text":"ClassB","link":"/test/out/default/module-1/classes/ClassB.md"},{"text":"InterfaceA","link":"/test/out/default/module-1/classes/InterfaceA.md"},{"text":"InterfaceB","link":"/test/out/default/module-1/classes/InterfaceB.md"}]}]},{"text":"module-2","link":"/test/out/default/module-2/index.md","collapsed":true,"items":[{"text":"Classes","collapsed":true,"items":[{"text":"ClassA","link":"/test/out/default/module-2/classes/ClassA.md"},{"text":"ClassB","link":"/test/out/default/module-2/classes/ClassB.md"},{"text":"InterfaceA","link":"/test/out/default/module-2/classes/InterfaceA.md"},{"text":"InterfaceB","link":"/test/out/default/module-2/classes/InterfaceB.md"}]}]}]"`; | ||
|
||
exports[`VitePress should generate typedoc sidebar with options 1`] = ` | ||
"[ | ||
{ | ||
"text": "module-1", | ||
"link": "/test/out/sidebar-options/module-1/index.md", | ||
"collapsed": false, | ||
"items": [ | ||
{ | ||
"text": "Classes", | ||
"collapsed": false, | ||
"items": [ | ||
{ | ||
"text": "ClassA", | ||
"link": "/test/out/sidebar-options/module-1/classes/ClassA.md" | ||
}, | ||
{ | ||
"text": "ClassB", | ||
"link": "/test/out/sidebar-options/module-1/classes/ClassB.md" | ||
}, | ||
{ | ||
"text": "InterfaceA", | ||
"link": "/test/out/sidebar-options/module-1/classes/InterfaceA.md" | ||
}, | ||
{ | ||
"text": "InterfaceB", | ||
"link": "/test/out/sidebar-options/module-1/classes/InterfaceB.md" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"text": "module-2", | ||
"link": "/test/out/sidebar-options/module-2/index.md", | ||
"collapsed": false, | ||
"items": [ | ||
{ | ||
"text": "Classes", | ||
"collapsed": false, | ||
"items": [ | ||
{ | ||
"text": "ClassA", | ||
"link": "/test/out/sidebar-options/module-2/classes/ClassA.md" | ||
}, | ||
{ | ||
"text": "ClassB", | ||
"link": "/test/out/sidebar-options/module-2/classes/ClassB.md" | ||
}, | ||
{ | ||
"text": "InterfaceA", | ||
"link": "/test/out/sidebar-options/module-2/classes/InterfaceA.md" | ||
}, | ||
{ | ||
"text": "InterfaceB", | ||
"link": "/test/out/sidebar-options/module-2/classes/InterfaceB.md" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
]" | ||
`; | ||
|
||
exports[`VitePress should output docs with vitepress theme 1`] = ` | ||
"# typedoc-vitepress-theme | ||
## Modules | ||
- [module-1](module-1/index.md) | ||
- [module-2](module-2/index.md) | ||
" | ||
`; |
26 changes: 26 additions & 0 deletions
26
packages/typedoc-vitepress-theme/test/specs/vitepress.spec.ts
This file contains 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,26 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
describe(`VitePress`, () => { | ||
test(`should output docs with vitepress theme`, async () => { | ||
const contents = fs | ||
.readFileSync(path.join(__dirname, '../out/default/index.md')) | ||
.toString(); | ||
expect(contents).toMatchSnapshot(); | ||
}); | ||
|
||
test(`should generate typedoc sidebar`, async () => { | ||
const contents = fs | ||
.readFileSync(path.join(__dirname, '../out/default/typedoc-sidebar.json')) | ||
.toString(); | ||
expect(contents).toMatchSnapshot(); | ||
}); | ||
|
||
test(`should generate typedoc sidebar with options`, async () => { | ||
const contents = fs | ||
.readFileSync( | ||
path.join(__dirname, '../out/sidebar-options/typedoc-sidebar.json'), | ||
) | ||
.toString(); | ||
expect(contents).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains 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,5 @@ | ||
export class ClassA {} | ||
export class ClassB {} | ||
|
||
export class InterfaceA {} | ||
export class InterfaceB {} |
This file contains 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,5 @@ | ||
export class ClassA {} | ||
export class ClassB {} | ||
|
||
export class InterfaceA {} | ||
export class InterfaceB {} |
This file contains 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,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"experimentalDecorators": true, | ||
"esModuleInterop": true, | ||
"lib": ["es2020", "dom"], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"noImplicitAny": false, | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"strictNullChecks": false, | ||
"target": "es2020" | ||
} | ||
} |
This file contains 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,13 @@ | ||
{ | ||
"entryPoints": ["./stubs/*.ts"], | ||
"tsconfig": "./stubs/tsconfig.json", | ||
"out": "./out", | ||
"plugin": ["typedoc-plugin-markdown", "typedoc-vitepress-theme"], | ||
"readme": "none", | ||
"githubPages": false, | ||
"disableSources": true, | ||
"cleanOutputDir": true, | ||
"hideGenerator": true, | ||
"hidePageHeader": true, | ||
"hideBreadcrumbs": true | ||
} |
Oops, something went wrong.