惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Palo Alto Networks Blog
P
Proofpoint News Feed
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
罗磊的独立博客
J
Java Code Geeks
月光博客
月光博客
F
Full Disclosure
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
U
Unit 42
WordPress大学
WordPress大学
A
About on SuperTechFans
C
Cyber Attacks, Cyber Crime and Cyber Security
SecWiki News
SecWiki News
Security Latest
Security Latest
C
Check Point Blog
C
CERT Recently Published Vulnerability Notes
小众软件
小众软件
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog RSS Feed
V
Visual Studio Blog
博客园_首页
NISL@THU
NISL@THU
I
Intezer
Spread Privacy
Spread Privacy
AWS News Blog
AWS News Blog
The Register - Security
The Register - Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Latest news
Latest news
Project Zero
Project Zero
博客园 - 叶小钗
C
Cybersecurity and Infrastructure Security Agency CISA
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
博客园 - 【当耐特】
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
T
Tor Project blog
V
Vulnerabilities – Threatpost
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网

Dvel's Blog

Rime 全拼双拼混输 CHD 油猴脚本:每日签到自动答题 Rime 配置:雾凇拼音 Hammerspoon 自动切换输入法 修复 Hugo 本地图片的累计布局偏移(CLS)问题 macOS 利用 Karabiner 修改 Emacs 键位为 Vim 键位 macOS 修改 Emacs 键位为 Vim 键位 Surge 配置 汉字的混乱 Netflix 中英双语字幕的好办法 优化 Rime 英文输入体验 判断字符是否为简体字或繁体字 Cloudflare 转入域名提示「出现了问题。请重试转移此域。尚未向您收费。」 图片压缩:Squoosh、TinyPNG、ImageOptim、WebP macOS grep + sed 批量替换多个文件的内容 在 macOS 根目录创建文件夹 博客图床小妙招 利用 Cloudflare Workers 进行批量 301 重定向 将博客部署在 Cloudflare Pages Alfred File Navigation(文件导航器)详解 在 Hugo Goldmark Markdown 中设置以新标签打开链接 日期与时间(UTC、GMT、时间戳、时区) 让 Alfred 以新标签的方式打开 Finder 用 git filter-branch 给 Git 仓库瘦身 qBittorrent 设置教程 联通光猫破解+桥接记录 配置 Mac 终端走代理 Steam for Mac 中文游戏推荐 我的 Mac 软件/工具列表 《Flask Web 开发》笔记 用 sleepwatcher 让 Mac 在睡眠及唤醒时自动执行一些脚本 解决 pyenv 导致的 brew warning 《SQL 必知必会》笔记 Git 自总结 Python 异步 IO 笔记 再见,双点医院! 用 CloudXNS 解决 CNAME 与 MX 记录冲突 你好,Hugo! 为 Mac 打造 zsh command line 环境 新 Mac 新装修 秦皇岛暑期自驾的烦恼 苹果公司开发者账号申请流程 UIScrollView 中使用 Masonry 解决 CocoaPods 的类库 import 没有提示 iOS 使用 CocoaPods 的快速回顾 GitBook 简单生成本地静态 HTML 的方法 你好, Hexo! About
折腾 Hugo & PaperMod 主题
Dvel · 2022-01-11 · via Dvel's Blog

无意浏览了一下 Hugo 官网的主题目录,发现了一个简约风格的 Paper 主题,非常喜欢,第二天发现了一个 PaperMod,差不多算是增强版。

之前就没遇到过心爱的主题,一直将就着,好多功能也没有弄,这两天一顿折腾,记录一下折腾经过。

使用的版本是 hugo-PaperMod-7.0

开始

更新 Hugo,新建站点,导入 PaperMod 主题。

示例配置在另一个分支里,导入 PaperMod 演示站的 config.yml

配置时可以参考着 Hugo 官方文档的 Configure Hugo

另外要看看 PaperMod Wiki,PaperMod 的示例文件里好多参数都没写,比如这些参数很好用:

params:
	# ...
    DateFormat: "2006-01-02"  # 日期格式化
    ShowFullTextinRSS: true   # RSS 输出全文

HTML lang

单语言的站点可以直接设置 languageCode 并在 baseof.html 修改为:

- <html lang="{{ .Site.Language }}" dir="{{ .Language.LanguageDirection | default "auto" }}">
+ <html lang="{{ .Site.LanguageCode }}">

参考一:Hugo博客目录放在侧边 | PaperMod主题 | Sulv’s Blog

参考二:JannikArndt/jannikarndt.github.io@8b99f6c

设置文章中链接以新标签的方式打开

参考:在 Hugo Goldmark Markdown 中设置以新标签打开链接

修复本地图片的累计布局偏移(CLS)问题

参考:修复 Hugo 本地图片的累计布局偏移(CLS)问题

最后更新时间

看到一篇 Use Lastmod with PaperMod,这个可以和 Git 搭配,不过我希望可以手动输入。

在 PaperMod 的 post_meta.html 中加上三行:

{{- if gt .Lastmod .Date -}}
{{- $scratch.Add "meta" (slice (printf "<span title='%s'>(updated: %s)</span>" (.Lastmod) (.Lastmod | time.Format (default "January 2, 2006" .Site.Params.DateFormat)))) }}
{{- end }}

在 Hugo 的 Front Matter 下手动加上 lastmod 属性即可:

title: 折腾 Hugo & PaperMod 主题
slug: hugo-papermod-config
author: Dvel
date: 2022-01-11T15:15:38+08:00
lastmod: 2023-02-14T00:40:08+08:00

评论功能

试用了一下 Disqus,但是界面好杂乱,就换到了 Waline。

官方教程非常详尽,就是配置麻烦点,不能像 Disqus 那样一键搞定。

部署在了 Vercel,按照 Errors Accessing From China 将 CANME 记录修改成官方推荐的地址 cname-china.vercel-dns.com。(现在那个页面访问不了了,不知道是否还推荐这个。)

适配 Waline 的黑暗模式,在 PaperMod 中以 body.dark 作为选择器:

/* # Waline 黑暗模式 */
body.dark {
    /* 下面是官网默认的黑暗模式配色 */
    /* 常规颜色 */
    --waline-white: #000;
    --waline-light-grey: #666;
    --waline-dark-grey: #999;

    /* 布局颜色 */
    --waline-color: #888;
    --waline-bgcolor: #1e1e1e;
    --waline-bgcolor-light: #272727;
    --waline-border-color: #333;
    --waline-disable-bgcolor: #444;
    --waline-disable-color: #272727;

    /* 特殊颜色 */
    --waline-bq-color: #272727;

    /* 其他颜色 */
    --waline-info-bgcolor: #272727;
    --waline-info-color: #666;
}

浏览量统计

不蒜子的:

总访客:<span id="busuanzi_value_site_uv"></span>
总浏览量:<span id="busuanzi_value_site_pv"></span>
页面访问量:<span id="busuanzi_value_page_pv"></span>

Waline 的:

老版的:
<span class="waline-visitor-count" id="{{ .RelPermalink }}">
新版的:
<span class="waline-pageview-count" data-path="{{ .RelPermalink }}" />

代码高亮

Hugo 自带的配色方案是 Chroma,但 PaperMod 用的 highlight.js,用 Chroma 时样式有点问题。

设置 disableHLJS: false 选择 highlight.js 作为高亮方案。

自定义的话,由于 PaperMod 是读取写死了的文件名:

  • assets/js/highlight.min.js
  • assets/css/hljs/an-old-hope.min.css

我是直接从 highlight.js 下载最新版的 JS 和 CSS 文件,不修改文件名,直接替换掉里面的内容。

PaperMod 的代码块背景颜色是写死了的,可以在 blank.css 中设定代码块在博客为亮/暗色主题时不同的背景色。

