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

推荐订阅源

CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
S
Securelist
GbyAI
GbyAI
The Register - Security
The Register - Security
B
Blog
Recorded Future
Recorded Future
D
DataBreaches.Net
C
Cybersecurity and Infrastructure Security Agency CISA
A
About on SuperTechFans
C
CERT Recently Published Vulnerability Notes
T
The Blog of Author Tim Ferriss
Vercel News
Vercel News
Google DeepMind News
Google DeepMind News
S
Schneier on Security
S
SegmentFault 最新的问题
Martin Fowler
Martin Fowler
T
Tenable Blog
T
The Exploit Database - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
AWS News Blog
AWS News Blog
L
Lohrmann on Cybersecurity
Spread Privacy
Spread Privacy
N
News | PayPal Newsroom
Engineering at Meta
Engineering at Meta
T
Tor Project blog
The Hacker News
The Hacker News
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog
Cyberwarzone
Cyberwarzone
Security Archives - TechRepublic
Security Archives - TechRepublic
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Threatpost
WordPress大学
WordPress大学
Google Online Security Blog
Google Online Security Blog
G
GRAHAM CLULEY
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
N
Netflix TechBlog - Medium
SecWiki News
SecWiki News
Hacker News: Ask HN
Hacker News: Ask HN
M
MIT News - Artificial intelligence
Scott Helme
Scott Helme
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org

Posts on 月夜Moonlight

浮生四日—拉斯维加斯行记 三年之期将满,给网站搬了家 沉默之声 2026年第三周 AI时代,你还在写作吗? The Journey Is The Destination 从落花生想到 心牧场—记2024年盛夏读李娟 「劝君更尽一杯酒」之纳帕行 六月的流水帐 血色象牙塔——读齐邦媛《巨流河》之一 MBTI与荣格认知模型的排列组合 就这样那样慢慢长大 Enhancing Workflow Efficiency: Practical Git Strategies in Action 大明王朝的余晖,一如它疲惫而沉重的眼光——读《万历十五年》 N.T. was the hint for 2023 流年似水,我心悠悠 —— 读黎紫书《流俗地》 那些让我喜欢湾区(加州)的小事 当时只道是寻常 故人叹 希望有朝一日,能笑着谈论今天 新年的G大调 当你消散如空气—病中乱读书 2021-2023 阅读总结 所谓「因缘」 我为什么写博客 那些岁月带给我的 在齐太史简,在晋董狐笔—悲怀高华 2020年阅读总结 2019 阅读总结 昨天的风霜雨雪云—读王鼎钧回忆录 风雨渡—记2018年读杨牧 乔森·道格拉斯冷杉 或者所谓春天 :: 月夜Moonlight
Hugo 操作纪要
2024-03-10 · via Posts on 月夜Moonlight

本文是基于我个人在使用Hugo建站过程中所遇到的问题总结而成。在Debug过程中主要依赖于Google + Github + YouTube + ChatGPT,在此也要感谢诸多前辈和技术大牛们在网上的无私分享。

主题设置

在Hugo 的主题展示区可以找到完整的主题列表。在选择主题时,除了选择自己喜欢的风格,建议也尽量选择开发者仍在积极维护的主题。如果主题的更新时间过于out-of-dated, 可能无法适配于Hugo的最新版本。此处也要提醒如果网站已经相对完善并上线,那么在本地的Hugo更新则需要非常谨慎。如果升级了Hugo却发现无法渲染主题则会非常麻烦。Mac 用户尤其需要注意,downgrading Hugo is tricky。也建议每次要升级前要记录下当前与自己主题相配合的Hugo 版本, 以备不时之需。

查看Hugo 版本的方法:

如果必须downgrade:

  • https://github.com/gohugoio/hugo/releases 下载特定的版本

  • 本地解压并把Hugo移至安装文件夹

    tar -xvf hugo_0.123.7_darwin-universal.tar.gz
    # Move the extracted hugo binary to a directory in your PATH 
    # Run `which hugo` to check the hugo PATH eg. /usr/local/bin
    sudo mv hugo /usr/local/bin/hugo
    # Verify it is executable:
    chmod +x /usr/local/bin/hugo
    

