Blog posts use Date type pubDate
This commit is contained in:
@@ -12,29 +12,18 @@ const { headingLevel = 2, hideAuthor = false } = Astro.props;
|
||||
const posts = (await getCollection('blog')).filter((post) => !post.data.hidden);
|
||||
|
||||
const distinctYears: number[] = posts
|
||||
.map(post => post.data.pubDate.year)
|
||||
.map(post => post.data.pubDate.getFullYear())
|
||||
.reduce<number[]>((acc, curr) => acc.includes(curr) ? acc : [...acc, curr], [])
|
||||
.sort((a, b) => b - a);
|
||||
|
||||
function matchesYear(year: number) {
|
||||
return (post: CollectionEntry<'blog'>) => post.data.pubDate.year === year;
|
||||
return (post: CollectionEntry<'blog'>) => post.data.pubDate.getFullYear() === year;
|
||||
}
|
||||
|
||||
function sortByPubDateDescending(post1: CollectionEntry<'blog'>, post2: CollectionEntry<'blog'>) {
|
||||
const year1 = post1.data.pubDate.year;
|
||||
const year2 = post2.data.pubDate.year;
|
||||
const month1 = post1.data.pubDate.month;
|
||||
const month2 = post2.data.pubDate.month;
|
||||
const day1 = post1.data.pubDate.day;
|
||||
const day2 = post2.data.pubDate.day;
|
||||
|
||||
if (year1 !== year2) {
|
||||
return year2 - year1;
|
||||
} else if (month1 !== month2) {
|
||||
return month2 - month1;
|
||||
} else {
|
||||
return day2 - day1;
|
||||
}
|
||||
const date1 = post1.data.pubDate.getMilliseconds();
|
||||
const date2 = post2.data.pubDate.getMilliseconds();
|
||||
return date2 - date1;
|
||||
}
|
||||
|
||||
const headingElem = `h${headingLevel}`;
|
||||
|
||||
@@ -3,10 +3,7 @@ title: Harari’s Sapiens on Religion
|
||||
description: >-
|
||||
In which I discuss why I think Harari’s characterisation of religion
|
||||
is inadequate because it’s too materialistic.
|
||||
pubDate:
|
||||
year: 2024
|
||||
month: 01
|
||||
day: 14
|
||||
pubDate: 2024-01-14
|
||||
---
|
||||
|
||||
I’ve been slowly re-reading Yuval Noah Harari’s 2014 classic,
|
||||
|
||||
@@ -6,10 +6,7 @@ description: >-
|
||||
Ullapool last weekend, I had the last privilege of giving the Toast to
|
||||
the Lassies. Particularly for the benefit of those who weren’t there,
|
||||
here it is in full!
|
||||
pubDate:
|
||||
year: 2024
|
||||
month: 01
|
||||
day: 29
|
||||
pubDate: 2024-01-29
|
||||
---
|
||||
|
||||
Had Burns, instead of his sweet bonnie Jean,<br>
|
||||
|
||||
@@ -4,10 +4,7 @@ description: >-
|
||||
Based on a talk given to my colleagues at
|
||||
<a href="https://www.scottlogic.co.uk">Scott Logic</a> for Maundy
|
||||
Thursday, 2024.
|
||||
pubDate:
|
||||
year: 2024
|
||||
month: 03
|
||||
day: 30
|
||||
pubDate: 2024-03-30
|
||||
---
|
||||
|
||||
As you might have noticed, it is Easter this week! So I'd like to take five or
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
---
|
||||
title: Who consecrates the tabernacle? (Ex 29)
|
||||
description: A quick, cursory and possibly completely rubbish observation I've made on Exodus 29.
|
||||
pubDate:
|
||||
year: 2024
|
||||
month: 04
|
||||
day: 11
|
||||
pubDate: 2024-04-11
|
||||
---
|
||||
|
||||
I've been reading Exodus recently, and the ending of Chapter 29 stuck out to me.
|
||||
|
||||
@@ -3,10 +3,7 @@ title: God Is Not Great, initial thoughts
|
||||
description: >-
|
||||
My spark notes on Hitchen's classic 2007 polemic against religion, plus some
|
||||
initial thoughts on how I want to respond to it.
|
||||
pubDate:
|
||||
year: 2024
|
||||
month: 04
|
||||
day: 14
|
||||
pubDate: 2024-04-14
|
||||
---
|
||||
|
||||
These are my 'spark notes' on _God Is Not Great_, Christopher Hitchen's classic
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
title: How I made YouTube work for me
|
||||
description: >-
|
||||
I just learned YouTube channels have an RSS feed. This is terrific news.
|
||||
pubDate:
|
||||
year: 2024
|
||||
month: 05
|
||||
day: 02
|
||||
pubDate: 2024-05-02
|
||||
---
|
||||
|
||||
One of my bad habits in life is wandering through YouTube. I've always had
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
title: LLMs do not understand anything
|
||||
description: >-
|
||||
Save this for the next time someone tells you that LLMs 'understand' things.
|
||||
pubDate:
|
||||
year: 2024
|
||||
month: 06
|
||||
day: 13
|
||||
pubDate: 2024-06-13
|
||||
---
|
||||
|
||||
LLMs do not understand what they are talking about. They just don't. It's not
|
||||
|
||||
@@ -3,10 +3,7 @@ title: Doctor Who, Gayness, and the Church
|
||||
description: >-
|
||||
Series 14 of Doctor Who has a schizophrenic relationship with Christianity.
|
||||
It’s also gay. I think there might be a connection.
|
||||
pubDate:
|
||||
year: 2024
|
||||
month: 07
|
||||
day: 8
|
||||
pubDate: 2024-07-08
|
||||
---
|
||||
|
||||
I’ve recently finished the most recent series of Doctor Who, series fourteen (or
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
import { defineCollection, z } from 'astro:content';
|
||||
|
||||
const dateSchema = z.object({
|
||||
year: z.number(),
|
||||
month: z.number(),
|
||||
day: z.number(),
|
||||
});
|
||||
|
||||
const blog = defineCollection({
|
||||
type: 'content',
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
hidden: z.optional(z.boolean()),
|
||||
description: z.string(),
|
||||
pubDate: dateSchema,
|
||||
updatedDate: z.optional(dateSchema),
|
||||
pubDate: z.date(),
|
||||
updatedDate: z.optional(z.date()),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -9,11 +9,6 @@ type Props = CollectionEntry<'blog'>['data'];
|
||||
const { title, description, pubDate, updatedDate } = Astro.props;
|
||||
|
||||
const canonicalUrl = new URL(Astro.url.pathname, Astro.site);
|
||||
|
||||
const pubDateStr = `${pubDate.year}-${pubDate.month}-${pubDate.day}`;
|
||||
const updatedDateStr = updatedDate ?
|
||||
`${updatedDate.year}-${updatedDate.month}-${updatedDate.day}`
|
||||
: pubDateStr;
|
||||
---
|
||||
|
||||
<html lang="en">
|
||||
@@ -32,9 +27,9 @@ const updatedDateStr = updatedDate ?
|
||||
</span>
|
||||
{ updatedDate
|
||||
? (
|
||||
<span>Updated: <FormattedDate date={updatedDateStr} className="dt-updated"/>.</span>
|
||||
<span>Originally published: <FormattedDate date={pubDateStr} className="dt-published"/>.</span>
|
||||
) : <span>Published: <FormattedDate date={pubDateStr} className="dt-published"/>.</span>
|
||||
<span>Updated: <FormattedDate date={updatedDate} className="dt-updated"/>.</span>
|
||||
<span>Originally published: <FormattedDate date={pubDate} className="dt-published"/>.</span>
|
||||
) : <span>Published: <FormattedDate date={pubDate} className="dt-published"/>.</span>
|
||||
}
|
||||
<span hidden><a class="u-url uid" href={canonicalUrl}>Permalink</a></span>
|
||||
</aside>
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function GET(context: APIContext) {
|
||||
link: `/blog/${post.slug}`,
|
||||
title: post.data.title,
|
||||
content: mdParser.render(post.body),
|
||||
pubDate: new Date(`${post.data.pubDate.year}-${post.data.pubDate.month}-${post.data.pubDate.day}`),
|
||||
pubDate: post.data.pubDate,
|
||||
description: post.data.description,
|
||||
author: 'Joe Carstairs',
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
---
|
||||
title: Tracking pixels
|
||||
description: Concerning a notice in the privacy policy of an HR app
|
||||
pubDate:
|
||||
year: 2024
|
||||
month: 04
|
||||
day: 10
|
||||
pubDate: 2024-04-10
|
||||
---
|
||||
|
||||
I recently made the mistake of reading the privacy policy of the HR app my
|
||||
|
||||
Reference in New Issue
Block a user