From cfe85f9b16a54ecd4c7b035f9253d558acbb4d3e Mon Sep 17 00:00:00 2001 From: fukunee Date: Sun, 15 Nov 2026 10:04:32 +0800 Subject: [PATCH] Add margin notes: Tufte-style side notes with dashed inline fallback --- assets/css/custom.css | 91 ++++++++++++++++++++++++++ content/blog/prolog-pokemon.md | 10 +-- layouts/_partials/custom/head-end.html | 5 ++ layouts/blog/single.html | 9 ++- layouts/shortcodes/note.html | 9 +++ static/js/notes.js | 72 ++++++++++++++++++++ 6 files changed, 188 insertions(+), 8 deletions(-) create mode 100644 layouts/shortcodes/note.html create mode 100644 static/js/notes.js diff --git a/assets/css/custom.css b/assets/css/custom.css index db53604..259b441 100644 --- a/assets/css/custom.css +++ b/assets/css/custom.css @@ -223,3 +223,94 @@ html.dark #post-list .post-card:hover { #post-list .blog-post-item { margin-bottom: 1rem; } + +/* ===== 注释(边注):宽屏显示在两侧留白,窄屏虚线框内嵌 ===== */ +.post-note-mark { + font-size: 0.7em; + line-height: 0; + vertical-align: super; + margin-left: 0.1em; + color: #2563eb; + font-weight: 600; +} + +.dark .post-note-mark { + color: #60a5fa; +} + +/* 窄屏 / 无 JS:虚线框内嵌在正文中 */ +.post-note { + display: block; + margin: 0.5rem 0; + padding: 0.5rem 0.75rem; + border: 1px dashed #cbd5e1; + border-radius: 0.375rem; + font-size: 0.85rem; + line-height: 1.65; + color: #6b7280; +} + +.dark .post-note { + border-color: #404040; + color: #9ca3af; +} + +/* 宽屏:由 notes.js 接管,放进正文两侧的留白 */ +@media (min-width: 80rem) { + /* 去掉 TOC / 侧栏占位后,把正文栏收回原来的阅读宽度,两侧留给注释 */ + main.notes-page { + max-width: 52rem; + margin-left: auto; + margin-right: auto; + } + + html.js .post-note { + display: none; + } + + html.js main.notes-page.notes-active { + position: relative; + } + + html.js main.notes-page.notes-active .post-note.placed { + display: block; + position: absolute; + width: 12rem; + margin: 0; + padding: 0 0.75rem; + border: 0 solid #e5e7eb; + border-radius: 0; + background: none; + font-size: 0.8125rem; + line-height: 1.65; + color: #6b7280; + } + + html.dark.js main.notes-page.notes-active .post-note.placed { + color: #9ca3af; + border-color: #333; + } + + /* 注释靠在正文哪一侧,就在朝向正文的那边加一条细线 */ + html.js main.notes-page.notes-active .post-note.placed[data-side="right"] { + left: calc(100% + 1rem); + right: auto; + border-left-width: 2px; + } + + html.js main.notes-page.notes-active .post-note.placed[data-side="left"] { + right: calc(100% + 1rem); + left: auto; + border-right-width: 2px; + } +} + +@media print { + .post-note { + display: block !important; + position: static !important; + width: auto !important; + border: 1px dashed #999 !important; + padding: 0.5rem 0.75rem !important; + } +} diff --git a/content/blog/prolog-pokemon.md b/content/blog/prolog-pokemon.md index 5ac7e03..9a797ac 100644 --- a/content/blog/prolog-pokemon.md +++ b/content/blog/prolog-pokemon.md @@ -74,7 +74,7 @@ pokemon(wartortle). pokemon(blastoise). ``` -在 Prolog 中,我们声明"谓词"(Predicate)。谓词定义关系:`bulbasaur` 是一个 `pokemon`,`charmander` 是一个 `pokemon`,以此类推。我们称这个谓词为 `pokemon/1`,因为它有一个参数。 +在 Prolog 中,我们声明"谓词"(Predicate)。谓词定义关系:`bulbasaur` 是一个 `pokemon`,`charmander` 是一个 `pokemon`,以此类推。我们称这个谓词为 `pokemon/1`,因为它有一个参数。{{< note >}}斜杠后面的数字是**元数**(arity),表示参数个数。`pokemon/1` 和 `pokemon/2` 在 Prolog 里是两个完全不同的谓词,可以同时存在。{{< /note >}} 这些事实被加载到一个交互式提示符——"顶层"(top-level)中。你输入一个语句到提示符,Prolog 试图找出所有使该语句为真的方式: @@ -113,7 +113,7 @@ type(blastoise, water). false. ``` -Prolog 中首字母大写的名字是**变量**。Prolog 尝试将谓词与变量的所有可能匹配进行"合一": +Prolog 中首字母大写的名字是**变量**。{{< note >}}变量也可以写成 `_` 开头,单独的 `_` 是匿名变量,每个 `_` 都互不相同,用来占位而不关心取值。{{< /note >}}Prolog 尝试将谓词与变量的所有可能匹配进行"合一": ``` ?- type(squirtle, Type). @@ -128,7 +128,7 @@ Prolog 中首字母大写的名字是**变量**。Prolog 尝试将谓词与变 ; Type = poison. ``` -分号 `;` 表示"或"。任何参数都可以是变量,这意味着我们可以从任意方向提问。所有草属性宝可梦有哪些?只需把第一个参数设为变量: +分号 `;` 表示"或"。{{< note >}}顶层不会一次性给出所有答案:按回车只得到第一个解,输入 `;`(或空格)才会回溯继续找下一个。{{< /note >}}任何参数都可以是变量,这意味着我们可以从任意方向提问。所有草属性宝可梦有哪些?只需把第一个参数设为变量: ``` ?- type(Pokemon, grass). @@ -168,7 +168,7 @@ Iron Bundle 是一只水/冰属性宝可梦,特攻很高。具体多高? ; ... ``` -Freeze-Dry 是一个特别好的特殊招式。找出所有特攻大于 120、会 Freeze-Dry 的冰属性宝可梦: +Freeze-Dry 是一个特别好的特殊招式。找出所有特攻大于 120、会 Freeze-Dry 的冰属性宝可梦:{{< note >}}`#>` 是约束求解库里的比较,作用在变量上;普通 `>` 只能用于已实例化的数值,在变量上会报错。{{< /note >}} ``` ?- pokemon_spa(Pokemon, SpA), SpA #> 120, learns(Pokemon, freezedry), type(Pokemon, ice). @@ -178,7 +178,7 @@ Freeze-Dry 是一个特别好的特殊招式。找出所有特攻大于 120、 ; Pokemon = ironbundle, SpA = 124. ``` -最后一个概念:**规则**(Rules)。规则有头部和主体,如果主体为真,则规则合一: +最后一个概念:**规则**(Rules)。规则有头部和主体,如果主体为真,则规则合一:{{< note >}}`:-` 读作"如果",逗号是"并且",分号是"或者"。规则的顺序会影响求解效率和回溯顺序。{{< /note >}} ```prolog damaging_move(Move) :- diff --git a/layouts/_partials/custom/head-end.html b/layouts/_partials/custom/head-end.html index 462ff11..e6efbd3 100644 --- a/layouts/_partials/custom/head-end.html +++ b/layouts/_partials/custom/head-end.html @@ -1,3 +1,8 @@ + +