Skip to content

Commit

Permalink
Fix date rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielPower committed Dec 21, 2024
1 parent 24889ba commit 0695c31
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 59 deletions.
4 changes: 0 additions & 4 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// @ts-check
import { defineConfig } from "astro/config";
import mdx from "@astrojs/mdx";
import sitemap from "@astrojs/sitemap";

import icon from "astro-icon";

import node from "@astrojs/node";

// https://astro.build/config
export default defineConfig({
site: "https://danielpower.ca",
integrations: [mdx(), sitemap(), icon()],
Expand Down
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"@astrojs/sitemap": "^3.2.1",
"@iconify-json/mdi": "^1.2.2",
"astro": "^5.1.0",
"astro-icon": "^1.1.4"
"astro-icon": "^1.1.4",
"date-fns": "^4.1.0"
},
"devDependencies": {
"prettier": "^3.4.2",
Expand Down
41 changes: 0 additions & 41 deletions src/layouts/BlogPost.astro

This file was deleted.

61 changes: 49 additions & 12 deletions src/pages/blog/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
---
import { type CollectionEntry, getCollection } from 'astro:content';
import BlogPost from '../../layouts/BlogPost.astro';
import { render } from 'astro:content';
import { type CollectionEntry, getCollection } from "astro:content";
import Layout from "../../layouts/Layout.astro";
import { render } from "astro:content";
import { format } from "date-fns";
export async function getStaticPaths() {
const posts = await getCollection('blog');
return posts.map((post) => ({
params: { slug: post.id },
props: post,
}));
const posts = await getCollection("blog");
return posts.map((post) => ({
params: { slug: post.id },
props: post,
}));
}
type Props = CollectionEntry<'blog'>;
type Props = CollectionEntry<"blog">;
const post = Astro.props;
const { Content } = await render(post);
---

<BlogPost {...post.data}>
<Content />
</BlogPost>
<Layout>
<article>
<div class="post-heading">
<h1>{post.data.title}</h1>
<div>
{
post.data.date ? (
<p>Published on {format(post.data.date, "yyyy-mm-dd")}</p>
) : null
}
</div>
</div>
<div class="post-body">
<Content />
</div>
</article>

<style>
.post-heading {
display: flex;
flex-direction: column;
align-items: center;
margin: 0 auto;
}

.post-body {
margin-top: 1rem;
}
.post-body :global(h2) {
margin-top: 1.5rem;
}
.post-body :global(h3) {
margin-top: 1rem;
}
.post-body :global(figure) {
margin-top: 1rem;
}
</style>
</Layout>

0 comments on commit 0695c31

Please sign in to comment.