Hugo

Hugo FixIt 主题美化:文章页

注意
本文最后更新于 2026-05-19,文中内容可能已过时。

FixIt 主题支持通过多种方式自定义样式与布局:

  • 自定义样式:在 assets/css/ 下创建 _override.scss(覆盖主题变量)和 _custom.scss(添加自定义 CSS),主题会自动加载。
  • 自定义脚本:在 assets/js/ 创建 custom.js 会在每个页面末尾自动执行,其它 JS 文件需在 [params.page.library.js] 中配置路径。
  • 模板覆盖:将主题 layouts/ 下的文件复制到项目根目录相同路径,Hugo 会优先使用新模板。
  • 自定义块:在 layouts/_partials/ 下创建任意 .html 文件,并在 [params.customPartials] 中启用,主题会自动渲染到页面相应位置。

下面介绍如何利用这些能力,实现 FixIt 主题文章页的美化。

双栏布局

左正文区 + 右目录,隐藏左侧边栏。

创建以下文件:

SCSSassets/css/_custom.scss
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 全局样式与变量见最后一章

// ========= 文章页 =========

.single {
  width: 100%;
  border-radius: 16px;
  box-sizing: border-box;
  padding: var(--c-space-8);
  background-color: var(--c-card-bg);
  max-width: clamp(360px, 85vw, 800px);
  border: 1px solid var(--c-card-border);
  box-shadow: 0 2px 10px var(--c-card-shadow);  
  margin-block: var(--c-space-4) var(--c-space-8);
  transition: background-color 0.3s ease, border-color 0.3s ease;
  @include phone { padding: var(--c-space-6); }
}

// ========= 目录 =========

// 隐藏静态目录 + 合集
#toc-static,
.aside-collection {
  display: none !important;
}

#toc-auto {
  padding: 0;
  overflow: hidden; 
  max-width: 280px;
  border-radius: 16px;
  margin-left: var(--c-space-2);
  top: calc(var(--c-space-8) * 2);
  box-shadow: var(--c-card-shadow);
  background-color: var(--c-card-bg);
  border: 1px solid var(--c-card-border);
  margin-block: var(--c-space-4) 0 !important;
  @include pad { display: none !important; }

  .toc-title {
    margin: 0;
    display: flex;
    margin-block: 0;
    align-items: center;
    background-color: transparent;
    justify-content: space-between; 
    font-size: var(--c-font-m) !important;
    padding: var(--c-space-2) var(--c-space-4);

    &::before {
      bottom: 0;
      margin-right: 0;
      content: "\f550";
      font-weight: 900;
      color: var(--c-toc-font);
      font-family: "Font Awesome 7 Free";
    }
  }

  .toc-content {
    margin-top: 0;
    overflow-y: auto;
    line-height: 1.7;
    scrollbar-width: thin;
    background-color: transparent;
    transition: box-shadow 0.3s ease;
    font-size: var(--c-font-s) !important;
    padding: var(--c-space-2) var(--c-space-6) var(--c-space-4);
  }
}

头部元数据

  • 分类 / 合集:取自 Front matter 中的 categories / collections,移至标题上方。
  • 标题 / 副标题:分别取自 Front matter 的 titlesubtitle
  • 作者:由 [params.author] name 或 Front matter 的 author 控制。
  • 发布日期 / 更新日期:发布日期始终显示,格式受 dateFormat 配置影响;更新日期由 [params.page] showLastmod 控制是否显示。
  • 字数 / 阅读时间:由 [params.page]wordCount / readingTime 控制。
  • 访客数 / 评论数:由 [params.page.comment] 中启用的评论系统的对应开关控制。

创建以下文件:

HTMLlayouts/posts/single.html
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
{{- /* 覆盖来源:FixIt/layouts/posts/single.html */ -}}

{{- define "title" -}}
  {{- cond (.Param "capitalizeTitles") (title .Title) .Title -}}
  {{- if .Site.Params.withSiteTitle }} {{ .Site.Params.titleDelimiter }} {{ .Site.Title }}{{- end -}}
{{- end -}}

