Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: TitleRenderer defaults to render current slide's title #1469

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/builtin/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Total number of slides.
<SlidesTotal />
```

### `Titles`
### `TitleRenderer`

Insert the main title from a slide parsed as HTML.

Expand Down
4 changes: 2 additions & 2 deletions docs/custom/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ In addition, every slide accepts the following configuration in the Frontmatter
- `hide` (`boolean`): The same as `disabled`.
- `hideInToc` (`boolean`): Hide the slide for the `<Toc>` components (learn more [here](/builtin/components.html#toc)).
- `layout` (`string`): Defines the layout component applied to the slide (learn more [here](/guide/syntax.html#front-matter-layouts) and [here](/builtin/layouts.html)).
- `level` (`number`): Override the title level for the `<Title>` and `<Toc>` components (only if `title` has also been declared, learn more [here](/builtin/components.html#titles)).
- `level` (`number`): Override the title level for the `<TitleRenderer>` and `<Toc>` components (only if `title` has also been declared, learn more [here](/builtin/components.html#titlerenderer)).
- `preload` (`boolean`, default `true`): Preload the next slide (learn more [here](/guide/animations.html#motion)).
- `routeAlias` (`string`): Create a route alias that can be used in the URL or with the `<Link>` component (learn more [here](/builtin/components.html#link)).
- `src` (`string`): Includes a markdown file (learn more [here](/guide/syntax.html#multiple-entries)).
- `title` (`string`): Override the title for the `<Title>` and `<Toc>` components (learn more [here](/builtin/components.html#titles)).
- `title` (`string`): Override the title for the `<TitleRenderer>` and `<Toc>` components (learn more [here](/builtin/components.html#titlerenderer)).
- `transition` (`string | TransitionProps`): Defines the transition between the slide and the next one (learn more [here](/guide/animations.html#slide-transitions)).
- `zoom` (`number`): Custom zoom scale. Useful for slides with a lot of content.

Expand Down
4 changes: 2 additions & 2 deletions packages/client/internals/Goto.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { computed, ref, watch } from 'vue'
import Fuse from 'fuse.js'
import { activeElement, showGotoDialog } from '../state'
import { useNav } from '../composables/useNav'
import Titles from '#slidev/title-renderer'
import TitleRenderer from '#slidev/title-renderer'

const container = ref<HTMLDivElement>()
const input = ref<HTMLInputElement>()
Expand Down Expand Up @@ -161,7 +161,7 @@ watch(activeElement, () => {
<div w-4 text-right op50 text-sm>
{{ item.no }}
</div>
<Titles :no="item.no" />
<TitleRenderer :no="item.no" />
</li>
</ul>
</div>
Expand Down
14 changes: 12 additions & 2 deletions packages/slidev/node/virtual/titles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ export const templateTitleRendererMd: VirtualModuleTemplate = {
id: '/@slidev/title-renderer.md',
async getContent({ data }) {
const lines = data.slides
.map(({ title }, i) => `<template ${i === 0 ? 'v-if' : 'v-else-if'}="+no === ${i + 1}">\n\n${title}\n\n</template>`)
.map(({ title }, i) => `<template ${i === 0 ? 'v-if' : 'v-else-if'}="no === ${i + 1}">\n\n${title}\n\n</template>`)

lines.push(`<script setup lang="ts">defineProps<{ no: number | string }>()</script>`)
lines.push(
[
`<script setup lang="ts">`,
`import { useSlideContext } from '@slidev/client'`,
`import { computed } from 'vue'`,
`const props = defineProps<{ no?: number | string }>()`,
`const { $page } = useSlideContext()`,
`const no = computed(() => +(props.no ?? $page.value))`,
`</script>`,
].join('\n'),
)
KermanX marked this conversation as resolved.
Show resolved Hide resolved

return lines.join('\n')
},
Expand Down