安装
以这个页面 https://gohugo.com.cn/getting-started/quick-start/ 进行初步安装,但要注意,以下主题代码不要使用:
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
应该使用如下克隆主题的代码:
克隆主题,并删除主题中的.git文件夹,使得主题与整个网站架构同一个仓库管理
git clone https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
rm -rf themes/ananke/.git
# 如果在windows下,用以下代码:
Remove-Item -Recurse -Force .\themes\ananke\.git
数学公式问题
在根目录的文件夹layouts下创建partials,在这个文件夹下创建math.html,内容如下:
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" id="MathJax-script" async></script>
<script>
MathJax = {
tex: {
inlineMath: [['\\(', '\\)'], ['$', '$']],
displayMath: [['\\[', '\\]'], ['$$', '$$']]
}
};
</script>
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.25/dist/katex.min.css" integrity="sha384-WcoG4HRXMzYzfCgiyfrySxx90XSl2rxY5mnVY5TwtWE6KLrArNKn0T/mOgNL0Mmi" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.25/dist/katex.min.js" integrity="sha384-J+9dG2KMoiR9hqcFao0IBLwxt6zpcyN68IgwzsCSkbreXUjmNVRhPFTssqdSGjwQ" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.25/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.body, {
delimiters: [
{left: '\\[', right: '\\]', display: true},
{left: '$$', right: '$$', display: true},
{left: '\\(', right: '\\)', display: false},
],
throwOnError : false
});
});
</script> -->
上面分别展示了mathjax和katex,注意:mathjax用v3版本可以直接用美元符号来进行行内公式设置
配置hugo.toml, 使其可以显示数学公式
baseURL = 'https://example.org/'
locale = 'en-us'
title = 'My New Hugo Project'
theme = 'ananke'
[markup]
[markup.goldmark]
[markup.goldmark.extensions]
[markup.goldmark.extensions.passthrough]
enable = true
[markup.goldmark.extensions.passthrough.delimiters]
block = [['\[', '\]'], ['$$', '$$']]
inline = [['\(', '\)'], ['$', '$']]
[params]
math = true
如果在文章页面不想显示数学公式,可以令 math=false即可。
在主题的baseof.html中添加代码:
<head>
...
{{ if .Param "math" }}
{{ partialCached "math.html" . }}
{{ end }}
...
</head>
数学公式测试页面
+++
date = '2026-05-28T11:13:12+08:00'
draft = false
title = 'My First Post'
+++
## 简介
这是 **粗体** 文本,这是 *斜体* 文本。
访问 [Hugo](https://gohugo.io) 网站!
This is an inline \(a^*=x-b^*\) equation.
测试:
This is another inline $a^*=x-b^*$ equation.
These are block equations:
\[a^*=x-b^*\]
\[ a^*=x-b^* \]
\[
a^*=x-b^*
\]
These are also block equations:
$$a^*=x-b^*$$
$$ a^*=x-b^* $$
$$
a^*=x-b^*
$$
注意,如果要往cloudflare部署,需要将draft设置为false
部署cloudflare
以下这个页面是能正常使用的:
https://developers.cloudflare.com/pages/framework-guides/deploy-a-hugo-site/
不过要在里面创建对应hugo版本的字符串,我使用的Variables and Secrets是:
HUGO_VERSION
0.161.0
余下的就是在github创建仓库,并用cloudflare与github连接。
关于推送时的问题
如果用了代理,则需要用下面代码确保推送github成功:
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890