{{- define "content" -}}
  {{- $title := cond (.Param "capitalizeTitles") (title .Title) .Title -}}
  {{- $params := partial "function/params.html" -}}
  {{- $toc := .Store.Get "toc" -}}
  {{- $tableOfContents := .Fragments.ToHTML ($toc.startlevel | int) ($toc.endlevel | int) ($toc.ordered | default false) -}}
  {{- $showToc := $toc.enable | and (ne $tableOfContents `<nav id="TableOfContents"></nav>`) -}}
  {{- .Store.Set "showToc" $showToc -}}
  {{- $tableOfContents = dict "Content" $tableOfContents "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}

  <aside class="aside-collection animate__animated animate__fadeIn animate__faster" aria-label="{{ T "collections" }}">
    {{- /* Collection List */ -}}
    {{- partial "single/collection-list.html" . -}}

    {{- /* Related Content */ -}}
    {{- partial "single/related-aside.html" . -}}

    {{- /* Custom Aside */ -}}
    {{- block "custom-aside" . }}{{ end -}}
  </aside>

  <article class="page single"{{ with .Params.fromAdapters }} data-adapters="{{ . }}"{{ end }}>

    {{- /* ======================== 修改点 1:开始 ======================== */ -}}
    {{- /* 重构文章头部:全部迁移至独立 partial "custom-single-header.html */ -}}
    {{- partial "custom-single-header.html" . -}}
    {{- /* ======================== 修改点 1:结束 ======================== */ -}}

    {{- /* Featured image */ -}}
    {{- $image := $params.featuredimage -}}
    {{- $matches := slice -}}
    {{- if .Resources.GetMatch "featured-image" -}}
      {{- $matches = $matches | append "featured-image" -}}
    {{- end -}}
    {{- if $image | or (gt (len $matches) 0) -}}
      <div class="featured-image">
        {{- $optim := slice 
          (dict "Process" "resize 800x webp" "descriptor" "800w")
          (dict "Process" "resize 1200x webp" "descriptor" "1200w")
          (dict "Process" "resize 1600x webp" "descriptor" "1600w") 
        -}}
        {{- dict "Src" $image "Title" $.Description "Resources" .Resources "Matches" $matches "Loading" "eager" "Sizes" "(max-width: 680px) 100vw, (max-width: 960px) 80vw, (max-width: 1440px) 56vw, 800px" "OptimConfig" $optim | partial "plugin/image.html" -}}
      </div>
    {{- end -}}

    {{- /* Static TOC */ -}}
    {{- if $showToc -}}
      <div class="details toc{{ with $params.password }} encrypted-hidden{{ end }}" id="toc-static" data-kept="{{ if $toc.keepstatic }}true{{ else }}false{{ end }}">
        <div class="details-summary toc-title">
          <span>{{ T "single.contents" }}</span>
          <span>{{ dict "Class" "details-icon fa-solid fa-angle-right" | partial "plugin/icon.html" }}</span>
        </div>
        <div class="details-content toc-content" id="toc-content-static">
          {{- $tableOfContents -}}
        </div>
      </div>
    {{- end -}}

    {{- /* AI Summary */ -}}
    {{- $summaryConfig := (.Params | merge .Site.Params).postSummary -}}
    {{- if $summaryConfig.enable -}}
      <div class="ai-summary"></div>
    {{- end -}}

    {{- /* Custom block before post content */ -}}
    {{- block "custom-post__content:before" . }}{{ end -}}

    {{- /* Expiration Reminder */ -}}
    {{- partial "single/expiration-reminder.html" . -}}

    {{- /* Content */ -}}
    {{- $content := dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
    <div class="content" id="content"{{ with $params.endFlag }} data-end-flag="{{ . }}"{{ end }}>
      {{- if not $params.password -}}
        {{- $content -}}
      {{- end -}}
    </div>

    {{- /* Custom block after post content */ -}}
    {{- block "custom-post__content:after" . }}{{ end -}}

    {{- /* Related Content */ -}}
    {{- partial "single/related.html" . -}}

    {{- /* ======================== 修改点 2:开始 ======================== */ -}}
    {{- /* 已删除 Reward before Footer */ -}}
    {{- /* ======================== 修改点 2:结束 ======================== */ -}}

    {{- /* Content Encryption */ -}}
    {{- dict "Content" $content "Password" $params.password "Message" $params.message "Page" . | partial "plugin/fixit-encryptor.html" -}}

    {{- /* ======================== 修改点 3:开始 ======================== */ -}}
    {{- /* 已删除 Collection Navigation */ -}}
    {{- /* ======================== 修改点 3:结束 ======================== */ -}}

    {{- /* Custom block before post footer */ -}}
    {{- block "custom-post__footer:before" . }}{{ end -}}

    {{- /* Footer */ -}}
    {{- partial "single/footer.html" . -}}

    {{- /* ======================== 修改点 4:开始 ======================== */ -}}
    {{- /* 已删除 Reward after post footer */ -}}
    {{- /* ======================== 修改点 4:结束 ======================== */ -}}

    {{- /* Custom block after post footer */ -}}
    {{- block "custom-post__footer:after" . }}{{ end -}}

    {{- /* Comment */ -}}
    {{- partial "single/comment.html" . -}}
  </article>

  <aside class="toc" id="toc-auto" aria-label="{{ T "single.contents" }}">
    {{- /* Custom block before post toc */ -}}
    {{- block "custom-post__toc:before" . }}{{ end -}}

    {{- /* Auto TOC */ -}}
    {{- if $showToc -}}
      <h2 class="toc-title{{ with $params.password }} encrypted-hidden{{ end }}">
        {{- T "single.contents" -}}&nbsp;
        {{- dict "Class" "toc-icon fa-solid fa-angle-down" | partial "plugin/icon.html" -}}
      </h2>
      <div class="toc-content{{ if eq $toc.auto false }} always-active{{ end }}{{ with $params.password }} encrypted-hidden{{ end }}" id="toc-content-auto"></div>
    {{- end -}}

    {{- /* Custom block after post toc */ -}}
    {{- block "custom-post__toc:after" . }}{{ end -}}
  </aside>

  {{- /* TOC Dialog */ -}}
  {{- if $showToc -}}
    <dialog id="toc-dialog" aria-labelledby="toc-dialog-title" role="dialog">
      <div class="toc">
        <h2 class="toc-title">{{ T "single.contents" }}</h2>
        <div class="toc-content" id="toc-content-drawer">
          {{- replace $tableOfContents `id="TableOfContents"` "" | safeHTML -}}
        </div>
      </div>
    </dialog>
  {{- end -}}
{{- end -}}

创建以下文件:

HTMLlayouts/_partials/custom-single-header.html
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
{{- /* 自定义块来源:FixIt/layouts/posts/single.html */ -}}

{{- $title := cond (.Param "capitalizeTitles") (title .Title) .Title -}}
{{- $params := partial "function/params.html" -}}
{{- $comment := .Store.Get "comment" | default dict -}}

{{- /* 分类和合集 */ -}}
{{- $categories := slice -}}
{{- range .GetTerms "categories" -}}
  {{- $url := partial "function/escapeurl.html" .RelPermalink -}}
  {{- $categories = $categories | append (printf `<a href="%s" class="post-category" title="%s - %s">%s %s</a>` $url (T "category") .LinkTitle (dict "Class" "fa-regular fa-folder" | partial "plugin/icon.html") .LinkTitle) -}}
{{- end -}}
{{- $collections := slice -}}
{{- range .GetTerms "collections" -}}
  {{- $url := partial "function/escapeurl.html" .RelPermalink -}}
  {{- $collections = $collections | append (printf `<a href="%s" class="post-collection" title="%s - %s">%s %s</a>` $url (T "collection") .LinkTitle (dict "Class" "fa-solid fa-layer-group" | partial "plugin/icon.html") .LinkTitle) -}}
{{- end -}}
{{- if or $categories $collections -}}
  <div class="post-top-meta">
    {{- delimit $categories " " | safeHTML -}}
    {{- if and $categories $collections -}} {{ end -}}
    {{- delimit $collections " " | safeHTML -}}
  </div>
{{- end -}}

{{- /* 标题 */ -}}
<h1 class="single-title animate__animated animate__flipInX">
  {{- $repost := $params.repost | default dict -}}
  {{- with $repost -}}
    {{- if eq .Enable true -}}
      {{- $icon := dict "Class" "fa-solid fa-share" -}}
      {{- $iconTitle := cond (hasPrefix .Url "http") (printf "%v -> %v" (T "single.repost") .Url ) (T "single.repost") -}}
      {{- if hasPrefix .Url "http" -}}
        {{ dict "Destination" .Url "Icon" $icon "Class" "icon-repost" "Title" $iconTitle | partial "plugin/link.html" -}}
      {{- else -}}
        <span title="{{ $iconTitle }}" class="icon-repost">{{- $icon | partial "plugin/icon.html" -}}</span>
      {{- end -}}
    {{- end -}}
  {{- end -}}
  <span>{{ $title }}</span>
</h1>

{{- /* 副标题 */ -}}
{{- with $params.subtitle -}}<p class="single-subtitle animate__animated animate__fadeIn">{{ . | $.RenderString }}</p>{{- end -}}

{{- /* 元数据 */ -}}
<div class="post-meta">
  {{- /* 作者 */ -}}
  {{- partial "single/post-author.html" . -}}
  {{- /* 发布日期 */ -}}
  {{- with .PublishDate | dateFormat (.Site.Params.dateformat | default "2006-01-02") -}}
    <span title="{{ dict "Date" ("2006-01-02 15:04:05" | $.PublishDate.Format) | T "single.publishedOnDate" }}">
      {{- dict "Class" "fa-solid fa-calendar-days me-1" | partial "plugin/icon.html" -}}
      {{- printf `<time datetime="%v">%v</time>` . . | safeHTML -}}
    </span>
  {{- end -}}
  {{- /* 更新日期 */ -}}
  {{- if (ne .Lastmod.Unix .PublishDate.Unix) | and $params.showLastmod -}}
    {{- with .Lastmod | dateFormat (.Site.Params.dateformat | default "2006-01-02") -}}
      <span title="{{ dict "Date" ("2006-01-02 15:04:05" | $.Lastmod.Format) | T "single.updatedOnDate" }}">
        {{- dict "Class" "fa-regular fa-calendar-check me-1" | partial "plugin/icon.html" -}}
        {{- printf `<time datetime="%v">%v</time>` . . | safeHTML -}}
      </span>
    {{- end -}}
  {{- end -}}
  {{- /* 字数 */ -}}
  {{- if $params.wordCount -}}
    <span title="{{ T "single.wordCount" .WordCount }}">
      {{- dict "Class" "fa-solid fa-pencil-alt me-1" | partial "plugin/icon.html" -}}
      {{- T "single.fuzzyWordCount" .FuzzyWordCount -}}
    </span>
  {{- end -}}
  {{- /* 阅读时间 */ -}}
  {{- if $params.readingTime -}}
    <span>
      {{- dict "Class" "fa-regular fa-clock me-1" | partial "plugin/icon.html" -}}
      约 {{ .ReadingTime }} 分钟
    </span>
  {{- end -}}
  {{- /* 访客数 */ -}}
  {{- $visitorIcon := dict "Class" "fa-regular fa-eye me-1" | partial "plugin/icon.html" -}}
  {{- if $comment.enable | and $comment.artalk.enable -}}
    <span class="comment-visitors" data-flag-title="{{ $title }}">
      {{- $visitorIcon }}<span class="artalk-visitor-count" data-page-key="{{ .RelPermalink }}">-</span>&nbsp;{{ T "single.views" }}
    </span>
  {{- else if $comment.enable | and $comment.valine.enable | and $comment.valine.visitor -}}
    <span id="{{ .RelPermalink }}" class="leancloud_visitors comment-visitors" data-flag-title="{{ $title }}">
      {{- $visitorIcon }}<span class="leancloud-visitors-count">-</span>&nbsp;{{ T "single.views" }}
    </span>
  {{- else if $comment.enable | and $comment.waline.enable | and $comment.waline.pageview -}}
    <span class="comment-visitors" data-flag-title="{{ $title }}">
      {{- $visitorIcon }}<span data-path="{{ .RelPermalink }}" class="waline-pageview-count">-</span>&nbsp;{{ T "single.views" }}
    </span>
  {{- else if $comment.enable | and $comment.twikoo.enable | and $comment.twikoo.visitor -}}
    <span id="{{ .RelPermalink }}" class="comment-visitors" data-flag-title="{{ $title }}">
      {{- $visitorIcon }}<span id="twikoo_visitors">-</span>&nbsp;{{ T "single.views" }}
    </span>
  {{- else if .Site.Params.busuanzi.enable | and .Site.Params.busuanzi.pageViews | and hugo.IsProduction -}}
    <span id="busuanzi_container_page_pv" class="busuanzi_visitors comment-visitors" data-flag-title="{{ $title }}">
      {{- $visitorIcon }}<span id="busuanzi_value_page_pv">-</span>&nbsp;{{ T "single.views" }}
    </span>
  {{- end -}}
  {{- /* 评论数 */ -}}
  {{- $commentIcon := dict "Class" "fa-regular fa-comments me-1" | partial "plugin/icon.html" -}}
  {{- if $comment.enable -}}
    {{- if $comment.artalk.enable -}}
      <span class="comment-count" data-flag-title="{{ $title }}">
        {{ $commentIcon }}<span class="artalk-comment-count" data-page-key="{{ .RelPermalink }}">-</span>&nbsp;{{ T "single.comments" }}
      </span>
    {{- else if $comment.valine.enable | and $comment.valine.commentCount -}}
      <span class="comment-count" data-flag-title="{{ $title }}">
        {{ $commentIcon }}<span data-xid="{{ .RelPermalink }}" class="valine-comment-count">-</span>&nbsp;{{ T "single.comments" }}
      </span>
    {{- else if $comment.waline.enable | and $comment.waline.comment -}}
      <span class="comment-count" data-flag-title="{{ $title }}">
        {{ $commentIcon }}<span data-path="{{ .RelPermalink }}" class="waline-comment-count">-</span>&nbsp;{{ T "single.comments" }}
      </span>
    {{- else if $comment.twikoo.enable | and $comment.twikoo.commentCount -}}
      <span id="{{ .RelPermalink }}" class="comment-count" data-flag-title="{{ $title }}">
        {{ $commentIcon }}<span id="twikoo-comment-count">-</span>&nbsp;{{ T "single.comments" }}
      </span>
    {{- end -}}
  {{- end -}}
</div>

创建以下文件:

SCSSassets/css/_custom.scss
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// 全局样式与变量见最后一章

// ========= 文章页 =========

.single {
  .post-top-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--c-space-2);
    font-size: var(--c-font-s);
    margin-block: var(--c-space-2);
    @include media('print') { display: none; }

    .post-category,
    .post-collection {
      border-radius: 14px;
      align-items: center;
      display: inline-flex;
      transition: all 0.3s;
      text-decoration: none;  
      gap: var(--c-space-2); 
      color: var(--c-meta-alt);   
      background-color: var(--c-meta-bg);  
      padding: var(--c-space-1) var(--c-space-2);
       
      &:hover {
        color: var(--c-meta-hover);
        background-color: var(--c-meta-bg-hover);
      }
    }

    .post-category {
      @include category-color-styles;
    }
  }

  .single-title {
    padding: 0;
    line-height: 1.6;
    font-size: var(--c-font-xxl); 
    @include media('print') { margin-block: var(--c-space-4) var(--c-space-2); }
  } 

  .post-meta {
    color: var(--c-meta);
    font-size: var(--c-font-s); 
    margin-block: var(--c-space-2);

    span {
      margin-right: var(--c-space-2);

      &:last-child {
        margin-right: 0;
      }      
    }

    a {
      color: var(--c-meta) !important; 

      &:hover {
        color: var(--c-meta) !important;  
      }
    }
  }
}

文末信息卡片

  • 作者卡片:头像(带链接)、昵称、个人简介(优先使用 home.profile.subtitle)。
  • 赞赏 / 订阅:赞赏由 [params.page.reward] 控制,订阅 RSS 始终显示。
  • 版权声明:使用主题 [params.page] license 配置的 HTML。
  • 分享模块:由 [params.page.share] 控制,包括 Facebook、X、微信(wechat = true)、微博、复制链接(copy = true)五个固定按钮(微信和复制为自定义,其余三个复用主题)。
  • 上下页导航:沿用 [params.navigation]inSection / reverse 逻辑,显示下上下篇标题。
  • 合集卡片:由 [params.page.collectionNavigation] 控制,展示与当前文章时间邻近的 6 篇同合集文章(含封面、日期、标题)。
  • 评论区标题:固定显示为留言交流,无配置项。

创建以下文件:

HTMLlayouts/_partials/custom-single-footer.html
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
{{- /* 自定义块来源:FixIt/layouts/_partials/home/profile.html */ -}}
{{- /* 自定义块来源:FixIt/layouts/_partials/single/footer.html */ -}}
{{- /* 自定义块来源:FixIt/layouts/_partials/single/collection-nav.html */ -}}
{{- /* 自定义块来源:FixIt/layouts/_partials/single/reward.html */ -}}
{{- /* 自定义块来源:FixIt/layouts/_partials/plugin/reward.html */ -}}
{{- /* 自定义块来源:FixIt/layouts/_partials/plugin/share.html */ -}}

{{- $params := partial "function/params.html" -}}
{{- $profile := .Site.Params.home.profile -}}
{{- $author := partial "function/get-author-map.html" .Params.author -}}
{{- $avatar := "" -}}
{{- if $profile.gravatarEmail -}}
  {{- $avatar = dict "Email" $profile.gravatarEmail "Size" "96" | partial "function/get-gravatar.html" -}}
{{- end -}}
{{- if not $avatar -}}
  {{- $avatar = $profile.avatarURL | default "" -}}
{{- end -}}
{{- if not $avatar -}}
  {{- $avatar = $author.avatar | default "" -}}
{{- end -}}
{{- $authorName := $author.name | default .Site.Params.author.name | default "作者" -}}
{{- $authorBio := $profile.subtitle | default .Site.Params.description | default "" -}}
{{- $reward := .Store.Get "reward" | default dict -}}

{{- /* 文末信息卡片:作者信息 + 赞赏 / 订阅 + 版权 + 分享 */ -}}
<div class="custom-post-footer">
  {{- /* 作者头像 */ -}}
  <div class="avatar-frame">
    {{- if $avatar -}}
      {{- $avatarLink := .Site.BaseURL -}}
      {{- $menus := $.Site.Menus.main | default slice -}}
      {{- if $profile.avatarMenu -}}
        {{- range $menus -}}
          {{- if eq .Identifier $profile.avatarMenu -}}
            {{- $avatarLink = .URL | relLangURL -}}
            {{- with .Page -}}
              {{- $avatarLink = .RelPermalink -}}
            {{- end -}}
          {{- end -}}
        {{- end -}}
      {{- end -}}
      <a href="{{ $avatarLink }}">
        <img class="avatar" src="{{ $avatar }}" alt="author avatar">
      </a>
    {{- else -}}
      <div class="avatar-placeholder"></div>
    {{- end -}}
  </div>
  {{- /* 作者信息 */ -}}
  <div class="author-info">
    <div class="author-name">{{ $authorName }}</div>
    <div class="author-bio">{{ $authorBio }}</div>
  </div>
  {{- /* 动态按钮 */ -}}
  <div class="action-buttons">
    {{- /* 赞赏 */ -}}
    {{- if $reward.enable -}}
      <div class="post-reward">
        <div class="reward-button">
          {{- dict "Class" "fa-solid fa-qrcode" | partial "plugin/icon.html" -}}
          {{- T "single.reward.donate" -}}
        </div>
        <div class="reward-ways" data-mode="static">
          {{- range $way, $image := $reward.ways -}}
            {{- with T (printf "single.reward.%v" $way) -}}{{ $way = . }}{{- end -}}
            {{- if $image -}}
              <div>
                {{- dict "Src" $image "Alt" (printf "%v %v" $authorName $way) | partial "plugin/image.html" -}}
                <span>{{ $way }}</span>
              </div>
            {{- end -}}
          {{- end -}}
        </div>
      </div>
    {{- end -}}
    {{- /* 订阅 */ -}}
    {{- $rssURL := "" -}}
    {{- if .OutputFormats.Get "RSS" -}}
      {{- $rssURL = (.OutputFormats.Get "RSS").Permalink -}}
    {{- else -}}
      {{- $rssURL = "index.xml" | absURL -}}
    {{- end -}}
    <a href="{{ $rssURL }}" class="subscribe-button{{ if not $reward.enable }} subscribe-button--solo{{ end }}" target="_blank" rel="noopener noreferrer">
      <i class="fa-regular fa-bell"></i> 订阅
    </a>
  </div>
  {{- /* 版权 */ -}}
  <div class="post-license">
    本博客部分代码由 AI 辅助生成,内容采用&nbsp;{{ $params.license | safeHTML }}&nbsp;协议,转载请注明来自&nbsp;<a href="{{ .Permalink }}">{{ .Site.Title }}</a>
  </div>
  {{- /* 分享 */ -}}
  {{- $shareConfig := (partial "function/params.html").share | default dict -}}
  {{- if $shareConfig.enable -}}
  <div class="post-share">
    <div class="share-label">
      <i class="fa-regular fa-share-from-square"></i> 分享本文
    </div>
    <div class="share-button">
      <!-- Facebook -->
      {{- if $shareConfig.Facebook -}}
      <a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="{{ .Permalink }}">
        <i class="fa-brands fa-facebook-square"></i>
      </a>
      {{- end -}}
      <!-- Twitter (X)  -->
      {{- if $shareConfig.Twitter -}}
      <a href="javascript:void(0);" title="分享到 X" data-sharer="twitter" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
        <i class="fa-brands fa-x-twitter"></i>
      </a>     
      {{- end -}} 
      <!-- 微信 -->
      {{- if $shareConfig.wechat -}}
      <span class="wechat-btn">
        <a href="javascript:void(0);" class="wechat" title="微信分享">
          <i class="fa-brands fa-weixin"></i>
        </a>
        <div class="qrcode-popup">
          <div id="wechat-qrcode" class="wechat-qrcode"></div>
          <div class="qrcode-text">扫码分享好友</div>
        </div>
      </span>  
      {{- end -}}
      <!-- 微博 -->
      {{- if $shareConfig.Weibo -}}
      <a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="{{ .Permalink }}" data-title="{{ .Title }}"{{ with .Params.featuredImage }} data-image="{{ . }}"{{ end }}>
        <i class="fa-brands fa-weibo"></i>
      </a>      
      {{- end -}}
      <!-- 复制链接 -->
      {{- if $shareConfig.copy -}}
      <a href="javascript:void(0);" class="copy-btn" title="复制链接" data-url="{{ .Permalink }}" onclick="copyPageUrl(this);">
        <i class="fa-regular fa-copy"></i>
      </a> 
      {{- end -}}
    </div>
  </div>
  {{- end -}}
</div>

{{- /* 上下页导航 */ -}}
{{- $navigation := .Site.Params.navigation -}}
<div class="post-nav">
  {{- $pages := .Site.Store.Get "mainSectionPages" -}}
  {{- $prev := $pages.Prev . -}}
  {{- $next := $pages.Next . -}}
  {{- if $navigation.inSection -}}
    {{- $prev = .PrevInSection -}}
    {{- $next = .NextInSection -}}
  {{- end -}}
  {{- if $navigation.reverse -}}
    {{- $prev = $pages.Next . -}}
    {{- $next = $pages.Prev . -}}
  {{- end -}}
  {{- /* 上一页 */ -}}
  {{- with $prev -}}
    {{- $capitalizeTitles := .Param "capitalizeTitles" -}}
    <a href="{{ .RelPermalink }}" class="post-nav-item" rel="prev" title="{{ cond $capitalizeTitles (title .LinkTitle) .LinkTitle }}">
      {{- dict "Class" "fa-solid fa-angle-left" | partial "plugin/icon.html" -}}
      <span class="nav-title">{{ cond $capitalizeTitles (title .LinkTitle) .LinkTitle }}</span>
    </a>
  {{- end -}}
  {{- /* 下一页 */ -}}
  {{- with $next -}}
    {{- $capitalizeTitles := .Param "capitalizeTitles" -}}
    <a href="{{ .RelPermalink }}" class="post-nav-item" rel="next" title="{{ cond $capitalizeTitles (title .LinkTitle) .LinkTitle }}">
      <span class="nav-title">{{ cond $capitalizeTitles (title .LinkTitle) .LinkTitle }}</span>
      {{- dict "Class" "fa-solid fa-angle-right" | partial "plugin/icon.html" -}}
    </a>
  {{- end -}}
</div>

{{- /* 合集卡片 */ -}}
{{- if $params.collectionNavigation -}}
  {{- /* 获取当前文章所属的第一个合集 */ -}}
  {{- $collections := .GetTerms "collections" -}}
  {{- if $collections -}}
    {{- $collection := index $collections 0 -}}
    {{- $current := . -}}
    {{- $all := $collection.Pages.ByDate -}}
    {{- $total := len $all -}}
    {{- /* 找到当前文章索引 */ -}}
    {{- $currIdx := -1 -}}
    {{- range $idx, $p := $all -}}
      {{- if eq $p.Permalink $current.Permalink -}}
        {{- $currIdx = $idx -}}
        {{- break -}}
      {{- end -}}
    {{- end -}}
    {{- if ne $currIdx -1 -}}
      {{- $max := 6 -}}
      {{- $half := 3 -}}
      {{- $start := sub $currIdx $half -}}
      {{- $end := add $currIdx $half -}}
      {{- /* 边界修正 */ -}}
      {{- if lt $start 0 -}}
        {{- $end = add $end (sub 0 $start) -}}
        {{- $start = 0 -}}
      {{- end -}}
      {{- if ge $end $total -}}
        {{- $start = sub $start (sub $end (sub $total 1)) -}}
        {{- $end = sub $total 1 -}}
        {{- if lt $start 0 -}}{{- $start = 0 -}}{{- end -}}
      {{- end -}}
      {{- /* 收集范围内的其他文章 */ -}}
      {{- $others := slice -}}
      {{- range $i, $p := $all -}}
        {{- if and (ge $i $start) (le $i $end) (ne $p.Permalink $current.Permalink) -}}
          {{- $others = $others | append $p -}}
        {{- end -}}
      {{- end -}}
      {{- /* 如果不够 6 篇,从范围外邻近方向补充 */ -}}
      {{- if lt (len $others) $max -}}
        {{- $need := sub $max (len $others) -}}
        {{- /* 先向左补充 */ -}}
        {{- $leftIdx := sub $start 1 -}}
        {{- range $need -}}
          {{- if lt $leftIdx 0 -}}{{- break -}}{{- end -}}
          {{- $p := index $all $leftIdx -}}
          {{- if ne $p.Permalink $current.Permalink -}}
            {{- $others = slice $p | append $others -}}
          {{- end -}}
          {{- $leftIdx = sub $leftIdx 1 -}}
        {{- end -}}
        {{- /* 如果还不够,向右补充 */ -}}
        {{- if lt (len $others) $max -}}
          {{- $need2 := sub $max (len $others) -}}
          {{- $rightIdx := add $end 1 -}}
          {{- range $need2 -}}
            {{- if ge $rightIdx $total -}}{{- break -}}{{- end -}}
            {{- $p := index $all $rightIdx -}}
            {{- if ne $p.Permalink $current.Permalink -}}
              {{- $others = $others | append $p -}}
            {{- end -}}
            {{- $rightIdx = add $rightIdx 1 -}}
          {{- end -}}
        {{- end -}}
      {{- end -}}
      {{- /* 渲染合集卡片 */ -}}
      {{- if $others -}}
        <div class="custom-collection-card">
          <div class="custom-coll-title">
            <i class="fa-solid fa-layer-group"></i> {{ $collection.LinkTitle }}
          </div>
          <div class="custom-coll-list">
            {{- range $others -}}
              {{- $img := .Params.featuredimagepreview | default .Params.featuredimage -}}
              {{- if not $img -}}
                {{- with .Resources.GetMatch "featured-image-preview" -}}
                  {{- $img = .RelPermalink -}}
                {{- else with .Resources.GetMatch "featured-image" -}}
                  {{- $img = .RelPermalink -}}
                {{- end -}}
              {{- end -}}
              <a class="custom-coll-card" href="{{ .RelPermalink }}">
                <div class="coll-card-img" style="background-image: url('{{ $img | safeCSS }}');"></div>
                <div class="coll-card-info">
                  <div class="coll-card-date"><i class="fa-regular fa-calendar-alt"></i> {{ .Date | dateFormat "2006-01-02" }}</div>
                  <div class="coll-card-title">{{ .Title }}</div>
                </div>
              </a>
            {{- end -}}
          </div>
        </div>
      {{- end -}}
    {{- end -}}
  {{- end -}}
{{- end -}}

{{- /* 评论区标题 */ -}}
<div class="custom-comment-title">
  <i class="fa-regular fa-comments"></i> 留言交流
</div>

创建以下文件:

JavaScriptassets/js/custom.js
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
(function() {

  // ========== 复制 + 二维码(仅文章页) ==========

  (function() {

    if (!document.querySelector('.page.single')) return;

    // 轻提示函数
    function showToast(msg) {
      const toast = document.createElement('div');
      toast.innerText = msg;
      toast.style.position = 'fixed';
      toast.style.top = '50%';
      toast.style.left = '50%';
      toast.style.transform = 'translate(-50%, -50%)';
      toast.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
      toast.style.color = '#fff';
      toast.style.padding = '10px 20px';
      toast.style.borderRadius = '30px';
      toast.style.fontSize = '14px';
      toast.style.fontWeight = '500';
      toast.style.zIndex = '9999';
      toast.style.whiteSpace = 'nowrap';
      toast.style.opacity = '0';
      toast.style.transition = 'opacity 0.2s';
      document.body.appendChild(toast);
      setTimeout(() => { toast.style.opacity = '1'; }, 10);
      setTimeout(() => {
        toast.style.opacity = '0';
        setTimeout(() => toast.remove(), 200);
      }, 1500);
    }

    // 全局复制函数
    window.copyPageUrl = function(btn) {
      var url = btn.getAttribute('data-url') || window.location.href;
      var text = document.title + '\n' + url;
      
      var textarea = document.createElement('textarea');
      textarea.value = text;
      textarea.style.position = 'fixed';
      textarea.style.top = '-9999px';
      textarea.style.left = '-9999px';
      document.body.appendChild(textarea);
      textarea.select();
      textarea.setSelectionRange(0, text.length); // 移动端兼容
      
      try {
        var success = document.execCommand('copy');
        if (success) {
          showToast('✅ 已复制');
        } else {
          // 失败时兜底
          window.prompt('请手动复制', text);
        }
      } catch (e) {
        window.prompt('请手动复制', text);
      }
      document.body.removeChild(textarea);
    };

    // 二维码生成(增强重试,避免无限循环)
    let qrRetryCount = 0;
    const MAX_QR_RETRY = 10;
    function initQRCode() {
      const qrcodeElem = document.getElementById('wechat-qrcode');
      if (!qrcodeElem) return;

      if (typeof QRCode !== 'undefined') {
        qrcodeElem.innerHTML = '';
        new QRCode(qrcodeElem, {
          text: window.location.href,
          width: 130,
          height: 130,
          colorDark: '#000000',
          colorLight: '#ffffff',
          correctLevel: QRCode.CorrectLevel.H
        });
        return;
      }

      // 如果库未加载,且未超过最大重试次数,则延迟重试
      if (qrRetryCount < MAX_QR_RETRY) {
        qrRetryCount++;
        setTimeout(initQRCode, 200);
      } else {
        console.warn('QRCode library failed to load after retries.');
      }
    }

    // 确保 DOM 就绪后执行,同时确保外部脚本(QRCode.js)已加载
    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', initQRCode);
    } else {
      // 如果 DOM 早已就绪,但可能 QRCode.js 还未加载,同样启动重试
      initQRCode();
    }
  })();

})();  

修改主题配置:

TOMLconfig/_default/hugo.toml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[params.customPartials]
postFooterBefore = ["custom-single-footer.html"]

[params.page.share]
enable = true
wechat = true
copy = true

[params.page.library.js]
QRCode = "https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js"

创建以下文件:

SCSSassets/css/_custom.scss
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
// 全局样式与变量见最后一章

// ========= 文章页 =========

.single {
  // 隐藏文章页脚
  .post-footer {
    display: none;
  }

  .custom-post-footer {
    position: relative; 
    text-align: center;
    border-radius: 10px;
    transition: all 0.3s;
    background-color: var(--c-postinfo-bg);
    border: 1px solid var(--c-postinfo-border);
    margin-block: calc(var(--c-space-12) * 3) var(--c-space-4);
    padding: var(--c-space-12) var(--c-space-8) var(--c-space-6);
    @include media('print') { display: none; }

    .avatar-frame {
      top: -40px; 
      left: 50%;
      z-index: 10;
      width: 80px;
      height: 80px;
      display: flex;
      overflow: hidden;
      position: absolute;
      border-radius: 50%;
      align-items: center;
      box-sizing: border-box;
      justify-content: center;
      font-size: var(--c-font-xs);
      transform: translateX(-50%);
      box-shadow: var(--c-avatar-shadow);
      background-color: var(--c-avatar-bg);
      border: 2px solid var(--c-avatar-border);
      transition: transform 0.3s ease, box-shadow 0.3s ease;

      &:hover {
        transform: translateX(-50%) scale(1.05);
        box-shadow: var(--c-avatar-shadow-hover);
      }

      &::after {
        content: "关于博主";
        top: 0;
        left: 0;
        opacity: 0;
        width: 100%;
        height: 100%;
        display: flex;
        font-weight: 500;
        color: #ffffff; 
        position: absolute;
        border-radius: 50%;
        align-items: center;
        pointer-events: none;
        justify-content: center;          
        transition: opacity 0.3s ease;
        background-color: rgba(0, 0, 0, 0.6);
      }

      &:hover::after {
        opacity: 1;
      }

      img.avatar, 
      .avatar-placeholder {
        width: 100%;
        height: 100%;
        display: block;
        object-fit: cover;
        border-radius: 50%;
      }

      .avatar-placeholder {
        background-color: var(--c-avatar-bg);
      }
    }

    .author-info {
      .author-name {
        font-weight: 600;
        font-size: var(--c-font-l); 
      }

      .author-bio {
        color: var(--c-meta);
        font-size: var(--c-font-xs);
      }
    }

    .action-buttons {
      display: flex;
      flex-wrap: wrap;
      position: relative;
      align-items: center;
      gap: var(--c-space-4);
      justify-content: center;
      font-size: var(--c-font-s);
      margin-block: var(--c-space-2);

      .post-reward {
        padding: 0;
        position: relative;
        text-align: center;
        align-items: center;
        display: inline-flex;

        &:hover .reward-ways[data-mode="static"] {
          opacity: 1;
          visibility: visible;
          transform: translateX(-50%) translateY(0);
        }
      }

      .subscribe-button,
      .reward-button {
        border: none;
        cursor: pointer;
        color: #ffffff;
        font-weight: 500;  
        line-height: 1.2;
        border-radius: 10px;
        align-items: center;
        transition: all 0.3s;
        display: inline-flex;
        text-decoration: none;
        gap: var(--c-space-1);
        box-sizing: border-box;
        justify-content: center;
        padding: calc(var(--c-space-1) * 3);

        &:hover {
          transform: translateY(-1px);
        }
      }      

      .reward-button {
        background-color: var(--c-reward-btn-bg);

        &:hover {
          background-color: var(--c-reward-btn-hover);
        }
      }

      .subscribe-button {
        background-color: var(--c-subscribe-btn-bg);

        &:hover {
          background-color: var(--c-subscribe-btn-hover); 
        }
      }   

      .subscribe-button--solo {
        min-width: 90px;
      } 

      .reward-ways[data-mode="static"] {
        left: 50%;
        opacity: 0;
        z-index: 20;
        bottom: 100%;
        display: grid;
        visibility: hidden;
        position: absolute;
        border-radius: 12px;
        gap: var(--c-space-4);
        box-sizing: border-box;
        justify-content: center;
        transition: all 0.3s ease;
        box-shadow: var(--c-card-shadow);
        background-color: var(--c-card-bg);
        margin-bottom: calc(var(--c-space-1) * 3);
        transform: translateX(-50%) translateY(12px);
        grid-template-columns: repeat(2, minmax(130px, auto));
        padding: var(--c-space-6) var(--c-space-6) var(--c-space-4);
        @include phone { grid-template-columns: 1fr; width: 200px; }   

        // 单个二维码时,改为单列居中
        &:has(> div:only-child) {
          grid-template-columns: 1fr;
          width: auto;
          min-width: 180px;
        }

        &::after {
          content: '';
          position: absolute;
          top: 100%;
          left: 50%;
          border-style: solid;
          border-width: 6px 6px 0;
          transform: translateX(-50%);
          border-color: var(--c-card-bg) transparent transparent;
        }

        div {
          width: 100%;
          display: flex;
          align-items: center;
          gap: var(--c-space-2);
          flex-direction: column;
        }

        img {
          width: 130px;
          height: 130px;
          display: block;
          border-radius: 6px;
          object-fit: contain;
          box-sizing: border-box;
          background-color: #fff;
        }

        span {
          display: block;
          line-height: 1.3;
          text-align: center;
          color: var(--c-meta);
          font-size: var(--c-font-s);
        }
      }            
    }

    .post-license {
      line-height: 1.6;
      color: var(--c-meta);   
      font-size: var(--c-font-xs);   
      margin-block: var(--c-space-2);

      a {
        color: var(--c-link);
        text-decoration: none;

        &:hover {
          text-decoration: underline;
          color: var(--c-link-hover);
        }
      }
    }

    .post-share {
      border-top: 1px solid var(--c-card-border);
      
      .share-label {
        text-align: center;   
        letter-spacing: 1px;
        color: var(--c-meta);
        text-transform: uppercase;
        font-size: var(--c-font-xs);
        margin-block: var(--c-space-2);
      }   
      
      .share-button {
        display: flex;
        flex-wrap: wrap;
        gap: var(--c-space-2);
        justify-content: center;
        margin-block: var(--c-space-2);
      }      

      a {
        width: 34px;
        height: 34px;
        border-radius: 50%;
        align-items: center;
        color: var(--c-meta);
        display: inline-flex;
        transition: all 0.3s;
        justify-content: center;
        background-color: var(--c-meta-bg);

        &:hover {
          color: var(--c-meta-hover);
          transform: translateY(-2px);
          background-color: var(--c-meta-bg-hover);
        }
      }

      a[data-sharer="twitter"] {
        color: #1da1f2;

        &:hover {
          color: #fff;
          background-color: #1da1f2;
        }
      }

      a[data-sharer="facebook"] {
        color: #1877f2;

        &:hover {
          color: #fff;
          background-color: #1877f2;
        }
      }

      a[data-sharer="weibo"] {
        color: #e6162d;

        &:hover {
          color: #fff;
          background-color: #e6162d;
        }
      }

      .wechat {
        color: #2baf2b;

        &:hover {
          color: #fff;
          transform: translateY(-2px);
          background-color: #2baf2b;  
        }
      }

      .wechat-btn {
        position: relative;
        display: inline-flex;
        
        &:hover .qrcode-popup {
          opacity: 1;
          visibility: visible;
          transform: translateX(-50%) translateY(0);
        }
      }

      .qrcode-popup {
        left: 50%;
        opacity: 0;
        z-index: 20;
        bottom: 100%; 
        position: absolute;
        visibility: hidden;
        text-align: center;
        border-radius: 10px;
        transition: all 0.3s ease;
        box-shadow: var(--c-card-shadow);
        background-color: var(--c-card-bg);
        margin-bottom: calc(var(--c-space-1) * 3);
        transform: translateX(-50%) translateY(12px);
        padding: var(--c-space-6) var(--c-space-6) var(--c-space-4); 
        
        &::after {
          top: 100%;
          left: 50%;
          content: '';
          position: absolute;
          border-style: solid;
          border-width: 6px 6px 0;
          transform: translateX(-50%);
          border-color: var(--c-card-bg) transparent transparent;
        }

        .wechat-qrcode {
          width: 130px;
          height: 130px;
          border-radius: 6px;
          display: inline-block;
          background-color: #fff;
          padding: calc(var(--c-space-6) / 10);
        }

        .qrcode-text {
          color: var(--c-meta);
          font-size: var(--c-font-s);
        }        
      }
    }
  }

  .post-nav {
    display: flex;
    border-radius: 10px;
    gap: var(--c-space-4);
    padding: var(--c-space-4);
    transition: box-shadow 0.2s;
    justify-content: space-between;
    background-color: var(--c-postinfo-bg);
    margin-bottom: calc(var(--c-space-8) * 2);
    border: 1px solid var(--c-postinfo-border);
    @include media('print') { display: none !important; }
    @include phone { flex-direction: column; gap: var(--c-space-2); padding: var(--c-space-2); }

    .post-nav-item {
      flex: 1;
      min-width: 0;
      display: flex;
      font-weight: 600;
      align-items: center;
      text-decoration: none;
      gap: var(--c-space-2);
      font-size: var(--c-font-m);
      transition: all 0.3s ease-out;

      &:hover {
        transform: translateX(0) !important;
      }  

      i, svg {
        flex-shrink: 0;
      }           
      
      .nav-title {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }

      &[rel='prev'] {
        justify-content: flex-start;

        .nav-title {
          text-align: left;
        }        
      }

      &[rel='next'] {
        justify-content: flex-end;

        .nav-title {
          text-align: right;
        }            
      }
    }
  }

  .custom-collection-card {
    margin-block: var(--c-space-8);
    @include media('print') { display: none !important; }

    .custom-coll-title {
      display: flex;
      font-weight: 700;
      align-items: center;
      gap: var(--c-space-2);
      color: var(--c-meta-alt);
      font-size: var(--c-font-xxl);
      margin-block: var(--c-space-4);
    }

    .custom-coll-list {
      display: grid;
      gap: var(--c-space-2);
      margin-block: var(--c-space-8);
      grid-template-columns: repeat(3, 1fr);
      @include phone { grid-template-columns: 1fr; }
      @include pad { grid-template-columns: repeat(2, 1fr); }
    }

    .custom-coll-card {
      position: relative;
      overflow: hidden;
      border-radius: 6px;
      text-decoration: none;
      transition: box-shadow 0.2s;
      box-shadow: var(--c-card-shadow); 
      background-color: var(--c-card-bg);

      &:hover {
        box-shadow: var(--c-card-shadow-hover);

        .coll-card-img {
          transform: scale(1.1);
        }      

        .coll-card-img::after {
          background: rgba(0, 0, 0, 0.75);
        }        
      }

    }

    .coll-card-img {
      width: 100%;
      aspect-ratio: 16 / 9;
      background-size: cover;
      background-position: center;
      background-color: var(--c-meta-bg);
      transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.4, 1.1);
      @include phone { aspect-ratio: 3 / 1; background-position: center 100%; }
      @include pad { aspect-ratio: 2 / 1; background-position: center 100%; }

      &::after {
        top: 0;
        left: 0;
        width: 100%;
        content: '';
        height: 100%;        
        position: absolute;
        pointer-events: none;
        transition: background 0.2s;
        background: rgba(0, 0, 0, 0.5);
      }
    }

    .coll-card-info {
      left: 0;
      right: 0;     
      bottom: 6px;
      color: #fff;
      position: absolute;
      text-align: center;
      font-size: var(--c-font-xs);
      text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
      @include pad { bottom: 4px; }

      .coll-card-date {
        opacity: 0.9;
      }

      .coll-card-title {
        font-weight: 500;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }      
    }
  }

  .custom-comment-title {
    display: flex;
    font-weight: 700;
    align-items: center;
    gap: var(--c-space-2);
    color: var(--c-meta-alt);
    font-size: var(--c-font-xxl);
    margin-top: var(--c-space-12);
    @include media('print') { display: none !important; }
  }
}

