此客製化基於 hugo blowfish theme 完成。
大部分的程式都由 GPT 完成,偉哉 GPT。
1. 超連結
游標移動到連結時變色+底線。範例
在assets/css/custom.css新增以下:
.article-content a {
color: rgb(65, 105, 225); /* 使用淡藍色 */
}
/* 懸停時底線改為粗線並增加距離 */
.article-content a:hover, .article-content a:focus {
color: rgb(0, 0, 139); /* 設定連結懸停和聚焦狀態下的顏色 */
text-decoration: underline; /* 添加連結懸停時的底線 */
text-decoration-thickness: 2px; /* 設定底線的粗線 */
text-decoration-skip-ink: none; /* 避免底線與文字重疊 */
text-underline-offset: 4.5px; /* 增加底線與文字的距離*/
}
2. 文章存檔頁面
列出所有文章,無論是哪一種分類,範例。
在 layouts/_default/archive.html
新增以下:
在 content/archives
新增 _index.md:
---
title: "所有文章"
layout: "archive"
description: "所有文章列表"
---
最後,在menus.zh-tw.toml新增:
[[footer]]
name = "所有文章"
pageRef = "archives"
weight = 40
3. 閱讀進度
加上文章閱讀進度比例。
- 在
static/js/progress-bar.js
貼上
document.addEventListener('scroll', function () {
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
const clientHeight = document.documentElement.clientHeight || window.innerHeight;
const scrollPercent = (scrollTop / (scrollHeight - clientHeight)) * 100;
document.getElementById('progress-bar').style.width = scrollPercent + '%';
});
- 在
layouts/_default/single.html
找到<header> <header>
,在他的前後分別貼上
<div id="progress-bar"></div>
<script src="{{ "js/progress-bar.js" | relURL }}"></script>
- 在
assets/css/custom.css
貼上
#progress-bar {
position: fixed;
top: 0;
left: 0;
width: 0%;
height: 3px;
background-color: #dc3434; /* You can change this color */
z-index: 50; /* 99999 */
}
4. 簡碼 - hint
移植 alex-shpak/hugo-book 的 hint shortcode。
Info
Markdown content
Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
Warning
Markdown content
Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
Danger
Markdown content
Lorem markdownum insigne. Olympo signis Delphis! Retexi Nereius nova develat stringit, frustra Saturnius uteroque inter! Oculis non ritibus Telethusa
在 assets/css/custom.css
加入
.book-hint {
padding: 0.5em 1em;
margin: 1em 0;
border-left: 6px solid;
border-radius: 4px;
font-style: normal; /* 確保文字不斜體 */
font-weight: normal; /* 確保文字不粗體 */
}
.book-hint .hint-content {
margin: 0;
font-style: normal; /* 確保文字不斜體 */
font-weight: normal; /* 確保文字不粗體 */
}
.book-hint .hint-content > p:first-child {
margin-top: 0;
font-style: normal; /* 確保文字不斜體 */
font-weight: normal; /* 確保文字不粗體 */
}
.book-hint .hint-content > p:last-child {
margin-bottom: 0;
font-style: normal; /* 確保文字不斜體 */
font-weight: normal; /* 確保文字不粗體 */
}
/* Info hint */
.book-hint.info {
border-color: #2196f3;
background-color: rgba(33, 150, 243, 0.1);
}
/* Warning hint */
.book-hint.warning {
border-color: #ffeb3b;
background-color: rgba(255, 235, 59, 0.1);
}
/* Danger hint */
.book-hint.danger {
border-color: #f44336;
background-color: rgba(244, 67, 54, 0.1);
}
.book-hint .expand-wrapper {
margin-top: 1em;
/* 為所有在 hint 內的 expand 添加上邊距 */
}
.book-hint>p:first-child+.expand-wrapper,
.book-hint>.expand-wrapper:first-child {
margin-top: 0;
/* 如果 expand 是 hint 中的第一個元素或緊跟在第一個段落後面,則移除頂部邊距 */
}
.book-hint .hint-content > h1,
.book-hint .hint-content > h2,
.book-hint .hint-content > h3,
.book-hint .hint-content > h4,
.book-hint .hint-content > h5,
.book-hint .hint-content > h6 {
margin-top: 0.5rem;
margin-bottom: 0.5rem;
}
新增 layouts/shortcodes/hint.html
並貼上
<blockquote class="book-hint {{ .Get 0 }}">
<div class="hint-content">
{{ .Inner | .Page.RenderString }}
</div>
</blockquote>
5. 簡碼 - expand
比較美觀的 expand UI,一樣從 alex-shpak/hugo-book 拿來的,範例如下:
新增 layouts/shortcodes/expand.html
<div class="expand-wrapper prose dark:prose-invert max-w-prose zen-mode-content">
<input id="{{ .Get "id" | default (printf "expand-%d" (.Ordinal)) }}" class="expand-toggle" type="checkbox" {{ if or (.Get "open") (in .Params "open") }}checked{{ end }}>
<label for="{{ .Get "id" | default (printf "expand-%d" (.Ordinal)) }}" class="expand-title">
<span class="expand-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-down">
<polyline points="6 9 12 15 18 9"></polyline>
</svg>
</span>
{{- $summary := cond .IsNamedParams (.Get "title") (.Get 0) -}}
{{ $summary | .Page.RenderString }}
</label>
<div class="expand-content">
<div class="expand-inner">
{{ .Inner | .Page.RenderString }}
</div>
</div>
</div>
新增 assets/css/custom.css
.expand-wrapper {
border: 1px solid #ddd;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
margin-bottom: 1rem;
background-color: #fff;
/* 預設背景顏色 */
width: 100%;
transition: max-width 0.3s ease-in-out;
}
body.zen-mode-enable .zen-mode-content {
max-width: 100% !important;
}
.expand-toggle {
display: none;
}
.expand-title {
display: flex;
align-items: center;
padding: 0.75rem 1rem;
/* 調整上下邊距 */
background-color: #f7f7f7;
/* 預設背景顏色 */
color: #333;
/* 預設文字顏色 */
cursor: pointer;
transition: background-color 0.3s ease, color 0.3s ease;
font-weight: normal;
/* 取消粗體樣式 */
}
.expand-title:hover {
background-color: #e0e0e0;
}
.expand-title .expand-icon {
margin-right: 0.5rem;
/* 調整圖標與文字之間的距離 */
}
.expand-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.5s cubic-bezier(0, 1, 0, 1);
background-color: #fff;
padding: 0 1.8rem;
}
.expand-toggle:checked~.expand-content {
max-height: 8000px;
/* 可以根據需要調整 */
transition: max-height 0.8s ease-in-out;
}
.expand-inner {
margin: -0.5rem 0;
/* 使用負邊距縮短內容區域與邊框的距離 */
padding: 0.5rem 0;
/* 可根據需要調整 */
color: #333;
/* 預設文字顏色 */
}
/* 暗色模式樣式 */
.dark .expand-wrapper {
border-color: #444;
/* 暗色模式下的邊框顏色 */
background-color: #222;
/* 暗色模式下的背景顏色 */
}
.dark .expand-title {
background-color: #333;
/* 暗色模式下的標題背景顏色 */
color: #e0e0e0;
/* 暗色模式下的標題文字顏色 */
}
.dark .expand-title:hover {
background-color: #444;
/* 暗色模式下的標題懸停背景顏色 */
}
.dark .expand-content {
background-color: #2c2c2c;
/* 暗色模式下的內容背景顏色 */
}
.dark .expand-inner {
color: #e0e0e0;
/* 暗色模式下的內容文字顏色 */
}
6. 自動加上編輯時間
在文章末放上編輯日期提醒。
在 layouts/_default/single.html
找到 {{ .Content }}
,在他下面貼上:
<br><br><br>
<div class="max-w-fit">
{{ if ne (.Lastmod.Format "2006-01-02") (.Date.Format "2006-01-02") }}
<div class="lead text-neutral-500 dark:text-neutral-400 !mb-9 text-xl">
{{- $lastmodContent := partial "meta/date-updated.html" .Lastmod -}}
{{ (printf "{{/%% hint info /%%}}文章更新:%s{{/%% /hint /%%}}" $lastmodContent) | markdownify }}
</div>
{{ end }}
</div>
記得要把 %% 前面的 / 刪掉。
7. 修改 metadata
Google 以不再用 keywords 為 SEO 關鍵字所以沒必要改這個。