Files

200 lines
7.3 KiB
Vue
Raw Permalink Normal View History

2026-04-29 23:06:11 -05:00
<script lang="ts" setup>
2026-09-10 00:45:36 -05:00
import { contentDateAttr, formatContentDate } from '~/utils/dates';
2026-07-30 09:21:34 -05:00
import {
DEFAULT_IMAGE,
SITE_NAME,
SITE_URL,
personId,
websiteId,
} from '~/utils/site';
2026-04-29 23:06:11 -05:00
const route = useRoute();
2026-07-30 09:21:34 -05:00
const articleUrl = `${SITE_URL}${route.path}`;
2026-06-28 18:50:53 -05:00
const webpageId = `${articleUrl}#webpage`;
const articleId = `${articleUrl}#article`;
2026-07-30 09:21:34 -05:00
const blogId = `${SITE_URL}/writing#blog`;
2026-08-22 12:43:00 -05:00
const slug = computed(() =>
Array.isArray(route.params.slug)
2026-08-22 11:59:33 -05:00
? route.params.slug.join('/')
2026-08-22 12:43:00 -05:00
: String(route.params.slug ?? ''),
);
const contentPath = computed(() => '/' + slug.value);
const folderName = computed(
() => slug.value.split('/').filter(Boolean).at(-1) ?? slug.value,
);
2026-08-22 11:59:33 -05:00
2026-08-22 12:43:00 -05:00
const { data } = await useAsyncData(
() => `writing:${route.path}`,
async () => {
const all = await queryCollection('writing').order('date', 'DESC').all();
2026-08-23 09:25:52 -05:00
const visible = all.filter((page) => import.meta.dev || !page.hidden);
2026-08-22 12:43:00 -05:00
const article = visible.find(
(page) =>
page.path === contentPath.value || page.stem === slug.value,
);
if (article) {
return { kind: 'article' as const, article, pages: [] };
}
const prefix = contentPath.value.endsWith('/')
? contentPath.value
: `${contentPath.value}/`;
const pages = visible.filter((page) => page.path.startsWith(prefix));
2026-04-29 23:06:11 -05:00
2026-08-22 12:43:00 -05:00
if (!pages.length) return null;
return { kind: 'folder' as const, article: null, pages };
},
{ watch: [() => route.path] },
);
if (!data.value) {
2026-04-29 23:06:11 -05:00
throw createError({ statusCode: 404, statusMessage: 'Page Not Found' });
}
2026-08-22 12:43:00 -05:00
const page = computed(() => data.value?.article ?? null);
const isFolder = computed(() => data.value?.kind === 'folder');
const articleTitle = page.value?.title ?? folderName.value;
2026-08-23 22:29:13 -05:00
const articleDescription = page.value
? page.value.description
: `Writing from ${folderName.value}`;
const layoutDescription = page.value
2026-09-10 00:45:36 -05:00
? formatContentDate(page.value.date, 'long')
2026-08-23 22:29:13 -05:00
: articleDescription;
2026-07-30 09:21:34 -05:00
2026-04-29 23:06:11 -05:00
useSeoMeta({
2026-07-30 09:21:34 -05:00
title: articleTitle,
ogTitle: articleTitle,
2026-08-23 22:29:13 -05:00
description: articleDescription,
ogDescription: articleDescription,
2026-07-30 09:21:34 -05:00
ogUrl: articleUrl,
2026-08-22 12:43:00 -05:00
ogType: isFolder.value ? 'website' : 'article',
2026-07-30 09:21:34 -05:00
ogImage: DEFAULT_IMAGE,
ogImageAlt: articleTitle,
twitterCard: 'summary',
twitterTitle: articleTitle,
2026-08-23 22:29:13 -05:00
twitterDescription: articleDescription,
2026-07-30 09:21:34 -05:00
twitterImage: DEFAULT_IMAGE,
2026-08-22 12:43:00 -05:00
articlePublishedTime: page.value
2026-09-10 00:45:36 -05:00
? contentDateAttr(page.value.date)
2026-08-22 12:43:00 -05:00
: undefined,
articleModifiedTime: page.value
2026-09-10 00:45:36 -05:00
? contentDateAttr(page.value.date)
2026-08-22 12:43:00 -05:00
: undefined,
articleAuthor: page.value ? [SITE_NAME] : undefined,
2026-04-29 23:06:11 -05:00
});
2026-06-22 00:44:50 -05:00
useHead({
2026-07-30 09:21:34 -05:00
link: [{ rel: 'canonical', href: articleUrl }],
2026-08-22 12:43:00 -05:00
script: page.value
? [
{
key: 'json-ld-article',
type: 'application/ld+json',
innerHTML: JSON.stringify({
'@context': 'https://schema.org',
'@graph': [
{
'@type': 'WebPage',
'@id': webpageId,
url: articleUrl,
name: articleTitle,
description: articleDescription,
inLanguage: 'en-US',
isPartOf: { '@id': websiteId },
breadcrumb: { '@id': `${articleUrl}#breadcrumb` },
mainEntity: { '@id': articleId },
},
{
'@type': 'Blog',
'@id': blogId,
url: `${SITE_URL}/writing`,
name: 'Jaron Pate Writing',
inLanguage: 'en-US',
isPartOf: { '@id': websiteId },
publisher: {
'@type': 'Person',
'@id': personId,
name: SITE_NAME,
},
},
{
'@type': 'BlogPosting',
'@id': articleId,
url: articleUrl,
headline: articleTitle,
description: articleDescription,
2026-09-10 00:45:36 -05:00
datePublished: contentDateAttr(page.value.date),
dateModified: contentDateAttr(page.value.date),
2026-08-22 12:43:00 -05:00
image: {
'@type': 'ImageObject',
'@id': `${articleUrl}#article-image`,
url: DEFAULT_IMAGE,
},
inLanguage: 'en-US',
isPartOf: { '@id': blogId },
mainEntityOfPage: { '@id': webpageId },
author: {
'@type': 'Person',
'@id': personId,
name: SITE_NAME,
url: SITE_URL,
},
publisher: {
'@type': 'Person',
'@id': personId,
name: SITE_NAME,
},
},
{
'@type': 'BreadcrumbList',
'@id': `${articleUrl}#breadcrumb`,
itemListElement: [
{
'@type': 'ListItem',
position: 1,
name: 'Home',
item: SITE_URL,
},
{
'@type': 'ListItem',
position: 2,
name: 'Writing',
item: `${SITE_URL}/writing`,
},
{
'@type': 'ListItem',
position: 3,
name: articleTitle,
item: articleUrl,
},
],
},
],
}),
},
]
: [],
2026-06-22 00:44:50 -05:00
});
2026-04-29 23:06:11 -05:00
</script>
<template>
2026-08-22 11:59:33 -05:00
<NuxtLayout
name="main"
2026-08-22 12:43:00 -05:00
:title="page ? page.title : folderName"
2026-08-23 22:29:13 -05:00
:description="layoutDescription"
2026-08-22 11:59:33 -05:00
>
<article v-if="page">
<div class="article-body">
<p v-if="page.description">
<strong>{{ page.description }}</strong>
</p>
<ContentRenderer :value="page" />
</div>
</article>
2026-08-22 12:43:00 -05:00
<article v-else>
<WritingList :pages="data?.pages ?? []" />
</article>
2026-08-22 11:59:33 -05:00
</NuxtLayout>
2026-04-29 23:06:11 -05:00
</template>