Skip to content

Commit 86e4e78

Browse files
authored
fix(rss): normalize pubDate to correct calendar date (#13)
1 parent a41e7e0 commit 86e4e78

File tree

2 files changed

+10
-113
lines changed

2 files changed

+10
-113
lines changed

package-lock.json

Lines changed: 1 addition & 112 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/rss.xml.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import rss from '@astrojs/rss';
22
import { getCollection } from 'astro:content';
33
import type { APIContext } from 'astro';
44

5+
// Get the date portion in Eastern time and return a Date at noon UTC
6+
// This ensures the pubDate displays the correct calendar date regardless of timezone
7+
function normalizeDateForRss(date: Date): Date {
8+
const eastern = date.toLocaleDateString('en-CA', { timeZone: 'America/New_York' });
9+
const [year, month, day] = eastern.split('-').map(Number);
10+
return new Date(Date.UTC(year, month - 1, day, 12, 0, 0));
11+
}
12+
513
export async function GET(context: APIContext) {
614
const posts = await getCollection('blog');
715
const sortedPosts = posts.sort((a, b) => b.data.date.getTime() - a.data.date.getTime());
@@ -14,7 +22,7 @@ export async function GET(context: APIContext) {
1422
const slug = post.id.split('/').pop() || post.id;
1523
return {
1624
title: post.data.title,
17-
pubDate: post.data.date,
25+
pubDate: normalizeDateForRss(post.data.date),
1826
description: post.data.description || '',
1927
link: `/${slug}/`,
2028
categories: post.data.categories,

0 commit comments

Comments
 (0)