Fix Date component for string from remark

This commit is contained in:
thiloho
2025-04-26 09:43:01 +02:00
parent 69be9d8ab7
commit f8e71fc3b6
3 changed files with 26 additions and 12 deletions

View File

@@ -1,9 +1,9 @@
import { execSync } from "child_process"; import { execSync } from "child_process";
export const remarkModifiedTime = () => { export const remarkModifiedTime = () => {
return (tree, file) => { return (file) => {
const filepath = file.history[0]; const filepath = file.history[0];
const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`); const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`);
file.data.astro.frontmatter.lastModified = result.toString(); file.data.astro.frontmatter.lastModified = result.toString();
}; };
}; }

View File

@@ -1,17 +1,29 @@
--- ---
interface Props { interface Props {
date: Date; date: Date | string;
} }
const { date } = Astro.props; const { date } = Astro.props;
---
<time datetime={date.toISOString()}> const isStringDate = typeof date === "string";
{ const transformedDate = isStringDate ? new Date(date) : date;
date.toLocaleString("en-us", {
// Create the base options object
const localeOptions = {
year: "numeric", year: "numeric",
month: "long", month: "long",
day: "numeric", day: "numeric",
}) };
// Conditionally add time options if it's a string date
if (isStringDate) {
Object.assign(localeOptions, {
hour: "2-digit",
minute: "2-digit"
});
} }
---
<time datetime={transformedDate.toISOString()}>
{transformedDate.toLocaleString("en-us", localeOptions)}
</time> </time>

View File

@@ -28,6 +28,8 @@ There are other great options, such as [FreeBSD](https://www.freebsd.org) and [O
Your main choice here should probably be [GrapheneOS](https://grapheneos.org). Your main choice here should probably be [GrapheneOS](https://grapheneos.org).
Wikipedia states the following:
> GrapheneOS is an open source, privacy and security-focused Android operating system that runs on selected Google Pixel devices, including smartphones, tablets and foldables. > GrapheneOS is an open source, privacy and security-focused Android operating system that runs on selected Google Pixel devices, including smartphones, tablets and foldables.
As mentioned in the quote, note that you need a [supported Google Pixel device](https://grapheneos.org/faq#supported-devices) to use GrapheneOS and I would not recommend using any other privacy focused or hardened mobile operating system as they do not come close to its usability while maintaining these aspects. As mentioned in the quote, note that you need a [supported Google Pixel device](https://grapheneos.org/faq#supported-devices) to use GrapheneOS and I would not recommend using any other privacy focused or hardened mobile operating system as they do not come close to its usability while maintaining these aspects.