refactor(deps): add SiteContext dependency to remove per-route config ritual#123
Merged
Conversation
… 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>
There was a problem hiding this comment.
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/SiteContextDepandget_site_context()dependency to bundle parsedConfigwithServices, exposing markdown via a lazy property. - Refactored posts/pages/admin dashboard and
/pygments.cssto acceptSiteContextDepinstead of repeating config parsing. - Updated tests (and added new dependency tests) to construct/pass
SiteContextwhen 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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