Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions app/lib/substack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ export type SubstackPost = {
description: string;
};

const FEEDS = [
"https://substack.com/@kaiiiichen/feed",
"https://kaiiiichen.substack.com/feed",
];
// `https://substack.com/@<user>/feed` started returning 404 (it serves the
// generic discover HTML page now), so we hit the publication feed directly.
const FEEDS = ["https://kaiiiichen.substack.com/feed"];

// Refetch the RSS feed every 10 minutes so newly-published posts appear on the
// homepage within ~10 min instead of the previous 1 h window.
const REVALIDATE_SECONDS = 600;

function extractTag(xml: string, tag: string): string {
const cdataMatch = new RegExp(`<${tag}[^>]*><!\\[CDATA\\[([\\s\\S]*?)\\]\\]><\\/${tag}>`, "i").exec(xml);
Expand All @@ -34,7 +37,7 @@ export async function getSubstackPosts(): Promise<SubstackPost[]> {
for (const feed of FEEDS) {
try {
const res = await fetch(feed, {
next: { revalidate: 3600 },
next: { revalidate: REVALIDATE_SECONDS },
headers: { "User-Agent": "kaichen.dev/1.0" },
});
if (!res.ok) continue;
Expand Down