36 lines
856 B
Plaintext
36 lines
856 B
Plaintext
---
|
|
import { Root } from '../components/Root'
|
|
import Prerendered from '../main.astro'
|
|
import { apiClient } from '../utils/apiClient'
|
|
import { initRouter } from '../stores/router'
|
|
import {getDescription} from '../utils/meta'
|
|
|
|
|
|
const slug = Astro.params.slug?.toString()
|
|
if (slug.includes('.')) {
|
|
return Astro.redirect('/404')
|
|
}
|
|
|
|
const article = await apiClient.getShout(slug)
|
|
if (!article) {
|
|
return Astro.redirect('/404')
|
|
}
|
|
|
|
const { pathname, search } = Astro.url
|
|
initRouter(pathname, search)
|
|
|
|
Astro.response.headers.set('Cache-Control', 's-maxage=1, stale-while-revalidate')
|
|
|
|
const title = article.title
|
|
const imageUrl = article.cover ?? ''
|
|
const description = article.body ? getDescription(article.body) : ''
|
|
---
|
|
|
|
<Prerendered
|
|
title={title}
|
|
imageUrl={imageUrl}
|
|
description={description}
|
|
>
|
|
<Root article={article} client:load />
|
|
</Prerendered>
|