Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions content/docs/customize/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ capabilities:
- { class: ok, prefix: '✓ ', text: listening on :5433 }
```

For a terminal session, use `lines` to colour the prompt or status prefix of
each line. With the development theme, paste a source snippet into a YAML
block string and set `lang` to its language. Omit `lang` for plain text.

```yaml {title="data/home/en.yaml"}
visual:
type: code
title: Python
lang: python
code: |
import acme
db = acme.connect("localhost:5433")
```

> [!DETAILS] Minimal YAML for eleven more sections
>
> ```yaml
Expand Down
13 changes: 13 additions & 0 deletions content/docs/customize/home.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ capabilities:
- { class: ok, prefix: '✓ ', text: 正在监听 :5433 }
```

展示终端会话时,用 `lines` 为每行的提示符或状态前缀上色。使用开发版主题时,可以把整段源码贴进
`code` 的 YAML 文本块,填写语言 `lang` 即可高亮。省略 `lang` 时按纯文本展示。

```yaml {title="data/home/zh.yaml"}
visual:
type: code
title: Python
lang: python
code: |
import acme
db = acme.connect("localhost:5433")
```

> [!DETAILS] 另外十一种分区的最小 YAML
>
> ```yaml
Expand Down
2 changes: 1 addition & 1 deletion content/docs/design/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ as `css/<name>.css`. An unknown name warns.
| `main` | Every theme page; 123 layers. `head-css.html` publishes it as `css/main.css`, or minified, fingerprinted and with an integrity attribute in production |
| `redoc.css` | Pages that register ReDoc. It is the single file `assets/css/td/redoc.css`, outside the layer lists, published the same way as `css/redoc.css` |
| `chrome` | A site-owned shell that does not load `main`: tokens, typography, the six palettes, the site navbar, and the language, theme and appearance controls |
| `landing` | Landing sections for a site-owned shell, loaded after `chrome`. It repeats the palettes, because they restyle Landing sections at equal specificity and must follow them |
| `landing` | Landing sections for a site-owned shell, loaded after `chrome`. The development version includes the dark Chroma palette for source panels. The visual presets follow the sections so their equal-specificity overrides take effect |
| `search`, `compare` | The command palette with local search, and Duo View, for a site-owned shell |

The four smaller stylesheets have no source of their own: each lists layers
Expand Down
2 changes: 1 addition & 1 deletion content/docs/design/architecture.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Bootstrap 组件拆分:其中带有主题的调色板,与某条 Bootstrap
| `main` | 所有主题页面,共 123 层。`head-css.html` 把它发布为 `css/main.css`;生产构建中压缩、加指纹并带完整性属性 |
| `redoc.css` | 登记了 ReDoc 的页面。它是单独的一个文件 `assets/css/td/redoc.css`,不在各层清单之内,按同样方式发布为 `css/redoc.css` |
| `chrome` | 不加载 `main` 的站点自有外壳:令牌、排版、六套配色、站点导航栏,以及语言、明暗与外观控件 |
| `landing` | 站点自有外壳使用的 Landing 区块,在 `chrome` 之后加载。它重复了配色规则,因为配色以同等优先级改写 Landing 区块,必须排在其后 |
| `landing` | 站点自有外壳使用的 Landing 区块,在 `chrome` 之后加载。开发版为源码面板附带 Chroma 深色语法配色。视觉预设排在区块规则之后,以便同等优先级的覆盖生效 |
| `search`、`compare` | 站点自有外壳使用的命令面板与本地搜索,以及双列视图 |

四份较小的样式表没有自己的源码:它们列出的每一层 `main` 也都加载。站点布局
Expand Down
17 changes: 12 additions & 5 deletions content/docs/design/landing.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,18 @@ Server output stays complete without JavaScript or if the Landing script fails t
Reveal candidates are initially visible; only an installed observer may mark one as pending entrance animation.
The server renders metrics with configured number formatting, prefixes, and suffixes, and the count-up's final frame uses the same display.

