参考 #
- Hugo安装
- 主题
- 使用blowfish主题的博客示例
- 前三个有github参考可以用于参考
- 捣鼓静态博客时在github上抄别人的配置,比费劲巴拉的看教程文档来的舒服。
- Ast3risk-ops/website
- 一位印尼前端的博客
- 江ノ島エスカー
- 详解程序中循环次数的判断 · Ohdmire
- GithubActions
- CDN
Hugo和Blowfish使用固定版本如下,方便后面维护
# hugo 0.140.2
# blowfish latest-version: 2.82.0 【forked】
# 考虑后续是升级,在hugo起的myblog中将blowfish中的配置文件准备好
安装Hugo #
到Hugo原仓库下载预编译的hugo extened二进制文件
# linux wget
wget https://github.com/gohugoio/hugo/releases/download/v0.143.1/hugo_extended_0.143.1_linux-amd64.tar.gz
tar -zxvf filename.tar.gz -C ./
# 添加至环境变量
# 将 `hugo` 目录添加到现有的 `PATH` 环境变量中
# 使用echo $path查看环境变量
nano ~/.bashrc
# 添加path
export PATH=$PATH:/vol1/1000/docker/docker_data/hugo
source ~/.bashrc
# 检查
hugo version
Hugo规则 #
标题
和正文
之间必须有空行- 一级标题无法被文章右侧的大纲TOC渲染
- 代码块必须注明语言才能使用
enableCodeCopy
, 以 kill process 为例 - Hugo渲染规则,默认只渲染过去的文章没当前文章不渲染
- hugo文章缺失
- 在
hugo.yaml
根级加入buildFuture: true
- 本篇文章定义发布时间为一千年以后, 如果你可以看到,就说明yaml在工作。
hugo.toml
中的baseURL必须指定为访问的网址,否则无法搜索(本地部署无法搜索的原因)
主题配置 #
Blowfish #
基本沿用website仓库的配置,略作修改。
目录结构 #
# 目录结构
|-- ./.github
| `-- ./.github/workflows
|-- ./archetypes # frontmatter默认
|-- ./assets # 图片文件引用
| `-- ./assets/img
|-- ./config # 配置文件
| `-- ./config/_default
| |-- ./config/_default/hugo.toml
| |-- ./config/_default/languages.zh-cn.toml
| |-- ./config/_default/markup.toml
| |-- ./config/_default/menus.zh-cn.toml
| `-- ./config/_default/params.toml
|-- ./content # 这里放文章
| `-- ./content/blog
| |-- ./content/blog/blog-history
| `-- ./content/blog/use-hugo
|-- ./data
|-- ./i18n
|-- ./layouts # 可以用于修改默认页面,比如comments.html
|-- ./static # 网站默认图片位置
`-- ./themes # 主题here
short code #
图标 #
将从阿里图标上下载的icon.svg进行格式转换,将fill中的值全部替换为 currentColor
。
import re
import argparse
def replace_fill_with_currentcolor(svg_content):
# 使用正则表达式查找并替换所有的 fill="#xxxxxx" 为 fill="currentColor"
updated_svg = re.sub(r'fill="[^"]+"', 'fill="currentColor"', svg_content)
return updated_svg
def main():
# 设置命令行参数
parser = argparse.ArgumentParser(description="Replace all fill color values in an SVG file with 'currentColor'.")
parser.add_argument('-f','--file', help="Path to the input SVG file")
args = parser.parse_args()
# 读取原始 SVG 文件
try:
with open(args.file, 'r', encoding='utf-8') as file:
svg_content = file.read()
except FileNotFoundError:
print(f"Error: The file '{args.input_file}' does not exist.")
return
# 替换 fill 值
updated_svg_content = replace_fill_with_currentcolor(svg_content)
# 将修改后的 SVG 内容保存到新的文件
with open(args.file, 'w', encoding='utf-8') as file:
file.write(updated_svg_content)
print(f"SVG fill color replaced with currentColor successfully! Saved to '{args.file}'.")
# python convert_svg.py -f bilibili.svg
if __name__ == "__main__":
main()
Github Actions #
Github Actions PersonalAccessToken:hidden here
custom domain #
- 现在github.io配置页面定义custom domain为自己的域名
- 第二步DNS验证:在cloudflare上,将自己的三级域名Cname到
github.io
上。 现在访问github.io会自动跳转到custom domain上。
Actions #
1、申请token
settings-Developrt Settings-Personal access tokens-Tokens(classic)
2、在仓库中配置Actions脚本
name: deploy
on:
push:
workflow_dispatch:
schedule:
# Runs everyday at 0:00 AM
- cron: "0 0 * * *"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "latest"
- name: Build Web
run: hugo
- name: Deploy Web
uses: peaceiris/actions-gh-pages@v3
with:
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
EXTERNAL_REPOSITORY: aoidayo/aoidayo.github.io
PUBLISH_BRANCH: master
PUBLISH_DIR: ./public
commit_message: ${{ github.event.head_commit.message }}
cname: blog.aoidayo.site
3、在仓库中配置Token
settings/secrets and variables/actions中添加你申请的token
CDN【TODO】 #
Github pages + cloudflare

要使用国内的cdn,需要备案,暂时搁置。
备份博客 #
在家里的服务器上添加一个用端口访问的备份博客,同时使用Github Actions自动部署。
nginx #
# docker
docker run -d \
--privileged \
--name nginx-server \
-p 1024:80 \
-v /vol1/1000/docker/docker_data/nginx/nginx.conf:/etc/nginx/nginx.conf:ro\
-v /vol1/1000/docker/docker_data/nginx/conf:/etc/nginx/conf.d:ro \
-v /vol1/1000/docker/docker_data/nginx/ssl:/home/dockers/nginx/ssl \
-v /vol1/1000/docker/docker_data/nginx/html:/usr/share/nginx/html:rw \
nginx
# https://www.cnblogs.com/Kingram/p/15009385.html
# 修改容器中的nginx.conf
# user nginx;
user root;
docker cp ./nginx.conf nginx-server:/etc/nginx/nginx.conf
# public/* -> nginx/html/hugo
# nginx/conf/hugo.conf
server{
#只代理80端口
listen 80;
# 监听指定域名
server_name you.aoidayo.site;
location / {
root /usr/share/nginx/html/hugo;
index index.html index.htm;
}
}
Hugo常用命令 #
hugo new site myblog
hugo new content blog/my-first-blog/my-first-blog.md
# 在content/下面新建blog/xx/index.md
hugo new post xx/index.md
# 在content/post下面新建xx/index.md
# hugo new 有扩展用法【TODO】
hugo
# 生成public和resources
# 部署在1313端口访问
hugo server --theme blowfish --bind 0.0.0.0 --port 1313
hugo server --theme blowfish --bind 0.0.0.0 --port 1313 --buildDrafts
Linux常用命令 #
解压 #
# tar
tar -zxvf filename.tar.gz -C ./
- `-t`: 查看 `.tar.gz` 文件中的内容。
- `-x`: 解压文件。
- `-z`: 使用 `gzip` 解压。
- `-v`: 显示解压进度。
- `-f`: 文件名。
- `-C`: 指定解压路径。
# zip
unzip xxx.zip -d ./
kill process #
# windows
netstat -ano | findstr :8080
taskkill /PID 1234 /F
netstat -ano | findstr :8080
# Linux
ps aux | grep hugo
kill -9 PID
树形目录 #
# windows
tree /f
func : 打印当前目录下的所有目录和文件
# [](https://www.cnblogs.com/ricolee/p/cmd-tree.html)
# 没找到其它参数可以只打印一级或者二级目录类似的参数;
# 安装tree https://blog.csdn.net/qq_33154343/article/details/100064726
tree -dL
# linux
tree -dL /path/to/dir
-d /path/to/dir
-L 显示指定层级
Appendix #
从0构建Hugo主题仓库 #
######################## /1. hugo new site myblog/ #########################
# hugo new site myblog
# 创建新网站
root@familyNas:/vol1/1000/docker/docker_data/hugo# hugo new site myblog
Congratulations! Your new Hugo site was created in /vol1/1000/docker/docker_data/hugo/myblog.
Just a few more steps...
1. Change the current directory to /vol1/1000/docker/docker_data/hugo/myblog.
2. Create or install a theme:
- Create a new theme with the command "hugo new theme <THEMENAME>"
- Or, install a theme from https://themes.gohugo.io/
3. Edit hugo.toml, setting the "theme" property to the theme name.
4. Create new content with the command "hugo new content <SECTIONNAME>/<FILENAME>.<FORMAT>".
5. Start the embedded web server with the command "hugo server --buildDrafts".
See documentation at https://gohugo.io/.
######################## /2. 修改配置文件/ #########################
# config/_default/下面的所有toml
######################## /2. 安装主题/ #########################
## cd myblog
## git init
## git submodule add -b main https://github.com/nunocoracao/blowfish.git themes/blowfish
## 这里可以替换成自己fork的仓库
######################## /3. hugo server/ #########################
## hugo server
## hugo server --theme blowfish --bind 0.0.0.0 --port 1313
## hugo server --theme blowfish --bind 0.0.0.0 --port 1313 --buildDrafts
### -D means --buildDrafts
### windows hugo server一直是用不了1313的原因https://blog.weiqh.net/2022/11/16/Windows-10-%E8%A7%A3%E5%86%B3%E7%AB%AF%E5%8F%A3%E8%A2%AB%E5%8D%A0%E7%94%A8%E9%97%AE%E9%A2%98/
######################## /4. hugo new/ #########################
# hugo new content blog/my-first-blog.md
gitignore 4 hugo #
# Hugo
resources/
public/
# Hugo themes
# themes/blowfish/
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# others
node_modules
.hugo_build.lock
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
.idea
.jampack