mirror of
https://github.com/jaronpate/folio.git
synced 2026-10-18 17:06:56 +00:00
fix date off by one
This commit is contained in:
@@ -1,20 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { contentDateAttr, formatContentDate } from '~/utils/dates';
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
pages: Array<{
|
pages: Array<{
|
||||||
path: string;
|
path: string;
|
||||||
title: string;
|
title: string;
|
||||||
date: string | Date;
|
date: string;
|
||||||
}>;
|
}>;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const formatDate = (dateString: string | Date) => {
|
|
||||||
return new Date(dateString).toLocaleDateString('en-US', {
|
|
||||||
month: 'short',
|
|
||||||
day: 'numeric',
|
|
||||||
year: 'numeric',
|
|
||||||
timeZone: 'UTC',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -27,8 +20,8 @@ const formatDate = (dateString: string | Date) => {
|
|||||||
>
|
>
|
||||||
<span class="listing__title">{{ page.title }}</span>
|
<span class="listing__title">{{ page.title }}</span>
|
||||||
<span class="listing__rule" aria-hidden="true"></span>
|
<span class="listing__rule" aria-hidden="true"></span>
|
||||||
<time :datetime="new Date(page.date).toISOString()">{{
|
<time :datetime="contentDateAttr(page.date)">{{
|
||||||
formatDate(page.date)
|
formatContentDate(page.date)
|
||||||
}}</time>
|
}}</time>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { contentDateAttr, formatContentDate } from '~/utils/dates';
|
||||||
import {
|
import {
|
||||||
DEFAULT_IMAGE,
|
DEFAULT_IMAGE,
|
||||||
SITE_NAME,
|
SITE_NAME,
|
||||||
@@ -54,19 +55,11 @@ if (!data.value) {
|
|||||||
const page = computed(() => data.value?.article ?? null);
|
const page = computed(() => data.value?.article ?? null);
|
||||||
const isFolder = computed(() => data.value?.kind === 'folder');
|
const isFolder = computed(() => data.value?.kind === 'folder');
|
||||||
const articleTitle = page.value?.title ?? folderName.value;
|
const articleTitle = page.value?.title ?? folderName.value;
|
||||||
const formatDate = (date: Date | string) => {
|
|
||||||
return new Date(date).toLocaleDateString('en-US', {
|
|
||||||
month: 'long',
|
|
||||||
day: 'numeric',
|
|
||||||
year: 'numeric',
|
|
||||||
timeZone: 'UTC',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const articleDescription = page.value
|
const articleDescription = page.value
|
||||||
? page.value.description
|
? page.value.description
|
||||||
: `Writing from ${folderName.value}`;
|
: `Writing from ${folderName.value}`;
|
||||||
const layoutDescription = page.value
|
const layoutDescription = page.value
|
||||||
? formatDate(page.value.date)
|
? formatContentDate(page.value.date, 'long')
|
||||||
: articleDescription;
|
: articleDescription;
|
||||||
|
|
||||||
useSeoMeta({
|
useSeoMeta({
|
||||||
@@ -83,10 +76,10 @@ useSeoMeta({
|
|||||||
twitterDescription: articleDescription,
|
twitterDescription: articleDescription,
|
||||||
twitterImage: DEFAULT_IMAGE,
|
twitterImage: DEFAULT_IMAGE,
|
||||||
articlePublishedTime: page.value
|
articlePublishedTime: page.value
|
||||||
? new Date(page.value.date).toISOString()
|
? contentDateAttr(page.value.date)
|
||||||
: undefined,
|
: undefined,
|
||||||
articleModifiedTime: page.value
|
articleModifiedTime: page.value
|
||||||
? new Date(page.value.date).toISOString()
|
? contentDateAttr(page.value.date)
|
||||||
: undefined,
|
: undefined,
|
||||||
articleAuthor: page.value ? [SITE_NAME] : undefined,
|
articleAuthor: page.value ? [SITE_NAME] : undefined,
|
||||||
});
|
});
|
||||||
@@ -131,12 +124,8 @@ useHead({
|
|||||||
url: articleUrl,
|
url: articleUrl,
|
||||||
headline: articleTitle,
|
headline: articleTitle,
|
||||||
description: articleDescription,
|
description: articleDescription,
|
||||||
datePublished: new Date(
|
datePublished: contentDateAttr(page.value.date),
|
||||||
page.value.date,
|
dateModified: contentDateAttr(page.value.date),
|
||||||
).toISOString(),
|
|
||||||
dateModified: new Date(
|
|
||||||
page.value.date,
|
|
||||||
).toISOString(),
|
|
||||||
image: {
|
image: {
|
||||||
'@type': 'ImageObject',
|
'@type': 'ImageObject',
|
||||||
'@id': `${articleUrl}#article-image`,
|
'@id': `${articleUrl}#article-image`,
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
const YMD = /^(\d{4})-(\d{2})-(\d{2})/;
|
||||||
|
const HAS_TZ = /(?:Z|[+-]\d{2}:?\d{2})$/i;
|
||||||
|
|
||||||
|
export function formatContentDate(value: string, month: 'short' | 'long' = 'short') {
|
||||||
|
const match = YMD.exec(value);
|
||||||
|
if (!match) return '';
|
||||||
|
return new Date(Date.UTC(+match[1], +match[2] - 1, +match[3], 12)).toLocaleDateString(
|
||||||
|
'en-US',
|
||||||
|
{ month, day: 'numeric', year: 'numeric', timeZone: 'UTC' },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function contentDateAttr(value: string) {
|
||||||
|
if (HAS_TZ.test(value)) return new Date(value).toISOString();
|
||||||
|
return YMD.exec(value)?.[0] ?? '';
|
||||||
|
}
|
||||||
@@ -5,16 +5,14 @@ export function projectEntryHref(page: {
|
|||||||
return page.href || `/projects${page.path}`;
|
return page.href || `/projects${page.path}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sortProjects<
|
export function sortProjects<T extends { title: string; date?: string | null }>(
|
||||||
T extends { title: string; date?: Date | string | null },
|
pages: T[],
|
||||||
>(pages: T[]) {
|
) {
|
||||||
return [...pages].sort((a, b) => {
|
return [...pages].sort((a, b) => {
|
||||||
const aTime = a.date ? new Date(a.date).getTime() : Number.NaN;
|
if (!a.date && !b.date) return a.title.localeCompare(b.title);
|
||||||
const bTime = b.date ? new Date(b.date).getTime() : Number.NaN;
|
if (!a.date) return 1;
|
||||||
const aHasDate = !Number.isNaN(aTime);
|
if (!b.date) return -1;
|
||||||
const bHasDate = !Number.isNaN(bTime);
|
if (a.date !== b.date) return b.date.localeCompare(a.date);
|
||||||
if (aHasDate && bHasDate && aTime !== bTime) return bTime - aTime;
|
|
||||||
if (aHasDate !== bHasDate) return aHasDate ? -1 : 1;
|
|
||||||
return a.title.localeCompare(b.title);
|
return a.title.localeCompare(b.title);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -10,7 +10,7 @@ export default defineContentConfig({
|
|||||||
},
|
},
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
date: z.coerce.date(),
|
date: z.string(),
|
||||||
description: z.string(),
|
description: z.string(),
|
||||||
hidden: z.boolean().optional(),
|
hidden: z.boolean().optional(),
|
||||||
}),
|
}),
|
||||||
@@ -26,7 +26,7 @@ export default defineContentConfig({
|
|||||||
description: z.string(),
|
description: z.string(),
|
||||||
href: z.string().optional(),
|
href: z.string().optional(),
|
||||||
hidden: z.boolean().optional(),
|
hidden: z.boolean().optional(),
|
||||||
date: z.coerce.date().optional(),
|
date: z.string().optional(),
|
||||||
image: z.string().optional(),
|
image: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
title: Unicord 🦄
|
title: Unicord 🦄
|
||||||
description: A Discord bot SDK that works like a web server.
|
description: A Discord bot SDK that works like a web server.
|
||||||
# href: https://unicord.hat.fish
|
# href: https://unicord.hat.fish
|
||||||
|
date: 2025-01-12
|
||||||
---
|
---
|
||||||
|
|
||||||
I wanted writing a Discord bot to feel like writing a small web app. Register a handler, get a request, send a reply. *Bang!...bot done.* This became particularly interesting once bots could be served over HTTP.
|
I wanted writing a Discord bot to feel like writing a small web app. Register a handler, get a request, send a reply. *Bang!...bot done.* This became particularly interesting once bots could be served over HTTP.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
title: AI and the Barrier of Entry
|
title: AI and the Barrier of Entry
|
||||||
date: 2023-03-25T12:00:00.000Z
|
date: 2023-03-25T12:00:00.000Z
|
||||||
description: We are witnessing the next major wave of technological innovation. And it's never been easier to be a part of it.
|
description: We are witnessing the next major wave of technological innovation. And it's never been easier to be a part of it.
|
||||||
|
hidden: true
|
||||||
---
|
---
|
||||||
|
|
||||||
To be fair the term itself, **AI**, has had its meaning stretched pretty thin in the last few years. :margin-note[(Artificial Intelligence. The label has been doing too much work.)] It's been used to describe everything from a simple chatbot to a self driving car. That use is extremely broad. It doesn't really describe the space we think of as "AI".
|
To be fair the term itself, **AI**, has had its meaning stretched pretty thin in the last few years. :margin-note[(Artificial Intelligence. The label has been doing too much work.)] It's been used to describe everything from a simple chatbot to a self driving car. That use is extremely broad. It doesn't really describe the space we think of as "AI".
|
||||||
|
|||||||
Reference in New Issue
Block a user