Skip to content

Commit

Permalink
feat: title and favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 24, 2021
1 parent c0dd298 commit e6fc35e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="https://raw.githubusercontent.com/slidevjs/slidev/main/assets/favicon.png">
<!-- head -->
</head>
<body>
Expand Down
6 changes: 4 additions & 2 deletions packages/client/internals/Presenter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { showOverview } from '../state'
import SlideContainer from './SlideContainer.vue'
import NavControls from './NavControls.vue'
import SlidesOverview from './SlidesOverview.vue'
// @ts-expect-error
import configs from '/@slidev/configs'
useHead({
title: 'Presenter Mode',
title: configs.title ? `Presenter - ${configs.title} - Slidev` : 'Presenter - Slidev',
})
const controls = useNavigateControls()
Expand All @@ -17,7 +19,7 @@ const controls = useNavigateControls()
<div class="grid-container">
<div class="grid-section top flex">
<div class="px-6 my-auto">
{{ controls.currentPage.value + 1}} / {{ controls.routes.length }}
{{ controls.currentPage.value + 1 }} / {{ controls.routes.length }}
</div>
<div class="flex-auto" />
<NavControls mode="persist" />
Expand Down
2 changes: 2 additions & 0 deletions packages/client/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ export const routes: RouteRecordRaw[] = [
...rawRoutes,
],
},
{ path: '', redirect: { path: '/0' } },
{ path: '/presenter', redirect: { path: '/presenter/0' } },
]
4 changes: 3 additions & 1 deletion packages/client/setup/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* __imports__ */
import { useHead } from '@vueuse/head'
// @ts-expect-error
import configs from '/@slidev/configs'

export default function setupApp() {
/* __injections__ */
useHead({
title: 'Slidev',
title: configs.title ? `${configs.title} - Slidev` : 'Slidev',
})
}
15 changes: 12 additions & 3 deletions packages/slidev/node/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ export interface ParseOptions {
enabledMonaco?: boolean
}

export interface SlidevConfig {
title: string
theme: string
}

export interface SlidesMarkdown {
filepath?: string
slides: SlidesMarkdownInfo[]
options: ParseOptions
raw: string
config: SlidevConfig
}

export async function load(
Expand Down Expand Up @@ -128,14 +134,17 @@ export function parse(
})
}

// make the first slide use cover layout by default
if (slides[0])
slides[0].frontmatter.layout ||= 'cover'
const headmatter = slides?.[0].frontmatter || {}
const config: SlidevConfig = Object.assign({}, headmatter.config || {})

config.theme ||= headmatter.theme || '@slidev/theme-default'
config.title ||= headmatter.title || (markdown.match(/^# (.*)$/m)?.[1] || '').trim()

return {
raw: markdown,
filepath,
slides,
options,
config,
}
}
12 changes: 7 additions & 5 deletions packages/slidev/node/plugins/slides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ export function createSlidesLoader({ entry, clientRoot, themeRoot, userRoot }: R
return res.end()
}

// console.log(`Hello from ${req.url} ${req.method}`)

next()
})
},
Expand All @@ -104,6 +102,7 @@ export function createSlidesLoader({ entry, clientRoot, themeRoot, userRoot }: R

const moduleEntries = [
'/@slidev/routes',
'/@slidev/configs',
...data.slides.map((i, idx) => `${entry}?id=${idx}.md`),
...data.slides.map((i, idx) => `${entry}?id=${idx}.json`),
]
Expand All @@ -126,10 +125,14 @@ export function createSlidesLoader({ entry, clientRoot, themeRoot, userRoot }: R
if (id === '/@slidev/routes')
return generateRoutes()

// routes
// layouts
if (id === '/@slidev/layouts')
return generateLayouts()

// configs
if (id === '/@slidev/configs')
return `export default ${JSON.stringify(data.config)}`

// pages
if (id.startsWith(entry)) {
const remaning = id.slice(entry.length + 1)
Expand Down Expand Up @@ -160,7 +163,7 @@ export function createSlidesLoader({ entry, clientRoot, themeRoot, userRoot }: R

const layouts = await getLayouts()
const pageNo = parseInt(no)
const layoutName = data.slides[pageNo].frontmatter?.layout || 'default'
const layoutName = data.slides[pageNo].frontmatter?.layout || (pageNo === 0 ? 'cover' : 'default')
if (!layouts[layoutName])
throw new Error(`Unknown layout "${layoutName}"`)

Expand Down Expand Up @@ -229,7 +232,6 @@ export function createSlidesLoader({ entry, clientRoot, themeRoot, userRoot }: R

let no = 0
const routes = [
'{ path: "", redirect: { path: "/0" } }',
...data.slides
.map((i, idx) => {
if (i.frontmatter?.disabled)
Expand Down

0 comments on commit e6fc35e

Please sign in to comment.