右下角合集控件

[params.page] collectionList 控制,点击弹出当前文章合集列表。

创建以下文件:

HTMLlayouts/_partials/custom-widget-collection.html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{{- /* 自定义块来源:FixIt/layouts/_partials/widgets.html */ -}}
{{- /* 自定义块来源:FixIt/layouts/posts/single.html */ -}}

{{- /* 合集按钮与右侧抽屉 - 仅文章页且属于合集时显示 */ -}}
{{- if and .IsPage .Params.collections -}}
  {{- $params := partial "function/params.html" -}}
  {{- if $params.collectionList -}}
    {{- /* 调用极简合集列表 */ -}}
    {{- $collectionListHTML := partial "custom-collection-list.html" . -}}
    {{- if and $collectionListHTML (ne $collectionListHTML "") -}}
      {{- /* 获取第一个合集名称 */ -}}
      {{- $collectionName := "" -}}
      {{- $collectionTerms := .GetTerms "collections" -}}
      {{- if $collectionTerms -}}
        {{- $collectionName = (index $collectionTerms 0).LinkTitle -}}
      {{- end -}}
      {{- /* 按钮模板 */ -}}
      <template id="collection-button-template">
        <div class="fixed-button collection-drawer-button" role="button" aria-label="合集">
          {{- dict "Class" "fa-solid fa-layer-group" | partial "plugin/icon.html" -}}
        </div>
      </template>
      {{- /* 合集对话框 */ -}}
      <dialog id="collection-dialog" aria-labelledby="collection-dialog-title" role="dialog">
        <div class="collection-dialog">
          <h2 class="collection-dialog-title" id="collection-dialog-title">合集 · {{ $collectionName }}</h2>
          <div class="collection-dialog-content" id="collection-dialog-content">
            {{- $collectionListHTML | safeHTML -}}
          </div>
        </div>
      </dialog>
    {{- end -}}
  {{- end -}}
{{- end -}}

