From 31cd7a3067a9996b7140aeaefb6c97e08db2f78f Mon Sep 17 00:00:00 2001 From: verdant Date: Sat, 11 Apr 2026 18:27:20 +0800 Subject: update --- layouts/partials/toc.html | 110 ++++++++-------------------------------------- 1 file changed, 19 insertions(+), 91 deletions(-) (limited to 'layouts/partials/toc.html') diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html index 66936a4..101c5e9 100644 --- a/layouts/partials/toc.html +++ b/layouts/partials/toc.html @@ -1,91 +1,19 @@ -{{/* 根据页面内容生成目录 */}} -{{ if and .TableOfContents (ne .TableOfContents "") }} - - - -{{ end }} \ No newline at end of file +{{ $hasHeadings := false }} +{{ if .RawContent }} + {{/* 正则匹配:查找以 1 到 6 个 # 开头的行 */}} + {{ $headings := findRE "(?m)^#{1,6} " .RawContent }} + {{ if gt (len $headings) 0 }} + {{ $hasHeadings = true }} + {{ end }} +{{ end }} + +{{ if $hasHeadings }} + +{{ end }} -- cgit v1.2.3