Skip to content

Commit d87ea5f

Browse files
xuekepeiclaude
andcommitted
Adopt four upstream improvements, fixing defects in them
1. meta description (upstream issue Track3#119 — issue only, no PR) The theme never emitted <meta name="description">, so params.description went unused and Lighthouse reported "document does not have a meta description". baseof.html now falls back .Description -> .Summary -> .Site.Params.description. 2. Analytics into head (upstream PR Track3#151) Loads earlier, losing fewer hits from visitors who leave quickly. 3. code-copy with table layout (upstream PR Track3#137) With markup.highlight.lineNos enabled chroma emits a <table> and copying grabs the line numbers too; select only the code cell in that case. 4. Admonition shortcodes (upstream PR Track3#130) Adds note / tip / warning. Four defects in the original PR are fixed: - all three shared one blue border colour, making them indistinguishable -> coloured per semantic - content background used $highlight-grey, ~2.5:1 against $text, below the WCAG AA 4.5:1 minimum -> $light-grey, ~6.5:1 - vertical margins sat on .admonition-content so the left border did not enclose the content -> moved to the container - .Inner abutted the <div>, so CommonMark's HTML block rule skipped inline Markdown parsing and bold/links inside the box stayed literal -> separated by blank lines Also drops $_hugo_config, deprecated since Hugo 0.55. Verified on Hugo v0.164.0+extended: builds with no warnings, all three colours compile, and Markdown inside the boxes renders. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 628833c commit d87ea5f

11 files changed

Lines changed: 108 additions & 2 deletions

File tree

assets/js/code-copy.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@
3636
var codeEl = containerEl.firstElementChild;
3737
copyBtn.addEventListener('click', function() {
3838
try {
39-
var selection = selectText(codeEl);
39+
// 开启 markup.highlight.lineNos 时 chroma 输出 <table>,行号与代码分列两个
40+
// 单元格,直接全选会把行号一起复制。此时只选取代码所在的最后一个单元格。
41+
// 上游 PR #137
42+
var selection;
43+
if (codeEl.firstElementChild instanceof HTMLTableElement) {
44+
selection = selectText(codeEl.firstElementChild.firstElementChild.firstElementChild.lastElementChild);
45+
} else {
46+
selection = selectText(codeEl);
47+
}
4048
document.execCommand('copy');
4149
selection.removeAllRanges();
4250

assets/scss/_admonition.scss

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Admonition(note / tip / warning 提示框)
2+
*
3+
* 基于上游 PR #130,修正三处问题:
4+
* 1. 原实现三种类型共用一个边框色,改为按语义分色
5+
* 2. 原内容底色用 $highlight-grey (#7d828a),与 $text (#e8eef2) 对比度约
6+
* 2.5:1,低于 WCAG AA 的 4.5:1;改用 $light-grey (#494f5c),约 6.5:1
7+
* 3. 原将上下外边距加在 .admonition-content 上,导致左边框无法包住内容;
8+
* 改为加在容器上
9+
*/
10+
11+
.admonition-highlight {
12+
position: relative;
13+
display: block;
14+
margin: 1.6em 0;
15+
border-left: 35px solid;
16+
17+
&.admonition-note {
18+
border-left-color: $admonition-note;
19+
}
20+
21+
&.admonition-tip {
22+
border-left-color: $admonition-tip;
23+
}
24+
25+
&.admonition-warning {
26+
border-left-color: $admonition-warning;
27+
}
28+
}
29+
30+
.admonition-icon {
31+
position: absolute;
32+
top: 10px;
33+
left: -27px;
34+
width: 20px;
35+
fill: $text;
36+
}
37+
38+
.admonition-content {
39+
padding: 0.125em 1em;
40+
overflow-x: auto;
41+
background-color: $light-grey;
42+
43+
// .Inner 渲染出的首尾段落自带 margin,收一收避免上下留白过大
44+
> :first-child {
45+
margin-top: 0.75em;
46+
}
47+
48+
> :last-child {
49+
margin-bottom: 0.75em;
50+
}
51+
}

assets/scss/_predefined.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ $dark-grey: #3B3E48;
77
$highlight-grey: #7d828a;
88
$midnightblue: #2c3e50;
99

10+
// Admonition 左边框配色。上游 PR #130 让 note / tip / warning 共用同一个蓝色,
11+
// 三者视觉上无法区分,这里改为按语义分色。
12+
$admonition-note: #0594cb;
13+
$admonition-tip: $theme;
14+
$admonition-warning: #d9822b;
15+
1016
// Fonts
1117
//
1218
$fonts: "Trebuchet MS", Verdana, "Verdana Ref", "Segoe UI", Candara, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Tahoma, sans-serif;

assets/scss/style.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import "normalize.scss";
33
@import "syntax.scss";
44
@import "animate.scss";
5+
@import "admonition.scss";
56

67
/* Webkit Scrollbar Customize */
78
::-webkit-scrollbar {

layouts/_default/baseof.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
{{- /* 统计脚本置于 head 顶部,尽早加载以减少访客快速离开时的漏统计(上游 PR #151) */}}
9+
{{- partial "analytics.html" . }}
10+
{{- /* 标准 meta description:文章取自身摘要,其余页面回退到 site 的 description(上游 issue #119) */}}
11+
{{- with or .Description .Summary .Site.Params.description }}
12+
<meta name="description" content="{{ . | plainify | chomp | truncate 150 }}">
13+
{{- end }}
814
{{- with .Site.Params.themeColor }}
915
<meta name="theme-color" content="{{.}}">
1016
<meta name="msapplication-TileColor" content="{{.}}">
@@ -41,7 +47,6 @@
4147
<script src="{{ $script.Permalink }}" {{ printf "integrity=%q" $script.Data.Integrity | safeHTMLAttr }} crossorigin="anonymous"></script>
4248
{{ end }}
4349

44-
{{- partial "analytics.html" . }}
4550
{{- if templates.Exists "partials/extra-foot.html" -}}
4651
{{ partial "extra-foot.html" . }}
4752
{{- end }}
Lines changed: 1 addition & 0 deletions
Loading

layouts/partials/svg/lightbulb.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

layouts/shortcodes/note.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- /* 请以百分号形式调用(note ... /note),使内部内容按 Markdown 渲染。
2+
.Inner 前后必须留空行且不可缩进:紧贴 HTML 标签时 goldmark 会按
3+
CommonMark 的 HTML block 规则跳过行内 Markdown 解析,缩进四格则会被
4+
当成代码块。上游 PR #130 缺少这两个空行,note 内的加粗与链接不生效。 */ -}}
5+
<aside class="admonition-highlight admonition-note">
6+
<div class="admonition-icon">{{ partial "svg/sticky-note.svg" }}</div>
7+
<div class="admonition-content">
8+
9+
{{ .Inner }}
10+
11+
</div>
12+
</aside>

layouts/shortcodes/tip.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{- /* 请以百分号形式调用(tip ... /tip)。.Inner 前后的空行不可省略,
2+
原因见 note.html 的说明。 */ -}}
3+
<aside class="admonition-highlight admonition-tip">
4+
<div class="admonition-icon">{{ partial "svg/lightbulb.svg" }}</div>
5+
<div class="admonition-content">
6+
7+
{{ .Inner }}
8+
9+
</div>
10+
</aside>

0 commit comments

Comments
 (0)