- post, index, category, tag and author pages render <SeoBreadcrumbs> at the top of their content while journal.breadcrumbs is on (default); false leaves the trail to the site's layout, the BreadcrumbList data is unchanged - JournalPagination renders <SeoPagination class-prefix="journal-pagination"> with the journal's labels: the same class names, plus page 1, the last page, gap items, aria labels and head rel prev/next, with links in the CMS's pagination form - with vue-seo-layer's seo.pagination.form 'path' the module registers <listing>/<segment>/:page routes (journalPagedRoutes), and the listing pages read the page from the :page param or ?page (pageFromRoute) - the category pillar text renders on page 1 only, the description on every page; an h1 in it becomes h2 while the category row's content_h1_to_h2 is on (absent counts as on)
101 lines
4.2 KiB
Vue
101 lines
4.2 KiB
Vue
<script setup lang="ts">
|
|
// journal-post: one published post by slug. An unknown, draft or future post
|
|
// is a real 404. The transform sanitizes the body before it reaches the payload.
|
|
// Related posts fall back to the latest posts when the API has none (it
|
|
// returns none for a post without a category).
|
|
//
|
|
// One H1 per page in both Journal H1 modes (UI-SPEC L6): while the Journal
|
|
// API reports content_h1_to_h2 on (or leaves it out), the title is the h1 and
|
|
// the body's h1 headings become h2; while it is off, the title is a
|
|
// p.journal-post__title (same class, same look) and the body's own h1 is the
|
|
// page's H1. journal.postTitleTag 'h1' or 'p' forces the title's element.
|
|
//
|
|
// The head comes from the CMS through vue-seo-layer; the post's own title,
|
|
// excerpt and featured image apply only while there is no CMS answer.
|
|
import { cmsHeadPresent, journalPostTitleTag, journalSiteOrigin, postSeoMeta } from '../utils/seo.ts'
|
|
import { demotesH1, toPostView } from '../utils/postView.ts'
|
|
import { journalBreadcrumbsOn, toListPost } from '../utils/view.ts'
|
|
import type { JournalModuleOptions } from '../utils/types.ts'
|
|
|
|
const route = useRoute()
|
|
const api = useJournalApi()
|
|
const links = useJournalLinks()
|
|
const cfg = useRuntimeConfig().public.journal as JournalModuleOptions
|
|
const slug = computed(() => String(route.params.slug ?? ''))
|
|
|
|
const { data: post, error } = await useAsyncData(
|
|
() => `journal-post-${slug.value}`,
|
|
async () => {
|
|
const found = await api.getPost(slug.value)
|
|
if (!found) return null
|
|
const count = Math.max(0, cfg.relatedCount)
|
|
let related = found.related_posts ?? []
|
|
if (related.length === 0 && count > 0) {
|
|
const latest = await api.listPosts({ perPage: count + 1, sort: cfg.sort })
|
|
related = latest.data.filter((p) => p.slug !== found.slug)
|
|
}
|
|
return { ...found, related_posts: related.slice(0, count).map(toListPost) }
|
|
},
|
|
{ transform: (p) => (p ? toPostView(p) : null) },
|
|
)
|
|
|
|
if (error.value) {
|
|
throw createError({ statusCode: (error.value as { statusCode?: number }).statusCode ?? 500, fatal: true })
|
|
}
|
|
if (!post.value) {
|
|
throw createError({ statusCode: 404, statusMessage: 'Post not found', fatal: true })
|
|
}
|
|
|
|
const answer = useSeoAnswer()
|
|
const requestOrigin = useRequestURL().origin
|
|
const fallback = computed(() =>
|
|
post.value && !cmsHeadPresent(answer.value) ? postSeoMeta(post.value, journalSiteOrigin(answer.value?.url, requestOrigin)) : null,
|
|
)
|
|
useSeoMeta({
|
|
title: () => fallback.value?.title,
|
|
ogTitle: () => fallback.value?.ogTitle,
|
|
description: () => fallback.value?.description,
|
|
ogDescription: () => fallback.value?.ogDescription,
|
|
ogType: () => fallback.value?.ogType,
|
|
ogImage: () => fallback.value?.ogImage,
|
|
articlePublishedTime: () => fallback.value?.articlePublishedTime,
|
|
articleModifiedTime: () => fallback.value?.articleModifiedTime,
|
|
})
|
|
|
|
const titleTag = computed(() => journalPostTitleTag(cfg.postTitleTag, post.value?.content_h1_to_h2))
|
|
const demoteH1 = computed(() => demotesH1(post.value))
|
|
const crumbs = journalBreadcrumbsOn(cfg.breadcrumbs)
|
|
</script>
|
|
|
|
<template>
|
|
<article v-if="post" class="journal-post">
|
|
<SeoBreadcrumbs v-if="crumbs" />
|
|
<header class="journal-post__header">
|
|
<component :is="titleTag" class="journal-post__title">{{ post.title }}</component>
|
|
<JournalPostMeta :post="post" />
|
|
</header>
|
|
<JournalFeaturedImage :src="post.featured_image_url" :alt="post.title" eager />
|
|
<JournalPostBody :html="post.content_html" :demote-h1="demoteH1" />
|
|
<nav v-if="post.previous_post || post.next_post" class="journal-post__siblings">
|
|
<NuxtLink
|
|
v-if="post.previous_post && links.postLink(post.previous_post.slug)"
|
|
:to="links.postLink(post.previous_post.slug)!"
|
|
rel="prev"
|
|
class="journal-post__previous"
|
|
>
|
|
<span>{{ $t('journal.post.previous') }}</span> {{ post.previous_post.title }}
|
|
</NuxtLink>
|
|
<NuxtLink
|
|
v-if="post.next_post && links.postLink(post.next_post.slug)"
|
|
:to="links.postLink(post.next_post.slug)!"
|
|
rel="next"
|
|
class="journal-post__next"
|
|
>
|
|
<span>{{ $t('journal.post.next') }}</span> {{ post.next_post.title }}
|
|
</NuxtLink>
|
|
</nav>
|
|
<JournalRelatedPosts :posts="post.related_posts" />
|
|
<JournalRssLink />
|
|
</article>
|
|
</template>
|