, "data">,
+): string => {
+ if (!post.data.createdAt) {
+ return "";
+ }
+
+ let full = `Posted on ${post.data.createdAt.toLocaleDateString("en-US", {
+ year: "numeric",
+ month: "long",
+ day: "numeric",
+ })}`;
+
+ if (post.data.lastUpdated instanceof Date) {
+ if (
+ post.data.createdAt.toLocaleDateString("en-US") !==
+ post.data.lastUpdated.toLocaleDateString("en-US")
+ ) {
+ full += ` (Edited on ${post.data.lastUpdated.toLocaleDateString("en-US", {
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ })})`;
+ }
+ }
+
+ return full;
+};
diff --git a/src/components/starlight/PageTitle.astro b/src/components/starlight/PageTitle.astro
index 49ffcff..7c08d64 100644
--- a/src/components/starlight/PageTitle.astro
+++ b/src/components/starlight/PageTitle.astro
@@ -4,22 +4,12 @@ import Default from "@astrojs/starlight/components/PageTitle.astro";
import getReadingTime from "reading-time";
-const readingTime = getReadingTime(Astro.props.entry.body);
+import { getCreatedDate } from "@components/get-posts";
-let lastUpdated: Date | undefined;
-if (typeof Astro.props.entry.data.lastUpdated === "number") {
- lastUpdated = new Date(Astro.props.entry.data.lastUpdated);
-} else if (Astro.props.entry.data.lastUpdated instanceof Date) {
- lastUpdated = Astro.props.entry.data.lastUpdated;
-}
+const readingTime = getReadingTime(Astro.props.entry.body);
-const lastUpdatedString = lastUpdated?.toLocaleDateString("en-US", {
- year: "numeric",
- month: "long",
- day: "numeric",
-});
+const createdDate = getCreatedDate(Astro.props.entry)
-// TODO: add `createdAt` time
---
@@ -29,7 +19,7 @@ const lastUpdatedString = lastUpdated?.toLocaleDateString("en-US", {
Astro.props.entry.data.template === "doc" ? (
{readingTime.text}
- {lastUpdatedString ? ` • Last updated ${lastUpdatedString}` : ""}
+ {createdDate ? ` • ${createdDate}` : ''}
) : null
}