Skip to content

Commit

Permalink
feat: improve guide structure & template dynamic loading (#86)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
a1mersnow and antfu authored Dec 27, 2023
1 parent d70bed9 commit 59c3280
Show file tree
Hide file tree
Showing 13 changed files with 456 additions and 211 deletions.
3 changes: 0 additions & 3 deletions content/foo.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@antfu/eslint-config": "^2.6.0",
"@iconify-json/logos": "^1.1.42",
"@iconify/json": "^2.2.162",
"@nuxt/content": "^2.10.0",
"@nuxt/content": "2.9.0",
"@nuxt/devtools": "^1.0.6",
"@nuxt/kit": "^3.9.0",
"@nuxtjs/color-mode": "^3.3.2",
Expand Down
21 changes: 17 additions & 4 deletions pages/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@
const router = useRouter()
const play = usePlaygroundStore()
const templatesMap = Object.fromEntries(
Object.entries(import.meta.glob('~/content/**/.template/index.ts'))
.map(([key, loader]) => [
key
.replace(/^\/content/, '')
.replace(/\/\.template\/index\.ts$/, '')
.replace(/\/\d+\./g, '/'),
loader,
]),
)
if (process.dev)
// eslint-disable-next-line no-console
console.log('templates', Object.keys(templatesMap))
async function mount(path: string) {
if (path === '/views/app-vue')
play.mountGuide(await import('~/content/views/1.app-vue/index').then(m => m.meta))
else if (path === '/views/routing')
play.mountGuide(await import('~/content/views/3.routing/index').then(m => m.meta))
if (templatesMap[path])
play.mountGuide(await templatesMap[path]().then((m: any) => m.meta))
else
play.mountGuide() // unmount previous guide
}
Expand Down
Loading

0 comments on commit 59c3280

Please sign in to comment.