diff options
| author | eltrac <hi@eltr.ac> | 2026-05-13 15:02:52 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-05-13 15:02:52 +0800 |
| commit | c1ed09c61fc2390fc29c5e70fe703a96339766ab (patch) | |
| tree | d4cbba305e82b52f1a4dff34603e4e41bfe5042b | |
| parent | d221c0f109bda63f72e0abe64fa7745a21c23744 (diff) | |
refactor(partial): replace partial items/post with view_postblock
| -rw-r--r-- | assets/css/_markdown.scss | 6 | ||||
| -rw-r--r-- | layouts/_partials/home/latest-posts.html | 11 | ||||
| -rw-r--r-- | layouts/_partials/items/post.html | 41 | ||||
| -rw-r--r-- | layouts/view_postblock.html | 31 | ||||
| -rw-r--r-- | layouts/view_postblock_summary.html | 14 |
5 files changed, 58 insertions, 45 deletions
diff --git a/assets/css/_markdown.scss b/assets/css/_markdown.scss index 11d0400..e2f0ce9 100644 --- a/assets/css/_markdown.scss +++ b/assets/css/_markdown.scss @@ -297,3 +297,9 @@ .webmention-body { .h-cite { display: none } } + +.post-summary { + p:first-child { + margin-top: 0 + } +} diff --git a/layouts/_partials/home/latest-posts.html b/layouts/_partials/home/latest-posts.html index ac01511..6115cac 100644 --- a/layouts/_partials/home/latest-posts.html +++ b/layouts/_partials/home/latest-posts.html @@ -1,11 +1,14 @@ <!-- Latest Posts --> <section class="pagefind-exclude flex flex-col my-4"> {{ $firstPost := true }} + {{ range first 12 (where site.RegularPages "Type" "in" site.Params.mainSections) }} - {{ partial "items/post" (dict - "ctx" . - "showSummary" $firstPost - ) }} + {{ if $firstPost }} + {{ .Render "view_postblock_summary" }} + {{ else }} + {{ .Render "view_postblock" }} + {{ end }} + {{ $firstPost = false }} {{ end }} </section> diff --git a/layouts/_partials/items/post.html b/layouts/_partials/items/post.html deleted file mode 100644 index 5527ea6..0000000 --- a/layouts/_partials/items/post.html +++ /dev/null @@ -1,41 +0,0 @@ -{{ $ctx := .ctx }} -{{ $showSummary := .showSummary }} -<div class="posts-item w-full my-2" - style="view-transition-name: post-{{ .ctx.File.UniqueID }}"> - <header class="w-full md:flex md:justify-between"> - <div> - <p class="font-mono text-secondary"> - <time>{{ .ctx.Date.Format "January 2" }},</time> - <span>in <a href="/{{ .ctx.Section }}/">{{ .ctx.Section }}</a></span> - </p> - <h2 class="xerox" - {{ if $showSummary }} style="margin-bottom: 0"{{ end }}> - <a href="{{ .ctx.Permalink }}"> - {{ if eq .ctx.Section "library" }} - 读《{{ .ctx.Title }}》 - {{ else }} - {{ .ctx.Title }} - {{ end }} - </a> - {{ if eq .ctx.Section "fictions" }} - <span class="font-normal text-4 text-secondary">小说</span> - {{ end }} - </h2> - </div> - {{ with .ctx.Params.categories }} - <div class="my-4"> - {{ partial "components/category-pill" $ctx }} - </div> - {{ end }} - </header> - {{ if or $showSummary .ctx.Params.description }} - <div class="markdown-body text-size-lg leading-relaxed" - style="view-transition-name: post-content-{{ .ctx.File.UniqueID }}"> - {{ if $showSummary }} - {{ .ctx.Summary }} - {{ else if .ctx.Params.description }} - {{ .ctx.Params.description }} - {{ end }} - </div> - {{ end }} -</div> diff --git a/layouts/view_postblock.html b/layouts/view_postblock.html new file mode 100644 index 0000000..3e21be1 --- /dev/null +++ b/layouts/view_postblock.html @@ -0,0 +1,31 @@ +<div class="posts-item w-full mt-2" + style="view-transition-name: post-{{ .File.UniqueID }}"> + <header class="w-full md:flex md:justify-between"> + <div> + <p class="font-mono text-secondary"> + <time>{{ .Date.Format "January 2" }},</time> + <span>in <a href="/{{ .Section }}/">{{ .Section }}</a></span> + </p> + <h2 class="xerox"> + <a href="{{ .Permalink }}"> + {{ if eq .Section "library" }} + 读《{{ .Title }}》 + {{ else }} + {{ .Title }} + {{ end }} + </a> + {{ if eq .Section "fictions" }} + <span class="font-normal text-4 text-secondary">小说</span> + {{ end }} + </h2> + </div> + + {{ $ctx := . }} + {{ with .Params.categories }} + <div class="my-4"> + {{ partial "components/category-pill" $ctx }} + </div> + {{ end }} + </header> +</div> + diff --git a/layouts/view_postblock_summary.html b/layouts/view_postblock_summary.html new file mode 100644 index 0000000..2426ee6 --- /dev/null +++ b/layouts/view_postblock_summary.html @@ -0,0 +1,14 @@ +<!-- + This is a Decorator of 'view_postblock', + with additional summary block. +--> + +{{ .Render "view_postblock" }} +<div class="post-summary markdown-body text-size-lg leading-relaxed mt-0" + style="view-transition-name: post-content-{{ .File.UniqueID }}"> + {{ if .Params.description }} + {{ .Params.description }} + {{ else }} + {{ .Summary }} + {{ end }} +</div> |
