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): rendering flash #1336

Merged
merged 14 commits into from
Jul 7, 2022
17 changes: 17 additions & 0 deletions playground/document-driven/components/content/Alert.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<div>
<div style="display: flex; align-items: center">
<div style="font-size: 64px;">
❕
</div>
<div>
<h3 style="margin: 0">
<Markdown :use="$slots.title" unwrap="p" />
</h3>
<div>
<Markdown :use="$slots.default" unwrap="p" />
</div>
</div>
</div>
</div>
</template>
14 changes: 14 additions & 0 deletions playground/document-driven/components/content/List.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script setup lang="ts">
// Utils from Nuxt Content
const { flatUnwrap } = useUnwrap()
</script>

<template>
<ul>
<li v-for="(item, index) of flatUnwrap($slots.default(), ['ul'])" :key="index">
β˜‘οΈŽ
<span><Markdown :use="() => item" unwrap="li" /></span>
</li>
</ul>
</template>
10 changes: 10 additions & 0 deletions playground/document-driven/content/10.alert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
layout: blog
---

::alert{icon="ph:circle-wavy-warning-duotone"}
#title
This is an alert
#default
This is the default content of my alert!
::
8 changes: 8 additions & 0 deletions playground/document-driven/content/9.list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
::list
- Item 1
::list{icon="ph:check-circle-light"}
- Item 1.1
- Item 1.2
::
- Item 2
::
2 changes: 1 addition & 1 deletion playground/document-driven/layouts/reversed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div>
<NuxtLoadingBar />

<NuxtPage />
<slot />

<PageNav />
</div>
Expand Down
18 changes: 18 additions & 0 deletions playground/shared/layouts/blog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<div style="max-width: 680px; margin: 0 auto">
<NuxtLoadingBar />

<PageNav />

<slot />
</div>
</template>

<style>
body, html {
margin: 0;
padding: 0;
min-height: 100vh;
min-width: 100vw;
}
</style>
2 changes: 1 addition & 1 deletion playground/shared/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<PageNav />

<NuxtPage />
<slot />
</div>
</template>

Expand Down
20 changes: 14 additions & 6 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,20 @@ export default defineNuxtModule<ModuleOptions>({
nuxt.options.pages = true

nuxt.hook('pages:extend', (pages) => {
pages.unshift({
name: 'slug',
path: '/:slug(.*)*',
file: resolveRuntimeModule('./pages/document-driven.vue'),
children: []
})
// Respect user's custom catch-all page
if (!pages.find(page => page.path === '/:slug(.*)*')) {
pages.unshift({
name: 'slug',
path: '/:slug(.*)*',
file: resolveRuntimeModule('./pages/document-driven.vue'),
children: []
})
}
})
nuxt.hook('app:resolve', (app) => {
if (app.mainComponent?.includes('@nuxt/ui-templates')) {
app.mainComponent = resolveRuntimeModule('./app.vue')
}
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of reading the mainComponent when we cannot overwrite it, check if it includes (<NuxtLayout) and warn the user to use <NuxtLayout> in the page to avoid layout shift with the document driven mode?

})
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<NuxtPage />
</template>
13 changes: 8 additions & 5 deletions src/runtime/pages/document-driven.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
import { useContent, useContentHead } from '#imports'

const { page } = useContent()
const currentPage = page.value

useContentHead(page)
</script>

<template>
<div class="document-driven-page">
<ContentRenderer v-if="page" :key="page._id" :value="page">
<template #empty="{ value }">
<DocumentDrivenEmpty :value="value" />
</template>
</ContentRenderer>
<NuxtLayout v-if="currentPage" :name="currentPage.layout || 'default'">
<ContentRenderer :key="currentPage._id" :value="currentPage">
<template #empty="{ value }">
<DocumentDrivenEmpty :value="value" />
</template>
</ContentRenderer>
</NuxtLayout>
<DocumentDrivenNotFound v-else />
</div>
</template>