创建以下文件:

HTMLlayouts/_partials/custom-collection-list.html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{{- /* 自定义块来源:FixIt/layouts/_partials/single/collection-list.html */ -}}

{{- $params := partial "function/params.html" -}}

{{- if .Params.collections | and $params.collectionList -}}
  {{- $collectionTerms := .GetTerms "collections" -}}
  {{- range $collectionTerms -}}
    {{- $pages := (where .Pages "Params.Weight" "!=" nil) | append (where .Pages "Params.Weight" "eq" nil).ByDate -}}

    {{- /* ======================== 修改点 1:开始 ======================== */ -}}
    {{- /* 极简合集列表:移除折叠结构和底部导航,仅保留文章标题链接 */ -}}
    <ul class="collection-drawer-list">
      {{- range $pages -}}
        {{- $capitalizeTitles := .Param "capitalizeTitles" -}}
        {{- $title := .Params.shortTitle | default .LinkTitle -}}
        {{- $title = cond $capitalizeTitles (title $title) $title -}}
        <li>
          {{- if $.Eq . -}}
            <a class="active" href="{{ .RelPermalink }}">{{ $title }}</a>
          {{- else -}}
            <a href="{{ .RelPermalink }}">{{ $title }}</a>
          {{- end -}}
        </li>
      {{- end -}}
    </ul>
    {{- /* ======================== 修改点 1:结束 ======================== */ -}}
    
  {{- end -}}
{{- end -}}