:root {
    --hljs-bg: #282C34;
}
.dark {
    --hljs-bg: #272b33;
}

SRI

今天发现了 SRI(完整性检查)的问题,浏览器提示「Failed to find a valid digest in the ‘integrity’ attribute for resource …」,导致语法高亮失效了。

搜索后发现是因为 Hugo 的「minify」与 Cloudflare 的「Auto Minify」发生了冲突,Cloudflare 在再次压缩后导致文件哈希值改变,校验失败。

解决办法是要么关闭 SRI,要么取消 Cloudflare 的「Auto Minify」。

Cloudflare 关闭的方法:速度 - 优化 - Auto Minify。

在 Hugo 中关闭的方法:

params:
  assets:
    disableFingerprinting: true

Markdown 渲染风格

自定义了一些渲染风格,参考了一点 Simple.css 和 GitHub。

由于习惯了在 Typora 的 H2 标题前打一个空行,标准 Markdown 都不会渲染空行,所以直接增加上边距了。

PaperMod 的表格有点空洞,用了 GitHub 那种样式的表格:

样式 体验
PaperMod 有点空洞
GitHub 感觉刚刚好

和一些杂七杂八的调整。

blank.css 中新增自定义样式:

/* # Markdown 风格 */
/* 标题、正文、行内代码 - 颜色 */
:root {
    --primary: #212121;  /* rgb(30, 30, 30); */
    --content: #333333;  /* rgb(31, 31, 31); */
    --code-bg: rgba(175, 184, 193, 0.2); /* rgb(245, 245, 245); */
}
.dark {
    --code-bg: rgba(175, 184, 193, 0.2); /* rgb(55, 56, 62); */
}
/* 链接样式 */
.post-content a {
    color: #0969da;
    box-shadow: none;
    text-decoration: none;
}
.post-content a:hover {
    text-decoration: underline;
}
/* 行内代码 - 左右间距 */
.post-content code {
    margin: unset;
}
/* 代码块 - 最大高度 */
/* .post-content pre code {
    max-height: 40rem;
} */
/* 图片居中 */
.post-content img {
    margin: auto;
}
/* 行文风格 */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Avenir Next", Avenir, "Nimbus Sans L", Roboto, Noto, "Segoe UI", Arial, Helvetica, "Helvetica Neue", sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    margin: 0;
}
.post-content {
    padding-top: 1rem;
}
.post-content blockquote {
    color: #808080;
}
.post-content p,
.post-content blockquote,
.post-content figure,
.post-content table {
    margin: 1.15rem 0;
}
.post-content hr {
    margin: 4rem 8rem;
}
.post-content ul,
.post-content ol,
.post-content dl,
.post-content li {
    margin: 0.5rem 0;
}
.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4,
.post-content h5,
.post-content h6 {
    margin-bottom: 1.15rem;
    font-weight: 600;
}
.post-content h1 {
    font-size: 2.6rem;
    margin-top: 4rem;
    border-bottom: 1px solid #ccc;
}
.post-content h2 {
    font-size: 1.8rem;
    margin-top: 4rem;
    border-bottom: 1px solid #ccc;
}
.post-content h3 {
    font-size: 1.6rem;
    margin-top: 2rem;
}
.post-content h4 {
    font-size: 1.4rem;
    margin-top: 1.44rem;
}
.post-content h5 {
    font-size: 1.2rem;
    margin-top: 1.15rem;
}
.post-content h6 {
    font-size: 1rem;
    margin-top: 1rem;
}
/* GitHub 样式的表格 */
.post-content table tr {
    border: 1px solid #979da3 !important;
}
.post-content table tr:nth-child(2n),
.post-content thead {
    background-color: var(--code-bg);
}
.post-content table th {
    border: 1px solid #979da3 !important;
}
.post-content table td {
    border: 1px solid #979da3 !important;
}