使用hugo搭建静态博客
安装Go
Go安装地址,下载相应版本的Go安装器,按步骤安装即可。
安装Hugo
去Hugo的Github上下载,hugo_extended版的压缩包,然后解压到指定目录,并将Hugo执行文件所在目录加入到Path环境变量中。 在终端中执行以下命令判断Hugo是否安装成功:
|
|
创建Hugo Site
|
|
安装Hugo-Vitae主题
- 切换至站点的themes目录并将hugo-vitae添加为当前工程的子模块
|
|
- 将hugo-vitae的exampleSite config.toml 复制到根目录稍作改动
创建文章
|
|
运行Hugo Server
|
|
创建GitHub仓库
创建GitHub仓库时需要注意仓库名称必须为:yourgithubusername.github.io
使用GitHub Actions自动部署
- 创建部署用的Token
- 在刚刚创建的仓库的设置中添加 Secrets
- 在仓库下创建文件 .github/workflows/gh-pages.yml
|
|
自动部署至腾讯云
前提条件,在CVM上已安装好Caddy
基本思路是:通过rsync将生成的静态内容复制到VPS上
- 生成无密码的密钥
ssh-keygen -t ed25519 -f ~/.ssh/blog_deploy_key
- 将生成的公钥内容添加到VPS上
~/.ssh/authorized_keys
将生成的私钥内容添加到项目的Secrets中,命名为 blog_deploy_key
工作流文件中使用 webfactory/ssh-agent 实现私钥的缓存
- name: Cache Private Key
uses: webfactory/ssh-agent@v0.4.1
with:
ssh-private-key: |
${{ secrets.BLOG_DEPLOY_KEY }}
- 工作流文件中还使用 ssh-keyscan 命令扫描 VPS 的公钥并保存到虚拟环境的 ~/.ssh/known_hosts 中
- name: Scan public keys
run: |
ssh-keyscan your_vps_ip_or_domain >> ~/.ssh/known_hosts
- 部署到VPS
- name: Deploy
run: |
rsync -av --delete public ./public root@your_vps_ip_or_domain:/data/caddy/site/hugo-web
- Caddyfile配置
blog.zling.site {
root * /srv/hugo-web/public
file_server
}
注意:VPS上也要安装 rsync
Hugo用法
创建文章
hugo new posts\xxx.md
删除文章
hugo delete posts\xxx.md
使用 MathJax 支持数学公式
layouts/partials/mathjax.html文件:
|
|
博文页面头加入以下内容
---
math: true
---
使用默认的 KaTex 显示数学公式
行内数学公式
$ E=mc^2 $
这是内嵌$ E=mc^2 $效果
单独一行
$$E=mc^2$$
$$E=mc^2$$
- 原文作者:ZemelLing
- 原文链接:https://www.zling.site/post/%E4%BD%BF%E7%94%A8hugo%E6%90%AD%E5%BB%BA%E9%9D%99%E6%80%81%E5%8D%9A%E5%AE%A2/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。