From b3c92dc17d7de3b7362aebe4ecabbb0c275075aa Mon Sep 17 00:00:00 2001 From: Han Xiao Date: Mon, 30 Nov 2026 22:15:29 +0900 Subject: [PATCH 1/2] feat(landing): highlight capabilities code visuals with code and lang Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01E5Vqiif7kfNNiDDMaM1B6r --- CHANGELOG.md | 9 +++++ assets/css/td/landing.css | 4 +- bin/check-landing.py | 38 +++++++++++++++++++ .../landing/sections/capabilities.html | 11 +++++- 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 429091ab..2f376596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ sites keep the `github.com/pgsty/oink` module path instead of moving to a `/v2` path. Version 1.6.0 retired several in this way, and 1.8.0 replaces the `social` shortcode of 1.7.0 with a callout. A patch release only fixes. +## Unreleased + +### Added + +- **Highlighted `capabilities` code visuals.** A `visual.type: code` panel + takes `code` and `lang` as `code-plate` does, and Chroma highlights it. + `lines` keeps its per-line prefix colours. A visual with both or neither + warns and is dropped, so the item keeps its text. + ## [1.8.0] — 2026-11-28 Paper looks as it did in 1.6.0 again. Its 1.7.0 refresh grows into a preset diff --git a/assets/css/td/landing.css b/assets/css/td/landing.css index 0d0b65ad..bcbb5f04 100644 --- a/assets/css/td/landing.css +++ b/assets/css/td/landing.css @@ -2185,7 +2185,9 @@ } .td-landing-code-plate-section .td-landing-codeplate .highlight, -.td-landing-code-plate-section .td-landing-codeplate .chroma { +.td-landing-code-plate-section .td-landing-codeplate .chroma, +.td-landing-capabilities .td-landing-codeplate .highlight, +.td-landing-capabilities .td-landing-codeplate .chroma { margin: 0; border: 0; background: transparent; diff --git a/bin/check-landing.py b/bin/check-landing.py index e8a93e5a..420b6001 100755 --- a/bin/check-landing.py +++ b/bin/check-landing.py @@ -372,6 +372,8 @@ def create_site(root: Path, landing_data: str, *, language: str = "en") -> None: ("zero-capabilities-columns", "sections:\n - type: capabilities\n data:\n items:\n - title: Bad\n visual:\n type: components\n columns: 0\n items: [{title: A, icon: fa-solid fa-star}]\n", "capabilities visual columns must be at least 1"), ("bad-capabilities-rules", "sections:\n - type: capabilities\n data:\n items:\n - title: Bad\n visual:\n type: shell\n rules: not-a-list\n", "rules must be an array"), ("bad-capabilities-rule-width", "sections:\n - type: capabilities\n data:\n items:\n - title: Bad\n visual:\n type: shell\n rules: ['88%', 'nope']\n", "is not a CSS length"), + ("capabilities-code-and-lines", "sections:\n - type: capabilities\n data:\n items:\n - title: Bad\n visual:\n type: code\n lang: python\n code: print(1)\n lines: [{text: print(1)}]\n", "code visual requires exactly one of code or lines"), + ("capabilities-code-empty", "sections:\n - type: capabilities\n data:\n items:\n - title: Bad\n visual: {type: code, title: Empty}\n", "code visual requires exactly one of code or lines"), ("bad-marquee-rows", "sections:\n - type: logo-wall\n data:\n layout: marquee\n rows: nope\n items: [{title: Logo}]\n", 'marquee rows "nope" is not a whole number'), ) @@ -648,6 +650,41 @@ def check_code_focus(hugo: str) -> list[str]: return errors +def check_capabilities_highlight(hugo: str) -> list[str]: + """A capabilities code visual with `code` goes through Chroma, as code-plate does.""" + errors: list[str] = [] + data = """sections: + - type: capabilities + data: + items: + - title: Python + visual: + type: code + title: Python + lang: python + code: | + import pystac + cat = pystac.Catalog.from_file("catalog.json") +""" + with tempfile.TemporaryDirectory(prefix="td-landing-capabilities-highlight-") as temp: + site = Path(temp) + create_site(site, data) + result = run(hugo, site) + if result.returncode != 0: + return [f"capabilities highlight fixture failed: {result.stdout}{result.stderr}"] + source = (site / "public/test/index.html").read_text(encoding="utf-8") + module = source[source.find("td-landing-capabilities"):] + require('class="chroma"' in module, + "capabilities code visual with code was not highlighted", errors) + require('data-lang="python"' in module or "language-python" in module, + "capabilities code visual lost its language", errors) + require('import' in module, + "capabilities code visual lost its Chroma tokens", errors) + require("must not be empty" not in result.stdout + result.stderr, + "capabilities code visual warned on non-empty code", errors) + return errors + + def check_rss(hugo: str) -> list[str]: errors: list[str] = [] with tempfile.TemporaryDirectory(prefix="td-landing-components-landing-rss-") as temp: @@ -877,6 +914,7 @@ def main() -> int: + check_rss(args.hugo) + check_markdown_scopes(args.hugo) + check_code_focus(args.hugo) + + check_capabilities_highlight(args.hugo) + check_capabilities_preset_buttons(args.hugo) ) if errors: diff --git a/layouts/_partials/landing/sections/capabilities.html b/layouts/_partials/landing/sections/capabilities.html index 22a8c84d..0939dcd4 100644 --- a/layouts/_partials/landing/sections/capabilities.html +++ b/layouts/_partials/landing/sections/capabilities.html @@ -30,10 +30,19 @@

{{- if not (in (slice "code" "shell" "components" "image" "card") $visualType) -}} {{- warnf "%s: capabilities item %d has unsupported visual.type %q; dropping the visual" $page.Path (add $index 1) $visualType -}} {{- end -}} - {{- if eq $visualType "code" }} + {{- $hasCode := isset . "code" -}}{{- $hasLines := isset . "lines" -}} + {{- if and (eq $visualType "code") (eq $hasCode $hasLines) -}} + {{- warnf "%s: capabilities item %d code visual requires exactly one of code or lines; dropping the visual" $page.Path (add $index 1) -}} + {{- else if eq $visualType "code" }}
{{ .title }}
+ {{- if $hasCode }} + {{- $code := strings.TrimRight "\r\n" (printf "%v" .code) -}}{{- if not $code }}{{ warnf "%s: capabilities item %d visual.code must not be empty; rendering an empty plate" $page.Path (add $index 1) }}{{ end -}} + {{- $lang := strings.TrimSpace (printf "%v" (.lang | default "text")) -}} + {{- transform.Highlight $code $lang (dict "noClasses" false) -}} + {{- else }} {{ partial "landing/code-lines.html" (dict "lines" .lines "position" (printf "%s: capabilities item %d visual" $page.Path (add $index 1))) }} + {{- end }}
{{- else if eq $visualType "shell" }}