diff --git a/lib/get-site-posts.ts b/lib/get-site-posts.ts index 2a9511a..2789a1d 100644 --- a/lib/get-site-posts.ts +++ b/lib/get-site-posts.ts @@ -46,7 +46,7 @@ export function getSitePosts(args: { if (!collection) return []; const collectionId = collection.id, - collectionTitle = collection.name[0][0], + collectionTitle = collection.name?.[0]?.[0], collectionSchema = collection.schema; if (!collectionId || collectionTitle !== POSTS_COLLECTION_TITLE) return []; diff --git a/lib/get-substack-essays.ts b/lib/get-substack-essays.ts index a726d87..0bb20bf 100644 --- a/lib/get-substack-essays.ts +++ b/lib/get-substack-essays.ts @@ -37,18 +37,23 @@ export async function getSubstackEssays( const response = await fetch(apiUrl, { headers }); if (!response.ok) { - log("ERROR", `Failed to fetch Substack essays from ${substackHandle}`, { - status: response.status, - response: await response.text(), - }); + const body = await response.text(); + console.error(`[substack] fetch failed: ${response.status}`, body.slice(0, 200)); return []; } const data = await response.json(); - // Extract essays from the Substack API response - const essays = (data || []) - .filter((post: any) => post.is_published === true) // Only published posts + if (!Array.isArray(data)) { + console.error(`[substack] unexpected response shape`, JSON.stringify(data).slice(0, 200)); + return []; + } + + // Extract essays from the Substack API response. + // The public endpoint already filters to published posts; avoid strict + // is_published === true which drops posts where the field is absent. + const essays = data + .filter((post: any) => post.is_published !== false) .map((post: any) => ({ id: String(post.id), title: post.title || "", @@ -62,16 +67,10 @@ export async function getSubstackEssays( image: post.cover_image || undefined, })) as SubstackEssay[]; - log("DEBUG", "Fetched Substack essays", { - count: essays.length, - substackHandle, - }); + console.error(`[substack] fetched ${essays.length} essays from ${substackHandle}`); return essays; } catch (err) { - log("ERROR", "Error fetching Substack essays", { - error: err, - substackHandle, - }); + console.error(`[substack] fetch threw`, err); return []; } } diff --git a/pages/index.tsx b/pages/index.tsx index fa9611b..8cdf281 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -6,7 +6,6 @@ import { getSitePosts } from "lib/get-site-posts"; import * as config from "lib/config"; import { resolveNotionPage } from "lib/resolve-notion-page"; import { resolveArenaChannels } from "lib/resolve-arena-channels"; -import { getSubstackEssays, SubstackEssay } from "lib/get-substack-essays"; import { useDarkMode } from "lib/use-dark-mode"; import { mapPageUrl } from "lib/map-page-url"; import { getLayoutProps } from "lib/get-layout-props"; @@ -34,23 +33,12 @@ export const getStaticProps = async () => { const channels = await resolveArenaChannels(); const siteMap = await getSiteMap(); - // Fetch Substack essays - public API works without a key; key is optional enhancement const substackHandle = process.env.SUBSTACK_HANDLE || "suruleredotdev"; - const substackApiKey = process.env.SUBSTACK_API_KEY; - let substackEssays: SubstackEssay[] = []; - if (substackHandle) { - substackEssays = await getSubstackEssays( - substackHandle, - 10, - substackApiKey - ); - } const props = { ...notionProps, channels, siteMap, - substackEssays, substackHandle, }; @@ -78,7 +66,6 @@ const homePageText = [ const textVersion = 0; interface HomePageContentProps extends types.PageProps { - substackEssays?: SubstackEssay[]; substackHandle?: string; } @@ -88,7 +75,6 @@ export const HomePageContent: React.FC = ({ pageId, channels, siteMap, - substackEssays = [], substackHandle = "suruleredotdev", }) => { // TODO: render from root page block @@ -115,110 +101,55 @@ export const HomePageContent: React.FC = ({ ESSAYS - {(() => { - const allItems = [ - ...posts - ?.filter((post) => post.public == true) - .map((post) => ({ ...post, isExternal: false, image: undefined as string | undefined })), - ...substackEssays.map((essay) => ({ - ...essay, - isExternal: true, - id: `substack-${essay.id}`, - })), - ].sort((a, b) => b.published - a.published); - - return ( - <> - {allItems.length > 0 && ( - - )} - {substackEssays.length === 0 && ( -