feat: template index.html meta tags via Jinja from the Python build#131
Merged
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
✨ Preview deployed to S3! Visit http://ds-preview-contributor-network-131.s3-website-us-west-2.amazonaws.com/ |
Member
Author
|
@gadomski I converted to draft, I haven't reviewed this yet |
gadomski
requested changes
May 5, 2026
Collaborator
gadomski
left a comment
There was a problem hiding this comment.
Our ad-hoc templating is a bit fragile. Instead, we could update our build command to use https://jinja.palletsprojects.com/en/stable/ to write out the index.html with "real" templating.
…ite plugin Moves SEO meta-tag templating from a custom Vite plugin (string replacement on %PLACEHOLDER% strings) to a real Jinja2 template rendered by the `contributor-network build` command. Jinja's autoescape protects against injection from config values, and unknown variables raise instead of silently shipping unsubstituted placeholders. The source template lives at python/contributor_network/templates/index.html.j2. The generated index.html is gitignored; `contributor-network build` writes it before `npm run dev` / `npm run build` consume it (same ordering as before). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Switch Jinja `Environment` to `undefined=StrictUndefined` so an unpassed template variable raises `UndefinedError` instead of silently rendering an empty string. - Drop `select_autoescape(["html", "j2"])` for the simpler `autoescape=True` since this Environment only ever loads one template. - Extract rendering into a `render_index_html(config)` helper so it's testable without invoking Click. - Add `test_cli.py` covering: meta-tag substitution, HTML escaping of config values, and StrictUndefined raising on missing kwargs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
gadomski
requested changes
May 6, 2026
Collaborator
gadomski
left a comment
There was a problem hiding this comment.
Just one nit on a mostly-useless test file, otherwise LGTM! Thanks for the change, this reads nicer to me 🙇🏼
gadomski
approved these changes
May 6, 2026
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.
Summary
og_url,og_image, andtheme_colorfields toConfig(withtheme_colorfalling back tobranding.primary_color).public/data/config.json.vite.plugin-template-html.ts) that substitutes%PLACEHOLDER%strings inindex.htmlfromconfig.jsonat build time viatransformIndexHtml.index.htmlwith placeholders.This enables downstream forks (e.g.
nasa-odsi-contributor-network) to drop their own copy ofindex.htmland instead override these values via their ownconfig.toml. Prerequisite for the NASA ODSI upstream-reuse cutover.Test plan
uv run pytest— 3 passed (incl. 2 new tests for default values and TOML fallback)uv run ruff check . && uv run ruff format --check . && uv run mypy— cleannpm run typecheck && npm test— 134 passeduv run contributor-network build && npm run build—dist/index.htmlcontains zero%PLACEHOLDER%strings;og:url,og:image,theme-colorpopulatednpm run dev— meta tags substituted in served HTML🤖 Generated with Claude Code