Skip to content

fix: Substack Cloudflare block + getSitePosts crash + build resilience - #4

Merged
Korede-TA merged 2 commits into
mainfrom
fix/substack-cloudflare-and-build-crashes
Jun 2, 2026
Merged

fix: Substack Cloudflare block + getSitePosts crash + build resilience#4
Korede-TA merged 2 commits into
mainfrom
fix/substack-cloudflare-and-build-crashes

Conversation

@Korede-TA

Copy link
Copy Markdown
Contributor

What

Two commits on top of the merged PR #3 changes.

1. Remove build-time Substack API fetch (pages/index.tsx, lib/get-substack-essays.ts)

The Substack API (/api/v1/posts) is behind Cloudflare bot protection, which returns a 403 JS challenge page for any non-browser request — including GitHub Actions. This will never work at build time regardless of API key or User-Agent.

Removed the getSubstackEssays call from getStaticProps entirely. Substack content is now surfaced via two client-side mechanisms that aren't affected by Cloudflare:

  • "Read on Substack ↗" link — permanent, always visible at the top of the essays section
  • Substack embed iframe — loads in the browser, shows the subscription widget + recent posts

2. Fix getSitePosts crash (lib/get-site-posts.ts)

collection.name[0][0] threw Cannot read properties of undefined (reading '0') when collection.name was absent in the Notion response. Added optional chaining (?.) so it returns undefined and the existing early-return guard handles it gracefully instead of crashing the build.

Test plan

  • CI build passes
  • Essays section shows "Read on Substack" link
  • Substack embed iframe renders on the page
  • Local Notion posts still list correctly

https://claude.ai/code/session_01P9Bn6gkWtM15yEzGf79XCQ


Generated by Claude Code

@netlify

netlify Bot commented Jun 2, 2026

Copy link
Copy Markdown

Deploy Preview for soft-swan-5d0ce7 failed. Why did it fail? →

Name Link
🔨 Latest commit f13c355
🔍 Latest deploy log https://app.netlify.com/projects/soft-swan-5d0ce7/deploys/6a1f5667c068990008fdff28

@netlify

netlify Bot commented Jun 2, 2026

Copy link
Copy Markdown

Deploy Preview for darling-dusk-441006 ready!

Name Link
🔨 Latest commit f13c355
🔍 Latest deploy log https://app.netlify.com/projects/darling-dusk-441006/deploys/6a1f5667615d990009a23b48
😎 Deploy Preview https://deploy-preview-4--darling-dusk-441006.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

claude added 2 commits June 2, 2026 22:17
- is_published === true was silently dropping posts where the field is
  absent (common on the public API) — changed to !== false so only
  explicitly unpublished posts are excluded
- Replace log() calls with console.error() so fetch errors always appear
  in CI output regardless of LOG_LEVEL / DEBUG env vars
- Add permanent 'Read on Substack' link at the top of the essays section
  as a reliable fallback if the API fetch returns nothing

https://claude.ai/code/session_01P9Bn6gkWtM15yEzGf79XCQ
…tSitePosts crash

Substack's API is behind Cloudflare bot protection which always returns 403
from GitHub Actions — build-time fetching is not viable. Removed the fetch
entirely; Substack content is now surfaced via:
  - "Read on Substack" link at the top of the essays section
  - Substack embed iframe (loads client-side, not blocked by Cloudflare)

Also fixed getSitePosts crash: collection.name[0][0] threw when
collection.name was undefined; added optional chaining so it returns
undefined and the early-return guard handles it gracefully.

https://claude.ai/code/session_01P9Bn6gkWtM15yEzGf79XCQ
@Korede-TA
Korede-TA force-pushed the fix/substack-cloudflare-and-build-crashes branch from 045a423 to f13c355 Compare June 2, 2026 22:17
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-06-02 22:22 UTC

@Korede-TA
Korede-TA merged commit 27494eb into main Jun 2, 2026
5 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants