Hexo 迁移到 Hugo

目录
花了几天时间将博客从 hexo 迁移到 Hugo,记录一下感受及过程。
博客有很长时间没有更新了,趁着时间充裕再次写起来。
之前就考虑更换 hexo,虽然主题和插件很丰富,但是安装起来还是不便,又需要 Node.js 环境,又需要安装一堆插件。
比较后决定使用 hugo,安装方便直接二进制文件即可使用,渲染速度更快,就是主题没有 hexo 丰富。
安装
可查看Hugo安装官方文档。
我是使用 Ubuntu 系统,建议直接使用二进制安装,还需要注意自已使用的主题支持版本是哪些。
注意
snap 安装时在使用 hugo mod 命令需要注意权限问题,否则会报错。
安装后检查版本,注意是否包含 extended:
$ hugo version
$ hugo v0.145.0-666444f0a52132f9fec9f71cf25b441cc6a4f355+extended linux/amd64 BuildDate=2025-02-26T15:41:25Z VendorInfo=gohugoio
迁移
迁移一开始并不是很顺利,首先主题很多在首次测试时就渲染失败,感觉主题使用 submodule 引入比 hugo mod 引入更好控制。
然后文章属性需要根据选择的主题修改适配,该部分可以借助一下 AI 工具。
shortcode
hugo 建议使用 shortcode 渲染内容,保持 markdown 的简洁。
如果加入其他自定义 html 格式,可以添加自己的 shortcode。
如我之前文章《Markdown 增强》中会使用到 html 原生语言。
在 hexo 中,我使用 {% raw %}
标签注释,在 hugo 中则可添加模板 layouts/shortcodes/html.html
:
{{ .Inner }}
然后文章需要原生 html 的地方,使用 {% html %}
标签:
{{< html >}}
...
{{< /html >}}
使用
vscode 中可以添加一些任务脚本辅助:
{
"version": "2.0.0",
"tasks": [
{
"label": "serve",
"type": "shell",
"command": "hugo serve --disableFastRender"
},
{
"label": "production",
"type": "shell",
"command": "hugo serve -e production"
},
{
"label": "debug",
"type": "shell",
"command": "hugo server -D --disableFastRender"
},
{
"label": "new",
"type": "shell",
"command": "hugo new posts/draft/index.zh-cn.md"
}
]
}