Landing code plates accept keyboard focus in interactive HTML, including
`capabilities` code visuals and `code-plate` line lists. Readers can tab to long
lines and scroll them with arrow keys without relying on a browser's implicit
scroll-container focus behavior. Static Print output adds no focus target to
these line-based renderers.
In interactive HTML, readers can tab to a `capabilities` or `code-plate` code
panel and use the arrow keys to scroll long lines. In the static Print output
both panels show the source as plain text and stay out of the tab order.

The development version adds `code` to the `capabilities` code visual alongside
the `lines` form available in 1.8.0. Choose exactly one. Use
`lines` for per-line prefixes or a nonblank `code` string for source highlighted
by Hugo at build time. Both the full theme and the `chrome` plus `landing`
stylesheets provide the dark syntax palette. The optional `lang` defaults to
`text`. A non-string language warns and uses plain text. Missing or conflicting
inputs and blank or non-string source warn and drop the visual. The item keeps
its title, text and links.

Marquee duplication uses only CSS. The duplicate is `aria-hidden` and `inert`.
A localized checkbox preserves pause state without JS.
Expand Down
12 changes: 8 additions & 4 deletions content/docs/design/landing.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ i18n。
出现动画的候选元素默认可见,只有成功安装观察器后才标记为等待动画。数字指标
由服务端按配置输出完整的数字格式、前缀和后缀,递增动画的最后一帧使用同一显示文本。

交互式 HTML 中的代码面板可通过键盘聚焦,包括 `capabilities` 的代码视图与
`code-plate` 的逐行代码。读者可以用 Tab 进入长行区域,再用方向键滚动,不依赖
浏览器自动把滚动容器加入焦点顺序。这两种逐行渲染器不为静态 Print 输出添加
焦点入口。
在交互式 HTML 中,读者可以用 Tab 聚焦 `capabilities` 或 `code-plate` 的代码面板,
再用方向键横向滚动长行。静态 Print 输出以纯文本显示源码,代码面板不占用 Tab 焦点。

开发版在 1.8.0 已有的 `lines` 之外,为 `capabilities` 代码面板增加了 `code`,两种写法二选一。用 `lines` 给每行的前缀上色,
用非空白的 `code` 字符串展示由 Hugo 在构建时高亮的源码。完整主题和仅加载
`chrome`、`landing` 样式表的站点外壳都提供深色语法配色。可选的 `lang` 默认是
`text`,类型有误时告警并按纯文本展示。两个输入都没填、同时填写,或 `code` 为空白
或非字符串时,构建会告警并略过该面板,条目的标题、文字和链接照常显示。

跑马灯只用 CSS 复制;副本带 `aria-hidden` 与 `inert`,本地化复选框无需
JavaScript 也能持久保存暂停状态。减少动画会停用动画,强制颜色保留控件,主题
Expand Down
61 changes: 58 additions & 3 deletions tests/browser/landing-code-focus.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect, test } from '@playwright/test';

const regions = [
['#capability-code', 'h3 a'],
['#syntax-code', 'h3 a'],
['#plain-lines', 'h2 a'],
['#highlighted-code', 'h2 a'],
];
Expand Down Expand Up @@ -42,12 +43,66 @@ for (const width of [360, 1440]) {
}

