Skip to content

refactor(deps): add SiteContext dependency to remove per-route config ritual#123

Merged
x3ek merged 3 commits into
mainfrom
refactor/112-site-context
Jul 3, 2026
Merged

refactor(deps): add SiteContext dependency to remove per-route config ritual#123
x3ek merged 3 commits into
mainfrom
refactor/112-site-context

Conversation

@x3ek

@x3ek x3ek commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Closes #112

Adds a SiteContext dependency (parsed config plus the services bundle, markdown service exposed as a lazy property) so routes stop repeating the get_config / Config.from_dict / markdown_for ritual. Posts, pages, admin dashboard, and /pygments.css now consume SiteContextDep.

Deliberately left on ServicesDep: feed.xml, sitemap.xml, and robots.txt check their response caches before fetching config; the eager dependency would add a config fetch on every cache hit, a behavior change.

Checks green (367 tests, pyright clean). Live smoke on the branch: posts, post detail, page, pygments, admin, feed, sitemap all serve correctly.

🤖 Generated with Claude Code

… ritual

Introduce SiteContext (config plus services bundle) and get_site_context
so routes drop the get_config/from_dict boilerplate. The markdown service
is a lazy property so config-only routes never build it. Cache-guarded
routes (feed, sitemap, robots) keep the manual fetch to preserve their
fast path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@x3ek x3ek added this to the SquishMark 1.0 milestone Jul 3, 2026
@x3ek x3ek requested a review from Copilot July 3, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a SiteContext FastAPI dependency to centralize per-request config parsing and access to the service container, reducing repeated “fetch config + Config.from_dict + markdown service” boilerplate across route handlers. This fits the DI layer (dependencies.py) and updates several routers and tests to consume the new context object.

Changes:

  • Added SiteContext / SiteContextDep and get_site_context() dependency to bundle parsed Config with Services, exposing markdown via a lazy property.
  • Refactored posts/pages/admin dashboard and /pygments.css to accept SiteContextDep instead of repeating config parsing.
  • Updated tests (and added new dependency tests) to construct/pass SiteContext when calling handlers directly.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/squishmark/dependencies.py Adds SiteContext dataclass + get_site_context dependency and type alias.
src/squishmark/routers/posts.py Switches post listing/detail routes to consume SiteContextDep for config/services.
src/squishmark/routers/pages.py Switches page route to use context.config and context.markdown.
src/squishmark/routers/assets.py Updates /pygments.css route to use SiteContextDep (keeps favicon/user static on ServicesDep).
src/squishmark/routers/admin.py Updates admin dashboard to use SiteContextDep for config/cache access.
tests/test_notes_rendering.py Updates direct handler calls to pass a constructed SiteContext.
tests/test_nav_pages.py Updates direct handler calls to pass a constructed SiteContext.
tests/test_dependencies.py Adds focused tests for get_site_context() and markdown laziness/caching semantics.

Comment thread src/squishmark/dependencies.py
@x3ek x3ek merged commit 680de62 into main Jul 3, 2026
5 checks passed
@x3ek x3ek deleted the refactor/112-site-context branch July 3, 2026 14:38
@x3ek x3ek mentioned this pull request Jul 3, 2026
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.

Add a shared request context dependency to remove per-route config boilerplate

2 participants