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";
export const remarkModifiedTime = () => {
return (tree, file) => {
return (file) => {
const filepath = file.history[0];
const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`);
file.data.astro.frontmatter.lastModified = result.toString();
};
};
}

View File

@@ -1,17 +1,29 @@
---
interface Props {
date: Date;
date: Date | string;
}
const { date } = Astro.props;
---
<time datetime={date.toISOString()}>
{
date.toLocaleString("en-us", {
const isStringDate = typeof date === "string";
const transformedDate = isStringDate ? new Date(date) : date;
// Create the base options object
const localeOptions = {
year: "numeric",
month: "long",
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>

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).
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.
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.