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: documentDriven configuration #1378

Merged
merged 4 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions playground/document-driven/pages/home.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script setup>
definePageMeta({
documentDriven: {
page: '/'
}
})

const { page } = useContent()
useContentHead(page)
</script>

<template>
<NuxtLayout name="reversed">
<ContentRenderer :value="page" />
</NuxtLayout>
</template>
18 changes: 16 additions & 2 deletions src/runtime/plugins/documentDriven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ export default defineNuxtPlugin((nuxt) => {
* `page`
*/
if (moduleOptions.page && routeConfig.page !== false) {
let where = { _path }
if (typeof routeConfig.page === 'string') {
where = { _path: routeConfig.page }
}
if (typeof routeConfig.page === 'object') {
where = routeConfig.page
}
const pageQuery = () => {
const { pages } = useContentState()

Expand All @@ -147,7 +154,7 @@ export default defineNuxtPlugin((nuxt) => {
}

return queryContent()
.where({ _path })
.where(where)
.findOne()
.catch(() => {
// eslint-disable-next-line no-console
Expand All @@ -164,6 +171,13 @@ export default defineNuxtPlugin((nuxt) => {
* `surround`
*/
if (moduleOptions.surround && routeConfig.surround !== false) {
let surround: any = _path
if (['string', 'object'].includes(typeof routeConfig.page)) {
surround = { _path: routeConfig.page }
}
if (['string', 'object'].includes(typeof routeConfig.surround)) {
surround = routeConfig.surround
}
const surroundQuery = () => {
const { surrounds } = useContentState()

Expand All @@ -179,7 +193,7 @@ export default defineNuxtPlugin((nuxt) => {
})
// Exclude `body` for `surround`
.without(['body'])
.findSurround(_path)
.findSurround(surround)
.catch(() => {
// eslint-disable-next-line no-console
// console.log(`Could not find surrounding pages for: ${to.path}`)
Expand Down