webapp/src/pages/[...slug].astro

25 lines
715 B
Plaintext
Raw Normal View History

2022-09-09 11:53:35 +00:00
---
2022-09-22 09:37:49 +00:00
import { Root } from '../components/Root'
2022-09-09 11:53:35 +00:00
import Zine from '../layouts/zine.astro'
import { apiClient } from '../utils/apiClient'
2022-09-23 18:27:05 +00:00
import { initRouter } from '../stores/router'
2022-09-14 15:44:06 +00:00
2022-10-04 09:26:47 +00:00
const slug = Astro.params.slug?.toString()
2022-10-05 11:16:28 +00:00
const routepaths = ['craete', 'search', 'inbox', 'topics', 'authors', 'robots.txt']
if (routepaths.includes(slug) || Boolean(slug) === false || slug.includes('.map')) return
2022-09-13 09:59:04 +00:00
const article = await apiClient.getArticle({ slug })
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')
2022-09-09 11:53:35 +00:00
---
<Zine>
2022-09-22 09:37:49 +00:00
<Root article={article} client:load />
2022-09-09 11:53:35 +00:00
</Zine>