Skip to content

feat: template index.html meta tags via Jinja from the Python build#131

Merged
aboydnw merged 9 commits into
mainfrom
feat/index-html-templating
May 6, 2026
Merged

feat: template index.html meta tags via Jinja from the Python build#131
aboydnw merged 9 commits into
mainfrom
feat/index-html-templating

Conversation

@aboydnw
Copy link
Copy Markdown
Member

@aboydnw aboydnw commented May 5, 2026

Summary

  • Adds og_url, og_image, and theme_color fields to Config (with theme_color falling back to branding.primary_color).
  • Emits the new fields into public/data/config.json.
  • Adds a Vite plugin (vite.plugin-template-html.ts) that substitutes %PLACEHOLDER% strings in index.html from config.json at build time via transformIndexHtml.
  • Replaces the hardcoded SEO meta tags in index.html with placeholders.

This enables downstream forks (e.g. nasa-odsi-contributor-network) to drop their own copy of index.html and instead override these values via their own config.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 — clean
  • npm run typecheck && npm test — 134 passed
  • uv run contributor-network build && npm run builddist/index.html contains zero %PLACEHOLDER% strings; og:url, og:image, theme-color populated
  • npm run dev — meta tags substituted in served HTML

🤖 Generated with Claude Code

aboydnw and others added 6 commits May 5, 2026 21:23
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>
@aboydnw aboydnw requested a review from gadomski as a code owner May 5, 2026 21:27
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

@aboydnw aboydnw marked this pull request as draft May 5, 2026 21:30
@aboydnw
Copy link
Copy Markdown
Member Author

aboydnw commented May 5, 2026

@gadomski I converted to draft, I haven't reviewed this yet

Copy link
Copy Markdown
Collaborator

@gadomski gadomski left a comment

Choose a reason for hiding this comment

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

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.

Comment thread vite.plugin-template-html.ts Outdated
aboydnw and others added 2 commits May 5, 2026 21:46
…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>
@aboydnw aboydnw changed the title feat: template index.html meta tags from config.toml feat: template index.html meta tags via Jinja from the Python build May 5, 2026
@aboydnw aboydnw marked this pull request as ready for review May 5, 2026 22:44
@aboydnw aboydnw requested a review from gadomski May 5, 2026 22:44
Copy link
Copy Markdown
Collaborator

@gadomski gadomski left a comment

Choose a reason for hiding this comment

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

Just one nit on a mostly-useless test file, otherwise LGTM! Thanks for the change, this reads nicer to me 🙇🏼

Comment thread python/tests/test_cli.py Outdated
@aboydnw aboydnw requested a review from gadomski May 6, 2026 15:17
@aboydnw aboydnw merged commit 48eaebf into main May 6, 2026
3 checks passed
@aboydnw aboydnw deleted the feat/index-html-templating branch May 6, 2026 15:25
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.

2 participants