From 37951dcf56d46f6e7a0481c7d23e6aad1e8624fc Mon Sep 17 00:00:00 2001
From: Cassidy Williams <1454517+cassidoo@users.noreply.github.com>
Date: Sun, 31 Dec 2023 00:26:04 -0600
Subject: [PATCH] Fix date formatting, add tags to blog header
---
src/components/Tags.astro | 8 ++++----
src/layouts/BlogPost.astro | 29 +++++++++++++++++++++++++----
src/pages/index.astro | 5 ++++-
src/pages/post/[slug].astro | 29 ++---------------------------
src/style/global.css | 2 +-
5 files changed, 36 insertions(+), 37 deletions(-)
diff --git a/src/components/Tags.astro b/src/components/Tags.astro
index f301a5d..b29462a 100644
--- a/src/components/Tags.astro
+++ b/src/components/Tags.astro
@@ -1,9 +1,9 @@
---
-const { tags } = Astro.props;
+const { tags, all } = Astro.props;
---
-
View posts by tag
-
+{all &&
View posts by tag
}
+
{
tags &&
tags.map((tag) => (
@@ -15,4 +15,4 @@ const { tags } = Astro.props;
>
))
}
-
+
diff --git a/src/layouts/BlogPost.astro b/src/layouts/BlogPost.astro
index f6e2eb7..6753227 100644
--- a/src/layouts/BlogPost.astro
+++ b/src/layouts/BlogPost.astro
@@ -7,11 +7,31 @@ import Tags from "../components/Tags.astro";
import getTags from "../scripts/getTags";
const posts = await Astro.glob("../posts/*.md");
-const tags = getTags(posts);
+const allTags = getTags(posts);
-const {
- content: { title, description, added, updated, heroImage },
+let {
+ content: { title, description, added, updated, tags, heroImage },
} = Astro.props;
+
+added = new Date(added).toLocaleDateString(
+ "en-us",
+ {
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ }
+);
+
+if (updated) {
+ updated = new Date(updated).toLocaleDateString(
+ "en-us",
+ {
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ }
+ );
+}
---
@@ -28,13 +48,14 @@ const {
:
{added && }
}
+
-
+
diff --git a/src/pages/index.astro b/src/pages/index.astro
index c2fdf15..1b4ab10 100644
--- a/src/pages/index.astro
+++ b/src/pages/index.astro
@@ -22,10 +22,13 @@ const tags = getTags(posts);
+
+
Here's my most recent posts
+
-
+
diff --git a/src/pages/post/[slug].astro b/src/pages/post/[slug].astro
index db25f7d..4479a2d 100644
--- a/src/pages/post/[slug].astro
+++ b/src/pages/post/[slug].astro
@@ -12,33 +12,8 @@ export async function getStaticPaths() {
}
const { post } = Astro.props;
-
-post.frontmatter.added = new Date(post.frontmatter.added).toLocaleDateString(
- "en-us",
- {
- year: "numeric",
- month: "short",
- day: "numeric",
- }
-);
-
-if (post.frontmatter.updated === "Invalid Date") {
- post.frontmatter.updated = null;
-} else {
- post.frontmatter.updated = new Date(post.frontmatter.updated).toLocaleDateString(
- "en-us",
- {
- year: "numeric",
- month: "short",
- day: "numeric",
- }
- );
-}
-
-const {
- Content,
- frontmatter: { title, added, updated, tags, excerpt },
-} = post;
+const { Content } = post;
---
+
diff --git a/src/style/global.css b/src/style/global.css
index 4d66d90..de70773 100644
--- a/src/style/global.css
+++ b/src/style/global.css
@@ -222,7 +222,7 @@ article :not(.article-title) {
.article-title {
font-size: 2em;
- margin: 0.25em 0 0;
+ margin: 0.25em 0;
}
.blog-post {