Skip to content

refactor: route site layout through Jinja (first step) (#13524) - #13529

Merged
RayBB merged 4 commits into
internetarchive:masterfrom
RsbhThakur:13524/spike/jinja-site-layout
Sep 4, 2026
Merged

RayBB merged 4 commits into
internetarchive:masterfrom
RsbhThakur:13524/spike/jinja-site-layout

Conversation

@RsbhThakur

@RsbhThakur RsbhThakur commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #13524

refactor: routes the top-level site layout through Jinja as the first step of the layout modernization roadmap.

Technical

  • Jinja Layout: Added openlibrary/templates/site.html.jinja to render the existing Templetor partials (site/head, site/body, and site/footer) using the reverse bridge helper render_templetor_template.
  • Autoescape Safety: render_templetor_template returns Markup so Jinja autoescape does not entity-escape the returned HTML; no | safe needed at call sites.
  • Direct Wiring: Deleted Templetor openlibrary/templates/site.html; setup() in openlibrary/plugins/openlibrary/code.py registers SiteLayoutTemplate via template.render.add_source({"site": ...}) so Infogami's render.site() serves Jinja directly.

Testing

  1. Run Jinja test suite:
    uv run --with-requirements requirements_test.txt pytest openlibrary/tests/core/test_jinja.py
  2. Verify pre-commit hooks pass:
    pre-commit run --files openlibrary/core/jinja.py openlibrary/plugins/openlibrary/code.py openlibrary/templates/site.html.jinja openlibrary/tests/core/test_jinja.py
  3. Start local docker environment (docker compose up) and verify that pages (/, /works/OL..., /authors/OL..., /status) render normally with intact chrome.

Screenshot

N/A — UI output and DOM structure are diff-clean (unchanged).

Stakeholders

@RayBB

@github-project-automation github-project-automation Bot moved this to Waiting Review/Merge from Staff in Ray's Project Sep 3, 2026
@RayBB

RayBB commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

@RsbhThakur Python tests are failing and please provide a screenshot to show that the site is actually working with your changes.

@RsbhThakur
RsbhThakur marked this pull request as draft September 3, 2026 20:24
@RsbhThakur
RsbhThakur force-pushed the 13524/spike/jinja-site-layout branch from 0f2a8d6 to 928790f Compare September 3, 2026 20:25
@RsbhThakur
RsbhThakur marked this pull request as ready for review September 3, 2026 20:28
@RsbhThakur

Copy link
Copy Markdown
Contributor Author
image image

@RayBB here are the screenshots of the pages getting rendered properly, the python tests failed due to an issue i was working on while pushing the 1st commit, its fixed in the latest commit. The PR is ready for review!

@RayBB

RayBB commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

@RsbhThakur why did the tests change so much?

@RsbhThakur

RsbhThakur commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

@RayBB, The change in test_jinja.py is because site/layout.html.jinja is the first template in the codebase to actually call render_templetor_template.

In test_all_jinja_templates_render_valid_html, it runs isolated structural HTML validation without booting Infogami or loading disk templates, so calling the uninitialized render_templetor_template was raising a TypeError ("'NoneType' object is not callable") when trying to resolve site/head.

I stubbed it in _create_validation_env to return an empty string (just like icon and render_component are already stubbed there), and added a unit test in TestGetJinjaEnv to verify that render_templetor_template is registered in the real environment.

@RayBB
RayBB force-pushed the 13524/spike/jinja-site-layout branch from 3c65ab7 to a200aee Compare September 4, 2026 07:58

@RayBB RayBB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've been prodding this on testing and locally.

I don't see any performance change from doing this (which is good and expected) and it seems to work flawlessly.

I did push some some changes to simplify and actually render jinja at the highest level so we can start working our way down but overall this seems very safe and a great step.

Thanks for your contribution!

@RayBB
RayBB merged commit 4d49450 into internetarchive:master Sep 4, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting Review/Merge from Staff to Done in Ray's Project Sep 4, 2026
@RsbhThakur
RsbhThakur deleted the 13524/spike/jinja-site-layout branch September 4, 2026 08:24
@RayBB RayBB changed the title refactor: route site layout through Jinja (first shim step) (#13524) refactor: route site layout through Jinja (first step) (#13524) Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Spike: route the site layout through Jinja (first shim step)

2 participants