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

fix(document-driven): sync page layout #1519

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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