Skip to content

Commit c325151

Browse files
committed
fix(ContentRenderer): render empty slot if body is empty
resolves #2877
1 parent f883273 commit c325151

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

playground/content/empty.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: Empty Page
3+
---

playground/pages/[...slug].vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ definePageMeta({
2424
<ContentRenderer
2525
v-if="data"
2626
:value="data"
27-
/>
27+
>
28+
<template #empty>
29+
<div>
30+
<h1>Nobody Exists</h1>
31+
</div>
32+
</template>
33+
</ContentRenderer>
2834
<h2>Surround</h2>
2935
<pre>{{ surround }}</pre>
3036
</div>

src/runtime/components/ContentRenderer.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ const body = computed(() => {
8787
return body
8888
})
8989
90+
const isEmpty = computed(() => !body.value?.children?.length)
91+
9092
const data = computed(() => {
9193
const { body, excerpt, ...data } = props.value
9294
return {
@@ -206,6 +208,7 @@ function findMappedTag(node: MDCElement, tags: Record<string, string>) {
206208

207209
<template>
208210
<MDCRenderer
211+
v-if="!isEmpty"
209212
:key="key"
210213
:body="body"
211214
:data="data"
@@ -216,4 +219,13 @@ function findMappedTag(node: MDCElement, tags: Record<string, string>) {
216219
:components="componentsMap"
217220
:data-content-id="debug ? value.id : undefined"
218221
/>
222+
<slot
223+
v-else
224+
name="empty"
225+
:body="body"
226+
:data="data"
227+
:data-content-id="debug ? value.id : undefined"
228+
>
229+
<!-- nobody -->
230+
</slot>
219231
</template>

0 commit comments

Comments
 (0)