toastie-site/src/pages/blog/[...slug].astro
2024-11-27 10:10:42 +13:00

129 lines
1.7 KiB
Text

---
import { getCollection } from "astro:content";
export const prerender = true;
export async function getStaticPaths() {
return (await getCollection("blog")).map(({ slug }) => ({
params: { slug },
}));
}
const { slug } = Astro.params;
if (slug === undefined) {
throw new Error("slug is missing");
}
const posts = (await getCollection("blog")).sort(
(blogEntryA, blogEntryB) =>
(blogEntryB.data.pubDate || new Date()).getTime() -
(blogEntryA.data.pubDate || new Date()).getTime()
);
const entry = posts.find((entry) => entry.slug === slug);
if (entry === undefined) {
return Astro.redirect("/404");
}
const { Content } = await entry.render();
---
<Content />
<style is:global>
h1,
h2,
h3,
h4,
h5,
h6 {
margin-top: 20px;
margin-bottom: 10px;
font-weight: bold;
}
h1 {
font-size: 32px;
}
h2 {
font-size: 28px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 20px;
}
h5 {
font-size: 18px;
}
h6 {
font-size: 16px;
}
p {
margin: 0 0 10px 0;
}
a {
color: #1a0dab;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
ul,
ol {
margin-left: 20px;
margin-bottom: 10px;
}
blockquote {
margin: 20px 0;
padding-left: 15px;
border-left: 5px solid #ccc;
}
pre,
code {
font-family: "Courier New", monospace;
background-color: #f4f4f4;
border-radius: 5px;
}
pre {
padding: 10px;
overflow-x: auto;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #d63384;
}
img {
max-width: 100%;
height: auto;
}
table {
border-collapse: collapse;
width: 100%;
}
th,
td {
text-align: left;
padding: 8px;
border-bottom: 1px solid #ddd;
}
</style>