Skip to content

Commit

Permalink
Merge branch 'main' into ci/cr
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX authored Jul 24, 2024
2 parents cb61968 + a46aea8 commit 4158beb
Show file tree
Hide file tree
Showing 181 changed files with 6,078 additions and 2,996 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ packages/create-app/template/pages
packages/create-app/template/slides.md
packages/create-app/template/snippets
packages/slidev/README.md
packages/vscode/syntaxes/codeblock-patch.json
slides-export.md
*slides-export.pptx
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
shamefully-hoist=true
ignore-workspace-root-check=true
strict-peer-dependencies=false
link-workspace-packages=true
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode"
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode",
"--folder-uri=${workspaceRoot}/packages/vscode/syntaxes"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@
"jsonc",
"yaml"
],
"vitest.disableWorkspaceWarning": true
"vitest.disableWorkspaceWarning": true,
"slidev.include": [
"**/slides.md",
"packages/vscode/syntax/slidev.example.md"
]
}
2 changes: 1 addition & 1 deletion demo/starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"@slidev/theme-default": "^0.25.0",
"@slidev/theme-seriph": "^0.25.0",
"nodemon": "^3.1.4",
"vue": "^3.4.32"
"vue": "^3.4.33"
}
}
4 changes: 2 additions & 2 deletions demo/vue-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@slidev/cli": "workspace:*",
"@slidev/theme-default": "^0.25.0",
"@slidev/theme-seriph": "^0.25.0",
"@vue/compiler-sfc": "^3.4.32",
"@vue/compiler-sfc": "^3.4.33",
"nodemon": "^3.1.4",
"vue": "^3.4.32"
"vue": "^3.4.33"
}
}
38 changes: 4 additions & 34 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { DefaultTheme } from 'vitepress'
import { defineConfig } from 'vitepress'
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
import { version } from '../package.json'
import { getSidebarObject } from './sidebar-gen'
import { Advanced, BuiltIn, Guides, Resources } from './pages'
import Customizations from './customizations'

Expand Down Expand Up @@ -83,7 +84,7 @@ export default defineConfig({

nav: [
{
text: 'Guide',
text: '📖 Guide',
items: [
...Guides,
{
Expand Down Expand Up @@ -122,13 +123,14 @@ export default defineConfig({
],

sidebar: {
'/features/': [],
'/guide/': slidebars,
'/themes/': slidebars,
'/addons/': slidebars,
'/custom/': slidebars,
'/builtin/': slidebars,
'/resources/': slidebars,
...await getSidebarObject(),
'/features/': [],
'/': slidebars,
},

Expand All @@ -146,37 +148,5 @@ export default defineConfig({
label: '简体中文',
link: 'https://cn.sli.dev/',
},
fr: {
label: 'Français',
link: 'https://fr.sli.dev/',
},
es: {
label: 'Español',
link: 'https://es.sli.dev/',
},
ru: {
label: 'Русский',
link: 'https://ru.sli.dev/',
},
vn: {
label: 'Việt Nam',
link: 'https://vn.sli.dev/',
},
de: {
label: 'Deutsch',
link: 'https://de.sli.dev/',
},
br: {
label: 'Português (BR)',
link: 'https://br.sli.dev/',
},
el: {
label: 'Ελληνικά',
link: 'https://el.sli.dev/',
},
ja: {
label: '日本語',
link: 'https://ja.sli.dev/',
},
},
})
4 changes: 4 additions & 0 deletions docs/.vitepress/customizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default [
text: 'Configure Code Runners',
link: '/custom/config-code-runners',
},
{
text: 'Configure Transformers',
link: '/custom/config-transformers',
},
{
text: 'Configure Monaco',
link: '/custom/config-monaco',
Expand Down
137 changes: 137 additions & 0 deletions docs/.vitepress/sidebar-gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { fileURLToPath } from 'node:url'
import { join } from 'node:path'
import fg from 'fast-glob'
import type { DefaultTheme } from 'vitepress'
import graymatter from 'gray-matter'

const root = fileURLToPath(new URL('../../', import.meta.url))

interface ParsedFile {
filepath: string
path: string
matter: graymatter.GrayMatterFile<string>
title: string
}

function parseFile(file: string) {
const filepath = join(root, file)
const path = file.replace('docs/', '').replace('.md', '')
const matter = graymatter.read(filepath)
const title = matter.data.title || matter.content.match(/^#\s+(.*)/m)?.[1] || path
return {
filepath,
path,
matter,
title,
}
}

export async function getSidebarObject() {
const map: Record<string, DefaultTheme.SidebarItem[]> = {}

const parsedFeatures: ParsedFile[] = await fg([
'docs/features/*.md',
], {
onlyFiles: true,
cwd: root,
})
.then(files => files.map(parseFile))

const parsedGuides: ParsedFile[] = await fg([
'docs/guide/*.md',
], {
onlyFiles: true,
cwd: root,
})
.then(files => files.map(parseFile))

parsedFeatures.forEach(({ matter, path }) => {
const items: DefaultTheme.SidebarItem[] = [
{
text: 'Back to',
items: [
{
text: 'All Features',
link: '/features',
},
],
},
]

function findParsed(related: string) {
related = related.replace(/#.*$/, '')
const feature = parsedFeatures.find(file => file.path === related)
if (feature) {
return {
type: 'features',
item: feature,
}
}
const guide = parsedGuides.find(file => file.path === related)
if (guide) {
return {
type: 'guide',
item: guide,
}
}
return undefined
}

function frontmatterToSidebarItem(path: string | Record<string, string>): DefaultTheme.SidebarItem[] {
if (typeof path === 'string') {
const match = findParsed(path)
if (match?.type === 'features') {
return [{
text: `✨ ${match.item.title}`,
link: `/${match.item.path}`,
}]
}
if (match?.type === 'guide') {
return [{
text: `📖 ${match.item.title}`,
link: `/${match.item.path}`,
}]
}
console.warn(`Dependent file not found: ${path}`)
return [{
text: path,
link: `/${path}`,
}]
}
else {
return Object.entries(path).map(([text, link]) => ({
text,
link,
}))
}
}

if (matter.data.depends) {
items.push({
text: 'Depends on',
items: matter.data.depends.flatMap(frontmatterToSidebarItem),
})
}

if (matter.data.relates) {
items.push({
text: 'Related to',
items: matter.data.relates.flatMap(frontmatterToSidebarItem),
})
}

const derives = matter.data.derives
?? parsedFeatures.filter(f => f.matter.data.depends?.includes(path)).map(f => f.path)

if (derives.length) {
items.push({
text: 'Derives',
items: derives.flatMap(frontmatterToSidebarItem),
})
}

map[`/${path}`] = items
})

return map
}
Loading

0 comments on commit 4158beb

Please sign in to comment.