创建以下文件:

JavaScriptassets/js/custom.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(function() {

  // ========== 合集抽屉(仅文章页且存在对话框) ==========

  (function() {
    if (!document.getElementById('collection-dialog')) return;

    function initCollectionWidget() {
      const container = document.querySelector('.fixed-buttons');
      if (!container) return;
      if (container.querySelector('.collection-drawer-button')) return;

      const template = document.getElementById('collection-button-template');
      if (!template) return;
      const button = template.content.firstElementChild.cloneNode(true);

      const tocBtn = container.querySelector('.toc-drawer-button');
      const commentBtn = container.querySelector('.view-comments');

      if (tocBtn && tocBtn.nextSibling) {
        container.insertBefore(button, tocBtn.nextSibling);
      } else if (commentBtn) {
        container.insertBefore(button, commentBtn);
      } else {
        container.appendChild(button);
      }

      const dialog = document.getElementById('collection-dialog');
      if (!dialog) return;

      button.addEventListener('click', (e) => {
        e.stopPropagation();
        dialog.showModal();
      });

      dialog.addEventListener('click', (e) => {
        const rect = dialog.getBoundingClientRect();
        const isInDialog = (rect.top <= e.clientY && e.clientY <= rect.top + rect.height &&
          rect.left <= e.clientX && e.clientX <= rect.left + rect.width);
        if (!isInDialog) dialog.close();
      });
    }

    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', initCollectionWidget);
    } else {
      initCollectionWidget();
    }
  })();

})();  

