Files
vue-journal-layer/app/components/Journal/CategoryHeader.vue

31 lines
1.5 KiB
Vue

<script setup lang="ts">
// Heading of a category page: name, description and the category's rich
// content (the pillar text), which goes through the Journal sanitizer before
// v-html. The rich content renders on page 1 only, the description on every
// page (D-41). An h1 in it becomes h2 while the category row's
// content_h1_to_h2 is on (absent counts as on), as for post bodies. The page
// payload keeps embed placeholders; expandEmbeds turns them into iframes as
// the last step, after sanitizing, and its output is never sanitized again.
import type { JournalCategory } from '../../utils/types.ts'
import { expandEmbeds } from '../../utils/embeds.ts'
import { sanitizeJournalHtml } from '../../utils/htmlGate.ts'
const props = defineProps<{ category: JournalCategory; page?: number }>()
const contentRef = ref<HTMLElement | null>(null)
const content = computed(() =>
props.page && props.page > 1 ? '' : expandEmbeds(sanitizeJournalHtml(props.category.content, { demoteH1: props.category.content_h1_to_h2 !== false })),
)
useJournalEmbedHydration(contentRef, content)
</script>
<template>
<header class="journal-category-header">
<h1 class="journal-category-header__title">
{{ category.name }}<template v-if="page && page > 1"> · {{ $t('journal.pagination.pageTitle', { page }) }}</template>
</h1>
<p v-if="category.description" class="journal-category-header__description">{{ category.description }}</p>
<div v-if="content" ref="contentRef" class="journal-category-header__content journal-post-body" v-html="content" />
</header>
</template>