62 lines
2.2 KiB
Vue
62 lines
2.2 KiB
Vue
<script setup lang="ts">
|
|
import type { Article } from '@interfaces'
|
|
import { ref, onBeforeMount, onUpdated, onMounted } from 'vue'
|
|
import { loadArticle, updateDynamicContent } from '@lib/articles'
|
|
import { useRoute, onBeforeRouteUpdate, type RouteLocation } from 'vue-router'
|
|
import { simpleDateFormat } from '@lib/dates'
|
|
import { AUTHORED, PUBLISHED_ON, SIGNATURE, TITLE, UPDATED_ON } from '@lib/config'
|
|
import { stripHTML } from '@lib/strings'
|
|
import BackHomeButton from '@components/BackHomeButton.vue'
|
|
import NotFoundView from '@views/NotFoundView.vue'
|
|
|
|
const article = ref<Article | null>(null)
|
|
const loading = ref<boolean>(true)
|
|
const route = useRoute()
|
|
|
|
async function loadPage(target: RouteLocation) {
|
|
loading.value = true
|
|
article.value = await loadArticle(target.params.pathMatch as string)
|
|
window.document.title =
|
|
stripHTML(TITLE) + ' — ' + stripHTML(article.value?.metadata.title ?? 'Not Found')
|
|
loading.value = false
|
|
await updateDynamicContent()
|
|
}
|
|
|
|
onBeforeMount(() => loadPage(route))
|
|
onBeforeRouteUpdate(loadPage)
|
|
onMounted(updateDynamicContent)
|
|
onUpdated(updateDynamicContent)
|
|
</script>
|
|
|
|
<template>
|
|
<template v-if="!loading && !article">
|
|
<NotFoundView />
|
|
</template>
|
|
<div v-if="!loading" class="article">
|
|
<template v-if="!loading && article">
|
|
<div class="article-header">
|
|
<h1 class="article-title" v-html="article.metadata.title"></h1>
|
|
<div class="article-info">
|
|
<span v-if="article.metadata.author"
|
|
><span v-html="AUTHORED"></span> <span v-html="article.metadata.author"></span> —
|
|
</span>
|
|
<span v-html="PUBLISHED_ON"></span> {{ simpleDateFormat(article.metadata.date) }}
|
|
<span v-if="article.metadata.updated"
|
|
>— <span v-html="UPDATED_ON"></span>
|
|
{{ simpleDateFormat(article.metadata.updated) }}</span
|
|
>
|
|
</div>
|
|
<img
|
|
v-if="article.metadata.thumbnail"
|
|
id="thumbnail"
|
|
:src="article.metadata.thumbnail"
|
|
alt="thumbnail"
|
|
/>
|
|
</div>
|
|
<div class="article-text" v-html="article.html"></div>
|
|
<div class="article-signature" v-html="SIGNATURE"></div>
|
|
<BackHomeButton />
|
|
</template>
|
|
</div>
|
|
</template>
|