修改主题配置:

TOMLconfig/_default/hugo.toml
1
2
3
4
5
[params.customPartials]
widgets = ["custom-widget-collection.html"]

[params.page]
collectionList = true

创建以下文件:

SCSSassets/css/_custom.scss
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
// 全局样式与变量见最后一章

// ========= 按钮控件 =========

// 合集按钮:取消注释即只显示在移动端
/*.collection-drawer-button {
  @include media('md', 'up') { display: none !important; }
}*/

// 合集列表
#collection-dialog {
  opacity: 0;
  border: none;
  height: 100dvh;
  max-width: 100%;
  margin-right: 0;
  max-height: 100%; 
  translate: 100vw 0;
  width: MIN(calc(100% - 4rem), 460px);
  background-color: var(--c-collection-bg);
  border-left: 1px solid var(--c-collection-border);
  transition: display 0.2s allow-discrete, overlay 0.2s allow-discrete, translate 0.2s, opacity 0.2s 0.4s;

  a:focus {
    outline: none !important;
    box-shadow: none !important;
  }
  
  .collection-dialog {
    max-width: 100%;
    margin-inline: var(--c-space-6);

    .collection-dialog-title {
      font-weight: bold;
      line-height: 1.7;
      font-size: var(--c-font-xxl);
      margin-block: var(--c-space-4);
      text-transform: none !important;
    }

    .collection-dialog-content {
      line-height: 1.6;
      margin-block: var(--c-space-4);

      nav {
        overflow: auto;
        max-height: calc(100dvh - 5rem);
      }

      ul {
        margin: 0;
        list-style: none;
        text-indent: -0.8rem;
        padding-left: var(--c-space-4);

        a:first-child::before {
          bottom: 2px;
          content: '|';
          position: relative;
          font-weight: bolder;
          color: var(--c-link);
          margin-right: var(--c-space-2);
        }
      }

      a.active {
        font-weight: bold;
        color: var(--c-link);
      }

      a.active::before {
        color: var(--c-link-hover) !important;
      }
    }
  }

  &::backdrop {
    opacity: 0;
    backdrop-filter: blur(2px);
    background-color: rgba(0, 0, 0, 0.25);
    transition: display 0.5s allow-discrete, overlay 0.5s allow-discrete, opacity 0.2s 0.4s;
  }

  &[open], 
  &[open]::backdrop {
    opacity: 1;
    transition: display 0.2s allow-discrete, overlay 0.2s allow-discrete, translate 0.2s, opacity 0.2s;
  }

  &[open] {
    translate: 0 0;
  }

  @starting-style {
    &[open], 
    &[open]::backdrop {
      opacity: 0;
    }

    &[open] {
      translate: 100vw 0;
    }
  }
}

html:has(#collection-dialog[open]) {
  overflow: hidden;
}

代码块语言显示

硬编码语言名称,增加 code-lang-name 占位容器,不依赖 CSS 伪元素。

创建以下文件:

HTMLlayouts/_partials/function/code-header.html
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{{- /* 覆盖来源:FixIt/layouts/_partials/function/code-header.html */ -}}

{{- /* Code header for classic mode code blocks */ -}}
{{- $config := .Config -}}
{{- $wrapper := .Wrapper -}}
{{- $lang := cond (transform.CanHighlight .Type) (lower .Type) "fallback" -}}
{{- $name := $config.name -}}
{{- $lineNosBtn := "" -}}
{{- $lineWrapBtn := "" -}}
{{- $editBtn := "" -}}
{{- $copyBtn := "" -}}
{{- $downloadBtn := "" -}}
{{- $fullscreenBtn := "" -}}
{{- $foldIcon := dict "Class" "arrow fa-solid fa-chevron-down" | partial "plugin/icon.html" -}}

{{- /* ======================== 修改点 1:开始 ======================== */ -}}
{{- /* 使用硬编码映射将常见语言标识符转换为可读名称,未映射的回退为原始标识符并首字母大写 */ -}}
{{- /* 代码语言来源:FixIt/assets/css/_maps/_code-type.scss */ -}}
{{- $codeTypes := .Site.Data.code_types -}}
{{- $langMap := dict
  "bash" "Bash"
  "bat" "Batchfile"
  "batch" "Batchfile"
  "c" "C"
  "clojure" "Clojure"
  "cmake" "CMake"
  "cmd" "CMD"
  "cpp" "C++"
  "csharp" "C#"
  "css" "CSS"
  "dart" "Dart"
  "diff" "Diff"
  "dockercompose" "Docker Compose"
  "dockerfile" "Dockerfile"
  "dockerignore" "Docker Ignore"
  "elixir" "Elixir"
  "erlang" "Erlang"
  "gitignore" "Git Ignore"
  "go" "Go"
  "gradle" "Gradle"
  "graphql" "GraphQL"
  "handlebars" "Handlebars"
  "haskell" "Haskell"
  "html" "HTML"
  "ini" "INI"
  "java" "Java"
  "js" "JavaScript"
  "json" "JSON"
  "javascript" "JavaScript"
  "jsx" "React JSX"
  "kotlin" "Kotlin"
  "lua" "Lua"
  "makefile" "Makefile"
  "markdown" "Markdown"
  "matlab" "MATLAB"
  "nginx" "Nginx"
  "ocaml" "OCaml"
  "perl" "Perl"
  "php" "PHP"
  "powershell" "PowerShell"
  "properties" "Properties"
  "protobuf" "Protocol Buffer"
  "python" "Python"
  "r" "R"
  "ruby" "Ruby"
  "rust" "Rust"
  "sass" "Sass"
  "scala" "Scala"
  "scss" "SCSS"
  "shell" "Shell"
  "sql" "SQL"
  "svelte" "Svelte"
  "swift" "Swift"
  "text" "Plaintext"
  "toml" "TOML"
  "tsx" "React TSX"
  "typescript" "TypeScript"
  "vb" "VBA"
  "vim" "Vim Script"
  "vue" "Vue"
  "xml" "XML"
  "yaml" "YAML"
  "zsh" "Zsh"
-}}
{{- $langKey := $lang | lower -}}
{{- $readableLang := index $langMap $langKey -}}
{{- if not $readableLang -}}
  {{- $readableLang = $lang | title -}}
{{- end -}}
{{- $langSpan := printf `<span class="code-lang-name">%s</span>` $readableLang -}}
{{- $titleEl := printf `<span class="code-title">%s%s</span>` $foldIcon $langSpan -}}
{{- /* ======================== 修改点 1:结束 ======================== */ -}}

{{- $ellipsisBtn := printf `<span class="ellipses-btn" aria-label="Show more options" role="button">%s</span>` (dict "Class" "fa-solid fa-ellipsis-h" | partial "plugin/icon.html") -}}

