Skip to content

Commit

Permalink
feat: handle titleTemplate in _dir.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Sep 14, 2022
1 parent 5f57e50 commit 3d11777
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions theme/components/AppLayout.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<script setup lang="ts">
const docus = useDocus()
const { navigation, page } = useContent()
const { navKeyFromPath } = useContentHelpers()
const titleTemplate = computed(() => {
const appTitleTemplate = docus.value.head?.titleTemplate || `%s | ${docus.value.title}`
if (page.value) {
return page.value.head?.titleTemplate || navKeyFromPath(page.value._path, 'titleTemplate', navigation.value) || appTitleTemplate
}
return appTitleTemplate
})
defineProps({
padded: {
Expand All @@ -9,13 +19,17 @@ defineProps({
})
useHead({
titleTemplate: `%s | ${docus.value.title}`,
titleTemplate: titleTemplate.value,
meta: [
{ name: 'twitter:card', content: 'summary_large_image' }
]
})
useContentHead(docus.value)
watch(titleTemplate, () => {
useHead({ titleTemplate: titleTemplate.value })
})
useContentHead(docus.value as any)
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion theme/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default defineNuxtConfig({
preload: ['json', 'js', 'ts', 'html', 'css', 'vue', 'diff', 'shell', 'markdown', 'yaml', 'bash', 'ini']
},
navigation: {
fields: ['icon']
fields: ['icon', 'titleTemplate']
}
},
colorMode: {
Expand Down

1 comment on commit 3d11777

@vercel
Copy link

@vercel vercel bot commented on 3d11777 Sep 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.