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

refactor(ContentRenderer): simplify conditions #1715

Merged
merged 3 commits into from
Nov 30, 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
4 changes: 2 additions & 2 deletions src/runtime/components/ContentRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default defineComponent({

const { value, excerpt, tag } = ctx

if ((!value || !value?.body?.children?.length) && slots?.empty) {
if (!value?.body?.children?.length && slots?.empty) {
// Fallback on `empty` slot.
return slots.empty({ value, excerpt, tag, ...this.$attrs })
}
Expand All @@ -70,7 +70,7 @@ export default defineComponent({
}

// Use built-in ContentRendererMarkdown
if (value && value?._type === 'markdown' && value?.body?.children?.length) {
if (value?._type === 'markdown' && value?.body?.children?.length) {
return h(
ContentRendererMarkdown,
{
Expand Down
3 changes: 2 additions & 1 deletion test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ describe('Basic usage', async () => {

test('Empty slot', async () => {
const html = await $fetch('/features/empty-slot')
expect(html).contains('Empty!!!')
expect(html).contains('Nullish Document!!!')
expect(html).contains('Empty Child!!!')
})

test('<ContentDoc> head management (if same path)', async () => {
Expand Down
3 changes: 2 additions & 1 deletion test/custom-api-base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ describe('Custom api baseURL', async () => {

test('Empty slot', async () => {
const html = await $fetch('/features/empty-slot')
expect(html).contains('Empty!!!')
expect(html).contains('Nullish Document!!!')
expect(html).contains('Empty Child!!!')
})

test('<ContentDoc> head management (if same path)', async () => {
Expand Down
22 changes: 16 additions & 6 deletions test/fixtures/basic/pages/features/empty-slot.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<template>
<ContentRenderer :value="emptyDocument">
<template #empty>
Empty!!!
</template>
</ContentRenderer>
<div>
<ContentRenderer :value="nullishDocument">
<template #empty>
Nullish Document!!!
</template>
</ContentRenderer>

<ContentRenderer :value="emptyChild">
<template #empty>
Empty Child!!!
</template>
</ContentRenderer>
</div>
</template>

<script setup>
const emptyDocument = {
const nullishDocument = null

const emptyChild = {
_path: '/_markdown',
_dir: '',
_draft: false,
Expand Down