{{- if $config.title -}}
  {{- $titleEl = printf `<span class="code-title">%s%s<span class="title-inner">%s</span></span>` $foldIcon $langSpan $config.title -}}
{{- end -}}
{{- if $config.linenostoggler -}}
  {{- $lineNosIcon := dict "Class" "fa-solid fa-list-ol" | partial "plugin/icon.html" -}}
  {{- $lineNosBtn = printf `<span class="action-btn line-nos-btn" aria-label="%s" role="button" title="%s" data-ct-tooltip>%s</span>` (T "assets.toggleLineNumbers") (T "assets.toggleLineNumbers") $lineNosIcon -}}
{{- end -}}
{{- if $config.linewraptoggler -}}
  {{- $lineWrapIcon := dict "Class" "fa-solid fa-right-left" | partial "plugin/icon.html" -}}
  {{- $lineWrapBtn = printf `<span class="action-btn line-wrap-btn" aria-label="%s" role="button" title="%s" data-ct-tooltip>%s</span>` (T "assets.toggleLineWrap") (T "assets.toggleLineWrap") $lineWrapIcon -}}
{{- end -}}
{{- if $config.editable -}}
  {{- $editIcon := dict "Class" "fa-solid fa-pen-to-square" | partial "plugin/icon.html" -}}
  {{- $editBtn = printf `<span class="action-btn edit-btn" aria-label="%s" role="button" title="%s" data-ct-tooltip>%s</span>` (T "assets.toggleCodeEditable") (T "assets.toggleCodeEditable") $editIcon -}}
{{- end -}}
{{- if $config.copyable -}}
  {{- $copyIcon := dict "Class" "fa-regular fa-clone" | partial "plugin/icon.html" -}}
  {{- $copyBtn = printf `<span class="action-btn copy-btn" aria-label="%s" role="button" title="%s" data-copied-text="%s" data-ct-tooltip>%s</span>` (T "assets.copyToClipboard") (T "assets.copyToClipboard") (T "assets.copiedText") $copyIcon -}}
{{- end -}}
{{- if $config.downloadable -}}
  {{- $downloadIcon := dict "Class" "fa-solid fa-download" | partial "plugin/icon.html" -}}
  {{- $downloadBtn = printf `<span class="action-btn download-btn" aria-label="%s" role="button" title="%s" data-ct-tooltip>%s</span>` (T "assets.downloadCode") (T "assets.downloadCode") $downloadIcon -}}
{{- end -}}
{{- if $config.fullscreen -}}
  {{- $fullscreenIcon := dict "Class" "fa-solid fa-expand" | partial "plugin/icon.html" -}}
  {{- $fullscreenBtn = printf `<span class="action-btn fullscreen-btn" aria-label="%s" role="button" title="%s" data-ct-tooltip>%s</span>` (T "assets.toggleCodeFullscreen") (T "assets.toggleCodeFullscreen") $fullscreenIcon -}}
{{- end -}}
{{- with $config.name -}}
  {{- $titleEl = replace $titleEl `<span class="code-title">` (printf `<span class="code-title" data-name="%s">` .) -}}
{{- end -}}
{{- $codeHeader := printf `<div class="code-header language-%s">%s%s%s%s%s%s%s%s</div>` $lang $titleEl $ellipsisBtn $lineNosBtn $lineWrapBtn $editBtn $copyBtn $downloadBtn $fullscreenBtn -}}
{{- $wrapper = replaceRE `(<div class="code-wrapper">)` (printf "%s$1" $codeHeader) $wrapper -}}

{{- return $wrapper -}}

创建以下文件:

SCSSassets/css/_custom.scss
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14

// ========= 文章页 =========

.single {
  .content {
    .highlight {
      .code-title {
        &::after {
          content: none !important;
        }
      }
    } 
  }
}      

导航栏滚动标题

滚动时替换导航栏站点名称为文章标题,移动端可选禁用。

创建以下文件:

JavaScriptassets/js/custom.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(function() {

  // ========== 滚动标题(仅文章页) ==========

  (function() {
    if (!document.querySelector('.page.single')) return;

    // 移动端可选禁用(默认注释)
    // if (window.matchMedia('(max-width: 767px)').matches) return;

    const desktopHeader = document.getElementById('header-desktop');
    const mobileHeader = document.getElementById('header-mobile');
    const titleSpan = document.querySelector('.single-title span');
    if (!titleSpan || !desktopHeader) return;

    const articleTitle = titleSpan.innerText.trim();
    const THRESHOLD = 100;

    let desktopOriginal = null;
    let mobileOriginal = null;

    function setScrolled(header, scrolled) {
      const titleDiv = header.querySelector('.header-title');
      if (titleDiv) {
        if (scrolled) titleDiv.classList.add('scrolled');
        else titleDiv.classList.remove('scrolled');
      }
    }

    function replaceTitle(header, isDesktop) {
      const textSpan = header.querySelector('.header-title-text');
      if (!textSpan) return;
      if (isDesktop && desktopOriginal === null) desktopOriginal = textSpan.innerText;
      else if (!isDesktop && mobileOriginal === null) mobileOriginal = textSpan.innerText;
      textSpan.innerText = articleTitle;
      setScrolled(header, true);
    }

    function restoreTitle(header, isDesktop) {
      const textSpan = header.querySelector('.header-title-text');
      if (!textSpan) return;
      if (isDesktop && desktopOriginal !== null) {
        textSpan.innerText = desktopOriginal;
        desktopOriginal = null;
      } else if (!isDesktop && mobileOriginal !== null) {
        textSpan.innerText = mobileOriginal;
        mobileOriginal = null;
      }
      setScrolled(header, false);
    }

    let ticking = false;
    function update() {
      const show = window.scrollY > THRESHOLD;
      if (show) {
        if (desktopOriginal === null) replaceTitle(desktopHeader, true);
        if (mobileHeader && mobileOriginal === null) replaceTitle(mobileHeader, false);
      } else {
        if (desktopOriginal !== null) restoreTitle(desktopHeader, true);
        if (mobileHeader && mobileOriginal !== null) restoreTitle(mobileHeader, false);
      }
    }

    window.addEventListener('scroll', () => {
      if (!ticking) {
        requestAnimationFrame(() => { update(); ticking = false; });
        ticking = true;
      }
    });
    update();
  })();

})();   

创建以下文件:

SCSSassets/css/_custom.scss
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 全局样式与变量见最后一章

// ========= 导航栏 =========

header {
  box-shadow: var(--c-header-shadow);
  -webkit-backdrop-filter: blur(12px);
  background-color: var(--c-header-bg);
  border-bottom: 1px solid var(--c-header-border);
  backdrop-filter: blur(20px) brightness(1.02) saturate(1.1);
}

.header-wrapper {
   padding: 0 var(--c-space-8) !important;
   @include phone { padding: 0 var(--c-space-4) !important; }
}

.header-title {
  .header-title-text {
    margin-inline: var(--c-space-2);
  }

  &.scrolled {
    .header-title-text {
      opacity: 0.9;
      font-size: var(--c-font-xl);
      text-shadow: 0 0 2px rgba(255, 255, 255, 0.3);
      transition: text-shadow 0.2s ease, opacity 0.2s ease;
    }
  }
}  

脚注悬浮提示

FixIt 2026.5.19 | 更改

动态添加参考资料标题,优化脚注内容显示,自定义脚注悬浮提示(支持链接点击、移除原生 title 提示),调整提示框位置与样式。

创建以下文件:

JavaScriptassets/js/custom.js
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
(function() {

  // ========== 脚注(仅文章页) ==========

  (function() {
    if (!document.querySelector('.page.single')) return;

    // 为脚注区域添加“参考资料”标题
    function addFootnotesTitle() {
      const footnotesDiv = document.querySelector('.footnotes[role="doc-endnotes"]');
      if (!footnotesDiv) return;
      if (footnotesDiv.querySelector('.footnotes-title')) return;
      
      const title = document.createElement('h2');
      title.className = 'footnotes-title';
      title.textContent = '参考资料';
      footnotesDiv.insertBefore(title, footnotesDiv.firstChild);
    }

    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', addFootnotesTitle);
    } else {
      addFootnotesTitle();
    }
  })();

  (function() {
    if (!document.querySelector('.page.single')) return;

    let currentTip = null;
    let hideTimer = null;

    function cleanContent(html) {
      const div = document.createElement('div');
      div.innerHTML = html;
      // 移除返回链接(↩)
      const backLink = div.querySelector('.footnote-return, a[href^="#fnref:"]');
      if (backLink) backLink.remove();
      return div.innerHTML;
    }

    function scrubAttributes(el) {
      const attrs = ['title', 'data-ct-title', 'data-ct-original-title', 'data-original-title', 'tooltip'];
      attrs.forEach(attr => el.removeAttribute(attr));
      if (el.parentElement) {
        attrs.forEach(attr => el.parentElement.removeAttribute(attr));
      }
      if (el.parentElement && el.parentElement.parentElement) {
        attrs.forEach(attr => el.parentElement.parentElement.removeAttribute(attr));
      }
    }

    function showTooltip(anchor) {
      const href = anchor.getAttribute('href');
      if (!href || href[0] !== '#') return;
      const target = document.getElementById(href.slice(1));
      if (!target) return;

      if (currentTip) currentTip.remove();
      if (hideTimer) clearTimeout(hideTimer);

      const tip = document.createElement('div');
      tip.className = 'custom-fn-tooltip';
      tip.innerHTML = cleanContent(target.innerHTML);
      document.body.appendChild(tip);

      const aRect = anchor.getBoundingClientRect();
      const tRect = tip.getBoundingClientRect();
      const sx = window.scrollX, sy = window.scrollY;

      let left = aRect.left + sx - 14;
      let top = aRect.bottom + sy + 10;
      left = Math.min(Math.max(left, sx + 5), sx + window.innerWidth - tRect.width - 5);
      if (top + tRect.height > sy + window.innerHeight - 10) {
        top = aRect.top + sy - tRect.height - 6;
      }
      tip.style.position = 'absolute';
      tip.style.top = top + 'px';
      tip.style.left = left + 'px';

      currentTip = tip;

      tip.addEventListener('mouseenter', () => {
        if (hideTimer) clearTimeout(hideTimer);
      });
      tip.addEventListener('mouseleave', () => {
        hideTimer = setTimeout(() => {
          if (currentTip) {
            currentTip.remove();
            currentTip = null;
          }
        }, 800);
      });
    }

    function hideTooltip() {
      if (hideTimer) clearTimeout(hideTimer);
      hideTimer = setTimeout(() => {
        if (currentTip) {
          currentTip.remove();
          currentTip = null;
        }
      }, 800);
    }

    function preventJump(anchor) {
      anchor.addEventListener('click', (e) => e.preventDefault());
    }

    function init() {
      const refs = document.querySelectorAll('.footnote-ref, a[href^="#fn:"]');
      refs.forEach(el => {
        scrubAttributes(el);
        preventJump(el);
        el.addEventListener('mouseenter', () => showTooltip(el));
        el.addEventListener('mouseleave', hideTooltip);
      });
    }

    const observer = new MutationObserver(() => {
      const refs = document.querySelectorAll('.footnote-ref, a[href^="#fn:"]');
      refs.forEach(scrubAttributes);
    });
    observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['title'] });

    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', init);
    } else {
      init();
    }
  })();

})();

