From 8467b0e3d3df7726e3c17254e28d5c070f8408d0 Mon Sep 17 00:00:00 2001 From: ynwd <10122431+ynwd@users.noreply.github.com> Date: Sat, 5 Oct 2024 17:40:26 +0700 Subject: [PATCH] chore(blog): update meta --- modules/blog/blog.layout.tsx | 46 +++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/modules/blog/blog.layout.tsx b/modules/blog/blog.layout.tsx index e8d9308e6..dfc450e66 100644 --- a/modules/blog/blog.layout.tsx +++ b/modules/blog/blog.layout.tsx @@ -11,6 +11,36 @@ function convert(dateString: string) { const formattedString = `${monthName} ${dateNumber}, ${year}`; return formattedString; } +function formatDateToISO(date: Date): string { + // Check if the input is a valid Date object + if (!(date instanceof Date) || isNaN(date.getTime())) { + throw new Error("Invalid date"); + } + + // Get the components of the date + const year: number = date.getUTCFullYear(); + const month: string = String(date.getUTCMonth() + 1).padStart(2, "0"); // Months are zero-based + const day: string = String(date.getUTCDate()).padStart(2, "0"); + const hours: string = String(date.getUTCHours()).padStart(2, "0"); + const minutes: string = String(date.getUTCMinutes()).padStart(2, "0"); + const seconds: string = String(date.getUTCSeconds()).padStart(2, "0"); + + // Get the timezone offset in hours and minutes + const timezoneOffset: number = -date.getTimezoneOffset(); + const offsetHours: string = String(Math.floor(Math.abs(timezoneOffset) / 60)) + .padStart(2, "0"); + const offsetMinutes: string = String(Math.abs(timezoneOffset) % 60).padStart( + 2, + "0", + ); + + // Format the timezone offset + const timezoneString: string = (timezoneOffset >= 0 ? "+" : "-") + + offsetHours + offsetMinutes; + + // Construct the final formatted date string + return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}${timezoneString}`; +} function generateTags(tags: string[]) { if (!tags) { @@ -51,6 +81,7 @@ export default function ( "https://avatars.githubusercontent.com/u/10122431?v=4"; const tags = props.attrs.tags as string[]; const data = props.data; + const time = formatDateToISO(new Date(date)); return ( @@ -59,6 +90,17 @@ export default function ( + + + + +