Skip to content

fix(build): make BLOG_YEAR scope lite builds to blog years again - #8071

Open
leecalcote wants to merge 2 commits into
masterfrom
fix/blog-year-lite-build
Open

leecalcote wants to merge 2 commits into
masterfrom
fix/blog-year-lite-build

Conversation

@leecalcote

@leecalcote leecalcote commented Sep 14, 2026

Copy link
Copy Markdown
Member

Symptom

make site-blog says "2026 posts only, much faster builds" and passes BLOG_YEAR=2026, but the dev server sourced every blog year (2019-2026). Nothing in gatsby-config.js, gatsby-node.js, or src/utils/build-collections.js read BLOG_YEAR.

Root cause

Year filtering was added in 8c73741 ("Refactor gatsby-config.js for improved configuration") as a LITE_BUILD_PROFILE === "blog" block that rewrote the blog source path. That commit was reverted wholesale in 8d3d41b, and the year filter went with it. The Makefile targets (86786ba, 8c66231) survived, so the knob became a silent no-op. Since then, lite builds moved to a single collections filesystem source with ignore globs from build-collections.js, so the old path-rewrite approach no longer fits.

Fix

Year filtering is restored in the current build-scope mechanism instead of reviving the reverted block.

  • src/utils/build-collections.js: getBlogYearFilter() turns BLOG_YEAR (2026 or 2025,2026) into ignore globs (**/collections/blog/<year>/**) for every other year directory (from listBlogYears()).
    • Applies to lightweight builds that include the blog (content and blog profiles).
    • Does not apply, and warns why, for BUILD_FULL_SITE=true or a profile that excludes the blog.
    • Throws on a value that is not a four-digit year, or a year with no directory, instead of silently building an empty blog.
  • gatsby-config.js: appends those globs to the collections source and logs Build Scope blog years (BLOG_YEAR): ....
  • Makefile: site-blog defaults BLOG_YEAR to the latest year directory instead of a hardcoded 2026 that goes stale every January, and accepts BLOG_YEAR=2025,2026 make site-blog. Help text updated.
  • Tests: src/utils/build-collections.test.js (14 cases, node:test, no new dependencies), run with npm run test:unit in Build PR Preview right after install (Checks, where they are also added, has been disabled since December 2025). A mutation (inverting the year filter) fails 2 cases.
  • Docs: CONTRIBUTING.md documents the blog profile, BLOG_YEAR, and make site-blog.

Blog listing, category, and tag pages need no change. They query allMdx for the blog collection and render whatever was sourced.

Verification

LITE_BUILD_PROFILE=blog make site (all years) make site-blog (BLOG_YEAR=2026)
Build scope log excludes (blog): events, integrations, members, news, resources same, plus blog years (BLOG_YEAR): 2026
Total nodes 4040 2845
SitePage nodes 567 410
/blog listing posts 117 9
2026 post /blog/ai/how-to-disable-how-is-claude-doing-this-session 200 200
2025 post /blog/engineering/supercharge-your-git-workflow-with-powerful-aliases 200 404
/blog, /blog/category/engineering 200 200 (3 Engineering posts)

Config paths checked by loading gatsby-config.js:

  • core + BLOG_YEAR=2026: warns "the blog collection is excluded from this build", no extra globs.
  • BUILD_FULL_SITE=true + BLOG_YEAR=2026: warns "BUILD_FULL_SITE=true builds every blog year", no globs.
  • BLOG_YEAR=1999: fails with "has no directory under src/collections/blog; available years: 2019, ..., 2026".
  • BLOG_YEAR=latest: fails with "must be a comma-separated list of four-digit years".
  • content + BLOG_YEAR=2025,2026: ignores 2019-2024.
  • make site (empty BLOG_YEAR): unchanged.
  • npm run test:unit: 14/14 pass.
  • npm run check:contributing-versions passes.

Watch for

  • .claude/skills/layer5-blog-writer/SKILL.md step 7b builds the whole blog profile to validate one post. Adding BLOG_YEAR=<post year> would make it faster. I left it out because the skill is versioned separately.
  • New per-year collections should follow the same <collection>/<YYYY>/ layout if they want the same treatment.

Summary by CodeRabbit

  • New Features

    • Lightweight blog builds now automatically use the latest available blog year.
    • Specify one or more years with BLOG_YEAR to build only selected blog content.
    • Invalid or unavailable year values now produce clear build errors.
  • Documentation

    • Updated contributor guidance for blog profiles, year filtering, and collections skipped by standard site builds.
  • Tests

    • Automated unit tests now run during site preview and validation workflows.

make site-blog advertised "2026 posts only" and passed BLOG_YEAR, but
nothing read it: year filtering was added in 8c73741 and removed with
the rest of that change by its revert, 8d3d41b. The blog profile
sourced every blog year.

- build-collections: getBlogYearFilter turns BLOG_YEAR (one year or a
  comma-separated list) into ignore globs for the other
  src/collections/blog/<year> directories. It applies to lightweight
  builds that include the blog (content, blog profiles), warns when it
  cannot apply (full build, blog excluded), and fails on a value that is
  not a year or has no directory rather than silently building nothing.
- gatsby-config: add the globs to the collections source and log the
  blog years in the build scope.
- Makefile: site-blog defaults to the latest year directory instead of a
  hardcoded 2026 and accepts BLOG_YEAR overrides.
- Unit tests with node:test (npm run test:unit), run in Checks CI.
- CONTRIBUTING: document the blog profile, BLOG_YEAR, and make site-blog.

Signed-off-by: Lee Calcote <lee.calcote@layer5.io>
The Checks workflow has been disabled since December 2025, so the unit
test step added there never runs. Build PR Preview runs on every PR;
run the tests right after install, before the long site build.

Signed-off-by: Lee Calcote <lee.calcote@layer5.io>
@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: c2586d77-43bd-46ad-8267-7bd36fac8404

📥 Commits

Reviewing files that changed from the base of the PR and between f78a0af and d5e2232.

📒 Files selected for processing (8)
  • .github/workflows/build-site-preview.yaml
  • .github/workflows/checks.yml
  • CONTRIBUTING.md
  • Makefile
  • gatsby-config.js
  • package.json
  • src/utils/build-collections.js
  • src/utils/build-collections.test.js

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The build now supports selecting blog years for lightweight builds. It derives the default year, filters other blog directories, validates BLOG_YEAR, documents the behavior, and runs unit tests in both CI workflows.

Changes

Blog year filtering

Layer / File(s) Summary
Blog year discovery and filtering
src/utils/build-collections.js
The build utilities list four-digit blog directories, validate BLOG_YEAR, and generate ignore globs for unselected years.
Build integration and year defaults
Makefile, gatsby-config.js
site-blog defaults to the latest blog year unless BLOG_YEAR is provided. Gatsby applies the year filters and logs the selected or inactive state.
Validation, documentation, and CI
src/utils/build-collections.test.js, package.json, .github/workflows/*, CONTRIBUTING.md
Unit tests cover filtering and validation. Documentation describes the new profile and variable. Both workflows run the unit-test script.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Developer
  participant Makefile
  participant GatsbyConfig
  participant BuildCollections
  Makefile->>Makefile: derive or accept BLOG_YEAR
  Makefile->>GatsbyConfig: start site-blog build
  GatsbyConfig->>BuildCollections: getBlogYearFilter(options)
  BuildCollections-->>GatsbyConfig: selected years and ignore globs
  GatsbyConfig->>GatsbyConfig: apply collection ignore patterns
  GatsbyConfig-->>Developer: log selected or inactive filtering state
Loading

Merge Risk: ⚪ Minimal · up to d5e22

The scoped blog build correctly selects requested years and excludes unselected year directories. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: restoring BLOG_YEAR scoping for lightweight blog builds.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/blog-year-lite-build

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for PR #8071 removed.

This PR preview was automatically pruned because we keep only the 3 most recently updated previews on GitHub Pages to stay within deployment size limits.

If needed, push a new commit to this PR to generate a fresh preview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant