Hang margin notes on the title and keep each to one paragraph
This commit is contained in:
@@ -14,7 +14,8 @@
|
||||
<h1
|
||||
class="hx:text-center hx:mt-2 hx:text-4xl hx:font-bold hx:tracking-tight hx:text-slate-900 hx:dark:text-slate-100"
|
||||
>
|
||||
{{ .Title }}
|
||||
{{ .Title }}{{ with .Params.titleNote }}{{ partial "note.html" (dict "page" $
|
||||
"title" true "class" "" "inner" .) }}{{ end }}
|
||||
</h1>
|
||||
<div class="hx:mb-16"></div>
|
||||
{{ end }}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
{{- /*
|
||||
边注的渲染核心:短代码 {{< note >}} 与标题边注(front matter 的 titleNote)共用。
|
||||
|
||||
参数:
|
||||
page —— 页面(.Page / .),用于 Store 编号与 RenderString
|
||||
class —— "cite" 表示书目边注,一行一项;留空则按普通注释渲染
|
||||
title —— 为 true 时挂在 h1 上,固定编 1 号,不占正文计数
|
||||
inner —— 内容,Markdown 或裸 HTML
|
||||
|
||||
约束:inner 按 inline 渲染,一旦分成两段,goldmark 会产出 <p>,
|
||||
塞进 <span class="post-note"> 里属于非法嵌套,浏览器会提前闭合 span,
|
||||
卡片宽度与高度归零、notes.js 的定位与折线随之失效。
|
||||
所以内容必须写成一整段;需要分行时用 <br /> 或 <span class="note-line">。
|
||||
*/ -}}
|
||||
{{- $page := .page -}}
|
||||
{{- $class := .class | default "" -}}
|
||||
{{- $inner := .inner -}}
|
||||
{{- $isTitle := .title | default false -}}
|
||||
{{- $n := 1 -}}
|
||||
{{- if not $isTitle -}}
|
||||
{{- $count := add ($page.Store.Get "noteCount" | default 0) 1 -}}
|
||||
{{- $page.Store.Set "noteCount" $count -}}
|
||||
{{- $n = add $count (cond (ne ($page.Params.titleNote | default "") "") 1 0) -}}
|
||||
{{- end -}}
|
||||
<span class="post-note-anchor" aria-hidden="true"></span><sup class="post-note-mark">{{ $n }}</sup><span class="post-note{{ with $class }} {{ . }}{{ end }}"><span class="post-note-num">{{ $n }}</span>{{- with $inner -}}
|
||||
{{- if eq $class "cite" -}}
|
||||
{{- range split (trim . "\r\n") "\n" -}}
|
||||
{{- $line := trim . "\r" -}}
|
||||
{{- if ne (trim $line " ") "" -}}<span class="note-line">{{ $line | $page.RenderString (dict "display" "inline") }}</span>{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- . | $page.RenderString (dict "display" "inline") -}}
|
||||
{{- end -}}
|
||||
{{- end -}}</span>
|
||||
@@ -17,7 +17,8 @@
|
||||
<h1
|
||||
class="post-title hx:mb-0"
|
||||
>
|
||||
{{ .Title }}
|
||||
{{ .Title }}{{ with .Params.titleNote }}{{ partial "note.html" (dict "page" $
|
||||
"title" true "class" "" "inner" .) }}{{ end }}
|
||||
</h1>
|
||||
{{ partial "components/page-context-menu" . }}
|
||||
</div>
|
||||
|
||||
@@ -4,18 +4,6 @@
|
||||
窄屏:以虚线框内嵌在文章中。
|
||||
用法:{{< note >}}注释内容{{< /note >}}
|
||||
书目:{{< note cite >}}每行一项,各占一行{{< /note >}}
|
||||
渲染逻辑在 layouts/_partials/note.html,标题边注(titleNote)共用同一套。
|
||||
*/ -}}
|
||||
{{- $class := .Get 0 | default "" -}}
|
||||
{{- $page := .Page -}}
|
||||
{{- $n := add ($page.Store.Get "noteCount" | default 0) 1 -}}
|
||||
{{- $page.Store.Set "noteCount" $n -}}
|
||||
<span class="post-note-anchor" aria-hidden="true"></span><sup class="post-note-mark">{{ $n }}</sup><span class="post-note{{ with $class }} {{ . }}{{ end }}"><span class="post-note-num">{{ $n }}</span>{{- with .Inner -}}
|
||||
{{- if eq $class "cite" -}}
|
||||
{{- range split (trim . "\r\n") "\n" -}}
|
||||
{{- $line := trim . "\r" -}}
|
||||
{{- if ne (trim $line " ") "" -}}<span class="note-line">{{ $line | $page.RenderString (dict "display" "inline") }}</span>{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- . | $page.RenderString (dict "display" "inline") -}}
|
||||
{{- end -}}
|
||||
{{- end -}}</span>
|
||||
{{- partial "note.html" (dict "page" .Page "class" (.Get 0 | default "") "inner" .Inner) -}}
|
||||
Reference in New Issue
Block a user