for (const language of ['', '/zh']) {
test(`${language || '/en'} Print line renderers remain static`, async ({ page }) => {
test(`${language || '/en'} Print code panels remain static`, async ({ page }) => {
await page.goto(`${language}/_print/tests/landing-code-focus/`);
for (const selector of ['#capability-code pre', '#plain-lines pre']) {
const pre = page.locator(selector);
for (const [selector] of regions) {
const pre = page.locator(selector).locator('pre');
await expect(pre).toHaveCount(1);
await expect(pre).not.toHaveAttribute('tabindex');
}
await expect(page.locator('#syntax-code pre code')).toContainText('import pystac\ncatalog =');
await page.emulateMedia({ media: 'print' });
const ink = await page.locator('#syntax-code pre code').evaluate(el => ({
text: getComputedStyle(el).color,
paper: getComputedStyle(el.closest('.td-landing-codeplate')).backgroundColor,
fits: el.parentElement.scrollWidth <= el.parentElement.clientWidth + 1,
}));
expect(contrastRatio(ink.text, ink.paper)).toBeGreaterThanOrEqual(4.5);
expect(ink.fits).toBe(true);
});
}

for (const route of ['landing-code-focus', 'landing-code-shell']) {
test(`${route} keeps syntax colours distinct and readable`, async ({ page }) => {
await page.goto(`/tests/${route}/`);
if (route === 'landing-code-shell') {
const styles = await page.locator('link[rel="stylesheet"]').evaluateAll(links =>
links.map(link => new URL(link.href).pathname));
expect(styles).toEqual(['/css/chrome.css', '/css/landing.css']);
}
const plate = page.locator('#syntax-code .td-landing-codeplate');
await expect(plate.locator('.kn')).toHaveText('import');
for (const preset of ['paper', 'slate', 'github', 'ink', 'news', 'terminal']) {
for (const mode of ['light', 'dark']) {
const { keyword, name, string, background } = await plate.evaluate((el, appearance) => {
document.documentElement.dataset.tdPreset = appearance.preset;
document.documentElement.dataset.bsTheme = appearance.mode;
const colour = selector => getComputedStyle(el.querySelector(selector)).color;
return {
keyword: colour('.kn'), name: colour('.n'), string: colour('.s2'),
background: getComputedStyle(el).backgroundColor,
};
}, { preset, mode });
const context = `${preset}/${mode}`;
expect(new Set([keyword, name, string]).size, context).toBe(3);
for (const ink of [keyword, name, string]) {
expect(contrastRatio(ink, background), `${context} ${ink} on ${background}`).toBeGreaterThanOrEqual(4.5);
}
}
}
});
}

function contrastRatio(foreground, background) {
function luminance(rgb) {
const [, red, green, blue] = /^rgb\((\d+), (\d+), (\d+)\)$/.exec(rgb);
const linear = channel => {
const value = Number(channel) / 255;
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
};
return 0.2126 * linear(red) + 0.7152 * linear(green) + 0.0722 * linear(blue);
}
const a = luminance(foreground);
const b = luminance(background);
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
}
12 changes: 12 additions & 0 deletions tests/fixtures/browser/content/landing-code-focus.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ sections:
title: Capability code
lines:
- {prefix: '$ ', text: 'python3 -m http.server 8080 --bind 127.0.0.1 --directory /srv/repo --package-snapshot stable-2026-10-15 --manifest /srv/repo/snapshots/current/verified-package-manifest.json'}
- type: capabilities
id: syntax-code
data:
items:
- title: '[Source example](#syntax-code)'
visual:
type: code
title: Python
lang: python
code: |
import pystac
catalog = pystac.Catalog.from_file("https://example.org/archives/observations/weather-models/global-forecast-system/reference-runs/2026/11/catalog.json")
- type: code-plate
id: plain-lines
data:
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/browser/content/landing-code-focus.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ sections:
title: 能力区块代码
lines:
- {prefix: '$ ', text: 'python3 -m http.server 8080 --bind 127.0.0.1 --directory /srv/repo --package-snapshot stable-2026-10-15 --manifest /srv/repo/snapshots/current/verified-package-manifest.json'}
- type: capabilities
id: syntax-code
data:
items:
- title: '[源码示例](#syntax-code)'
visual:
type: code
title: Python
lang: python
code: |
import pystac
catalog = pystac.Catalog.from_file("https://example.org/archives/observations/weather-models/global-forecast-system/reference-runs/2026/11/catalog.json")
- type: code-plate
id: plain-lines
data:
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/browser/content/landing-code-shell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Landing code in a custom shell
layout: landing-code-shell
outputs: [HTML]
search_exclude: true
---
17 changes: 17 additions & 0 deletions tests/fixtures/browser/layouts/landing-code-shell.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="{{ .Language.Lang }}" data-td-preset="paper">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ .Title }}</title>
{{ range slice "chrome" "landing" }}{{ with partial "css/bundle.html" . }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}{{ end }}
</head>
<body>
<main>
{{ with site.GetPage "/tests/landing-code-focus" }}{{ partial "landing/render.html"
(dict "page" $ "data" (partial "landing/data.html" .)) }}{{ end }}
</main>
</body>
</html>