另外,在下载主题时,一般建议使用 git submodule add 这样可以实现主题的及时更新。但需要注意,如果有使用不同设备操作,那么在新设备 git clone 自己的 repo 之后,也需要 git submodule init, 不然是无法在新设备渲染网站的。具体步骤如下:

$ git clone https://github.com/user/repo.git
$ git submodule init
$ git submodule update --remote --merge

文章设置

使用命令hugo new content posts/my-first-post.md 可以在路径 content/posts 下产生一个markdown 文件。这里建议加入几个参数:

  • slug: 设置slug的目的是优化固定连接,也就是防止文章的链接复制到剪贴板之后所有中文部分变成某种“乱码”。在设置了slug 之后,记得再去Config 中修改permlinks的格式。更多关于slug的说明,可以参考此教程
  • categoriestags 都是帮助我们更好的组织管理网站上的文章。大部分的主题在自己的Config file里都已经把 Category 和 Tag 放在了Menu下面,所以只要我们在文章的参数里写了相应的值,文章就会自动出现在这些不同的类别和标签下面了。(当然Tag 和 Category也可以只选择一个。)
---
title: "my-first-post"
slug: "first-post"
date: 2024-03-02T19:20:54-08:00
draft: true
tags:
  - Hugo
  - Blog
categories:
	- 
---

Config.toml下面 Permlink、Category 和 Tag的设置可以参考:

[permalinks]
  posts = "/posts/:year/:month/:slug/"

[[menu.main]]
  name = "分类"
  weight = 3
  identifier = "categories"
  url = "categories/" 
  
 [[menu.main]]
  name = "标签"
  weight = 4
  identifier = "tags"
  url = "tags/"

字体设置

本网站使用的字体为霞鹜文楷。在Hugo 网站使用霞鹜文楷有两个步骤:

  • Step 1: 在 layouts/partials/head.html 加入在线字体链接:

    <link rel="stylesheet" href="https://npm.elemecdn.com/lxgw-wenkai-screen-webfont/style.css" media="print" onload="this.media='all'">
    
  • Step 2: 在 .css file 所有的 font-family 处添加霞鹜文楷:

    body {
      /* Screen version */
      font-family: "LXGW WenKai Screen", sans-serif;
    }
    

添加评论

尽管 Hugo 提供了方便的 Disqus shorcode , 但 Disqus 的界面浮夸且必须接受广告协议,所以不是个好选择。目前发现的最好选择是Twikoo + Vercel,请参见官方详细的使用说明视频教程

在配置好自己的environment ID之后,如果使用的主题没有支持 Twikoo 则需要通过CDN 引入。方法是在 layouts/posts/single.html (也可能是layouts/partials/footer.html, 依据不同主题会有所不同)加入官方指导的代码 (此处只需替其中的environment ID):

<div id="tcomment"></div>
<script src="https://cdn.staticfile.org/twikoo/1.6.31/twikoo.all.min.js"></script>
<script>
twikoo.init({
  envId: '您的环境id', // 腾讯云环境填 envId;Vercel 环境填地址(https://xxx.vercel.app)
  el: '#tcomment', // 容器元素
  // region: 'ap-guangzhou', // 环境地域,默认为 ap-shanghai,腾讯云环境填 ap-shanghai 或 ap-guangzhou;Vercel 环境不填
  // path: location.pathname, // 用于区分不同文章的自定义 js 路径,如果您的文章路径不是 location.pathname,需传此参数
  // lang: 'zh-CN', // 用于手动设定评论区语言,支持的语言列表 https://github.com/twikoojs/twikoo/blob/main/src/client/utils/i18n/index.js
})
</script>

在前端也配置成功Twikoo之后, 可参考教程进行Twikoo的界面和邮件提醒设置。

使用图床

使用图床主要有两个好处:

  • 方便文章的移动和分享
  • 不占用本地空间

Github 作为搭建图床的选择优点在于简单快速完全免费,但缺点是有时Github会被国内block, 且作为储存地点的Repo必须设置为"public"。具体步骤可以参考 GitHub + PicGo 教程。需要注意的是在配置PicGo时 “设定仓库名称” 需要的格式必须是: username/reponame,不能只写 reponame

另外也可以考虑 Backblaze + Cloudflare + PicGo, 可参见教程

其他有用资源