Skip to content

Commit

Permalink
fix(document-driven): sync page layout (#1519)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Sep 15, 2022
1 parent b4e9591 commit 2813d35
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions playground/document-driven/content/_theme.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test: 'Hello World'
layout: debug
19 changes: 19 additions & 0 deletions playground/document-driven/layouts/debug.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script setup>
const { layout } = useContent()
</script>
<template>
<div>
<PageNav />
<pre>Layout: {{ layout }}</pre>
<slot />
</div>
</template>

<style>
body, html {
margin: 0;
padding: 0;
min-height: 100vh;
min-width: 100vw;
}
</style>
3 changes: 2 additions & 1 deletion playground/document-driven/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default defineNuxtConfig({
},
without: ['_']
}
}
},
layoutFallbacks: ['theme']
}
}
})
16 changes: 4 additions & 12 deletions src/runtime/composables/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,12 @@ export const useContent = () => {
/**
* Current `page` key, computed from path and content state.
*/
const page = computed(
() => {
return pages.value[_path.value]
}
)
const page = computed(() => pages.value[_path.value])

/**
* Current `surround` key, computed from path and content state.
*/
const surround = computed(
() => {
return surrounds.value[_path.value]
}
)
const surround = computed(() => surrounds.value[_path.value])

/**
* Table of contents from `page`.
Expand All @@ -64,7 +56,7 @@ export const useContent = () => {
/**
* Content type from `page`.
*/
const type = computed(() => page.value?.meta?.type)
const type = computed(() => page.value?.type)

/**
* Excerpt from `page`.
Expand All @@ -74,7 +66,7 @@ export const useContent = () => {
/**
* Layout type from `page`.
*/
const layout = computed(() => page.value?.meta?.layout)
const layout = computed(() => page.value?.layout)

/**
* Next page from `surround`.
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/pages/document-driven.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useContent, useContentHead, useRequestEvent } from '#imports'
const { page } = useContent()
const { page, layout } = useContent()
// Page not found, set correct status code on SSR
if (!page.value && process.server) {
Expand All @@ -14,7 +14,7 @@ useContentHead(page)

<template>
<div class="document-driven-page">
<NuxtLayout :name="page?.layout || 'default'">
<NuxtLayout :name="layout || 'default'">
<ContentRenderer v-if="page" :key="page._id" :value="page">
<template #empty="{ value }">
<DocumentDrivenEmpty :value="value" />
Expand Down
1 change: 1 addition & 0 deletions src/runtime/plugins/documentDriven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export default defineNuxtPlugin((nuxt) => {
}
// Apply layout
to.meta.layout = layoutName
_page.layout = layoutName

// Update values
pages.value[_path] = _page
Expand Down

0 comments on commit 2813d35

Please sign in to comment.