修改主题配置:

TOMLconfig/_default/hugo.toml
1
2
[params]
tooltip = false

创建以下文件:

SCSSassets/css/_custom.scss
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 全局样式与变量见最后一章

// ========= 文章页 =========

.single {
  .content {  
    .footnotes {
      margin-block: var(--c-space-10);

      .footnotes-title {
        color: var(--c-meta-alt);
        margin-block: var(--c-space-2) calc(var(--c-space-1) * 3);
      }      
    }
  }
}

.custom-fn-tooltip {
  z-index: 10000;
  line-height: 1.5;
  max-width: 260px;
  border-radius: 6px;
  position: absolute;
  pointer-events: auto;
  word-wrap: break-word;
  font-size: var(--c-font-xs);
  color: var(--c-tooltip-color);
  background: var(-c--tooltip-bg);
  box-shadow: 0 6px 16px rgba(0,0,0,0.1);
  padding-inline: calc(var(--c-space-1) * 3);
  
  a {
    text-decoration: none;

    &:hover {
      color: var(--c-link-hover);
      text-decoration: underline;
    }
  }
}  

全局样式与变量

创建以下文件:

SCSSassets/css/_override.scss
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
:root {
  // 字号
  --c-font-base: clamp(0.96875rem, 0.85rem + 0.2vw, 1rem);
  --c-font-xxs: calc(0.625 * var(--c-font-base));
  --c-font-xs: calc(0.75  * var(--c-font-base));
  --c-font-s: calc(0.875 * var(--c-font-base));
  --c-font-m: var(--c-font-base); 
  --c-font-l: calc(1.125 * var(--c-font-base));
  --c-font-xl: calc(1.25 * var(--c-font-base));
  --c-font-xxl: calc(1.5 * var(--c-font-base));
  --c-font-xxxl: calc(1.75 * var(--c-font-base));

  // 边距
  --c-space-1: 0.25rem;   /* 1 unit = 4px */
  --c-space-2: calc(var(--c-space-1) * 2);    /* 0.5rem */
  --c-space-4: calc(var(--c-space-1) * 4);    /* 1rem   */
  --c-space-6: calc(var(--c-space-1) * 6);    /* 1.5rem */
  --c-space-8: calc(var(--c-space-1) * 8);    /* 2rem   */
  --c-space-10: calc(var(--c-space-1) * 10);  /* 2.5rem */
  --c-space-12: calc(var(--c-space-1) * 12);  /* 3rem   */

  @media (max-width: 680px) { --c-space-1: 0.22rem; }
  @media (min-width: 681px) and (max-width: 1200px) { --c-space-1: 0.23rem; }

  // 颜色
  --c-global-font-color: #333;

  --c-card-bg: #fefefe;
  --c-card-border: #e5e7eb; 
  --c-card-shadow: 0 2px 8px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --c-card-shadow-hover: 0 12px 24px -8px rgba(0, 0, 0, 0.12);
  --c-card-border-hover: rgba(0, 0, 0, 0.08);

  --c-header-bg: rgba(255, 255, 255, 0.68);
  --c-header-border: rgba(0, 0, 0, 0.06);
  --c-header-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);

  --c-meta-1: #8b949e;
  --c-meta-2: #3a3a44;
  --c-meta-hover: #000;
  --c-meta-bg: rgba(0, 0, 0, 0.05);
  --c-meta-bg-hover: rgba(0, 0, 0, 0.1);

  --c-tech-color: #2376b7; 
  --c-tech-hover: #1a5a8a;
  --c-tech-bg: rgba(35, 118, 183, 0.12);
  --c-tech-bg-hover: rgba(35, 118, 183, 0.2);  

  --c-work-color: #28a050;
  --c-work-hover: #1e6e3a;
  --c-work-bg: rgba(40, 160, 80, 0.12);
  --c-work-bg-hover: rgba(40, 160, 80, 0.2);
  
  --c-life-color: #e6781e;
  --c-life-hover: #b85c12;
  --c-life-bg: rgba(230, 120, 30, 0.12);
  --c-life-bg-hover: rgba(230, 120, 30, 0.2);

  --c-postinfo-bg: #fafbfc;
  --c-postinfo-border: rgba(0, 0, 0, 0.06);
  --c-avatar-bg: #fefefe;
  --c-avatar-border: #e0e4e8;
  --c-avatar-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --c-avatar-shadow-hover: 0 8px 20px rgba(0, 0, 0, 0.12);
  --c-reward-btn-bg: #e65c3c;
  --c-reward-btn-hover: #c94b2c;
  --c-subscribe-btn-bg: #45b37a;
  --c-subscribe-btn-hover: #3ab47a;

  --c-link-color: #2376b7;
  --c-link-hover: #ea517f;  
  --c-toc-color: #161209;
  --c-collection-bg: #fefefe;
  --c-collection-border: #f0f0f0;
  --c-tooltip-bg: #fefefe;
  --c-tooltip-color: #0f172a;
  --c-summary-update-bg: #ff5722;

  --c-book-corner-bg: #f99b01;
  --c-book-corner-shadow: rgba(0, 0, 0, 0.2);
  --c-book-corner-border: #e68900;
  --c-book-star-full: #ffac2d;
  --c-book-star-empty: #ddd;

  --c-hea-level-1: #9be9a8;
  --c-hea-level-2: #40c463;
  --c-hea-level-3: #30a14e;
  --c-hea-level-4: #216e39;  
  --c-hea-publish-bg: #dbeafe;
  --c-hea-publish-color: #1d4ed8;
  --c-hea-update-bg: #fef3c7;
  --c-hea-update-color: #b45309;  
}


[data-theme="dark"] {
  // 颜色
  --c-global-font-color: #c0c0c0;
  
  --c-card-bg: #35373c;
  --c-card-border: #46494f;
  --c-card-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.1);
  --c-card-shadow-hover: 0 16px 28px -8px rgba(0, 0, 0, 0.35);
  --c-card-border-hover: rgba(255, 255, 255, 0.1);  

  --c-header-bg: rgba(46, 47, 51, 0.8);
  --c-header-border: rgba(255, 255, 255, 0.04); 
  --c-header-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);

  --c-meta-1: #7d8792;
  --c-meta-2: #c0c0c8;
  --c-meta-hover: #ffffff;
  --c-meta-bg: rgba(255, 255, 255, 0.08);
  --c-meta-bg-hover: rgba(255, 255, 255, 0.15);

  --c-tech-color: #1781b5;
  --c-tech-hover: #2a8fbf;
  --c-tech-bg: rgba(23, 129, 181, 0.2);
  --c-tech-bg-hover: rgba(23, 129, 181, 0.3);

  --c-work-color: #8ad6a8;
  --c-work-hover: #6ec08a;
  --c-work-bg: rgba(60, 180, 100, 0.2);
  --c-work-bg-hover: rgba(60, 180, 100, 0.3);
  
  --c-life-color: #f5bc7a;
  --c-life-hover: #e09c5a;
  --c-life-bg: rgba(240, 150, 60, 0.2);
  --c-life-bg-hover: rgba(240, 150, 60, 0.3);

  --c-postinfo-bg: #2f3136;
  --c-postinfo-border: rgba(255, 255, 255, 0.06);
  --c-avatar-bg: #2f3136;
  --c-avatar-border: #5a5e66;
  --c-avatar-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --c-avatar-shadow-hover: 0 8px 20px rgba(0, 0, 0, 0.5);
  --c-reward-btn-bg: #a5452a;
  --c-reward-btn-hover: #c55a3a;
  --c-subscribe-btn-bg: #1e6d3a;
  --c-subscribe-btn-hover: #155a2e;

  --c-link-color: #1781b5;
  --c-link-hover: #cc5595;
  --c-toc-color: #b1b1ba;
  --c-collection-bg: #292a2e;
  --c-collection-border: #383838;
  --c-tooltip-bg: #39393c;
  --c-tooltip-color: #e2e2e6;  
  --c-summary-update-bg: #cc4a1a;

  --c-book-corner-bg: #b84b00;
  --c-book-corner-shadow: rgba(0, 0, 0, 0.4);
  --c-book-corner-border: #963b00;
  --c-book-star-full: #ffac2d;
  --c-book-star-empty: #ddd;

  --c-hea-level-1: #2a5a40;
  --c-hea-level-2: #3a7a58;
  --c-hea-level-3: #4a9a70;
  --c-hea-level-4: #5aba88;
  --c-hea-publish-bg: #2a4a7a;
  --c-hea-publish-color: #8ab4f8;
  --c-hea-update-bg: #5a3a1a;
  --c-hea-update-color: #f5b342;
}

创建以下文件:

SCSSassets/css/_custom.scss
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// ========= 全局 =========

// 字体
body { font-size: var(--c-font-m); color: var(--c-global-font-color); }
h1 { font-size: var(--c-font-xxl); }
h2 { font-size: var(--c-font-xl); }
h3, h4 { font-size: var(--c-font-l); }

// 暗黑模式
[data-theme="dark"] { img:not(.no-darken) { filter: brightness(0.95); } }
[data-theme="dark"] { .single .content { b, strong { color: #c8c8c8; } } }

// 设备响应使用方法:@include phone { } @include pad { } @include pc { } */
@mixin phone { @media (max-width: 680px) { @content; } } 
@mixin pad { @media (min-width: 681px) and (max-width: 1200px) { @content; } } 
@mixin pc { @media (min-width: 1201px) { @content; } } 

// 分类标签使用方法:@include category-color-styles;
@mixin category-color-styles {
  $cats: tech, work, life;
  @each $cat in $cats {
    &[href*="/#{$cat}/"] {
      color: var(--c-#{$cat}-color);
      background-color: var(--c-#{$cat}-bg);

      &:hover {
        color: var(--c-#{$cat}-hover);
        background-color: var(--c-#{$cat}-bg-hover);
      }
    }
  }
}
留言交流