fix feed time

This commit is contained in:
ld3zian 2025-02-05 16:03:44 -07:00
parent 01734e8ce5
commit 06025b567e
3 changed files with 44 additions and 6 deletions

View file

@ -48,7 +48,19 @@ export const GET: APIRoute = async ({ params, request }) => {
});
chapters.forEach((chapter) => {
if (!chapter?.created_at) {
console.error('Chapter missing created_at:', chapter);
return;
}
const chapterUrl = `https://comick.io/comic/${chapter.md_comics.slug}`;
const rawDate = chapter.created_at.endsWith('Z')
? chapter.created_at
: `${chapter.created_at}Z`;
const pubDate = isValidDate(rawDate) ? new Date(rawDate) : new Date();
feed.addItem({
title: `${chapter.md_comics.title} - Chapter ${chapter.chap}`,
id: `${chapter.md_comics.slug}-${chapter.chap}`,
@ -64,7 +76,7 @@ export const GET: APIRoute = async ({ params, request }) => {
<p>New chapter available: Chapter ${chapter.chap}</p>
</div>
`,
date: new Date(chapter.updated_at),
date: pubDate,
});
});
@ -73,4 +85,8 @@ export const GET: APIRoute = async ({ params, request }) => {
'Content-Type': 'application/xml; charset=utf-8',
},
});
};
};
function isValidDate(dateString: string): boolean {
return !isNaN(Date.parse(dateString));
}