2022-09-09 11:53:35 +00:00
|
|
|
---
|
2022-09-22 09:37:49 +00:00
|
|
|
import { Root } from '../components/Root'
|
2022-11-13 09:25:31 +00:00
|
|
|
import Prerendered from '../main.astro'
|
2022-09-09 11:53:35 +00:00
|
|
|
import { apiClient } from '../utils/apiClient'
|
2022-09-23 18:27:05 +00:00
|
|
|
import { initRouter } from '../stores/router'
|
2023-01-30 10:39:36 +00:00
|
|
|
import {getDescription} from '../utils/meta'
|
2022-09-14 15:44:06 +00:00
|
|
|
|
2023-01-03 06:13:01 +00:00
|
|
|
|
2022-10-04 09:26:47 +00:00
|
|
|
const slug = Astro.params.slug?.toString()
|
2023-01-30 10:39:36 +00:00
|
|
|
if (slug.includes('.')) {
|
2022-10-09 10:29:35 +00:00
|
|
|
return Astro.redirect('/404')
|
2022-10-05 11:42:13 +00:00
|
|
|
}
|
2022-09-13 09:59:04 +00:00
|
|
|
|
2022-11-18 02:23:04 +00:00
|
|
|
const article = await apiClient.getShout(slug)
|
2022-09-13 09:59:04 +00:00
|
|
|
if (!article) {
|
|
|
|
return Astro.redirect('/404')
|
2022-09-09 11:53:35 +00:00
|
|
|
}
|
2022-09-13 09:59:04 +00:00
|
|
|
|
2022-09-23 18:27:05 +00:00
|
|
|
const { pathname, search } = Astro.url
|
|
|
|
initRouter(pathname, search)
|
|
|
|
|
2022-09-13 09:59:04 +00:00
|
|
|
Astro.response.headers.set('Cache-Control', 's-maxage=1, stale-while-revalidate')
|
2023-01-30 10:39:36 +00:00
|
|
|
|
|
|
|
const title = article.title
|
|
|
|
const imageUrl = article.cover ?? ''
|
|
|
|
const description = article.body ? getDescription(article.body) : ''
|
2022-09-09 11:53:35 +00:00
|
|
|
---
|
|
|
|
|
2023-01-30 10:39:36 +00:00
|
|
|
<Prerendered
|
|
|
|
title={title}
|
|
|
|
imageUrl={imageUrl}
|
|
|
|
description={description}
|
|
|
|
>
|
2022-11-18 02:23:04 +00:00
|
|
|
<Root article={article} client:load />
|
2022-11-13 09:25:31 +00:00
|
|
|
</Prerendered>
|