1. 安装 Hugo, 参阅官方文档
2. 选择合适的主题
-
Hugo网站的Doks主题: Huog-Doks-Theme
-
Doks官网: Doks
-
# Doks child theme git clone https://github.com/h-enk/doks-child-theme.git my-doks-site && cd my-doks-site
-
# Doks starter theme git clone https://github.com/h-enk/doks.git my-doks-site && cd my-doks-site
-
# Install dependencies npm install
-
# Start development server # 下载安装主题之后, 无需任何修改, 即可预览主题效果 npm run start
-
添加
blog
文章# 两种方式均可 1. npm run create blog/{文件夹名称}/{文件名}.md 2. hugo new "blog/{文件夹名称}/{文件名}.md"
-
编写博客文件, 完成之后, 注意事项
# 取消草稿形式 # draft: true draft: false
-
预览效果
npm run start
-
发布到Github
-
Add
.github/workflows/deploy-github.yml
# Deploy your Hyas site to GitHub Pages name: GitHub Pages on: push: branches: - master jobs: deploy: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: '15' # node版本, 更改为你服务器环境的版本 - name: Install dependencies run: npm ci - name: Check for linting errors run: npm test - name: Build production website run: npm run build # 修复: 就算在项目根目录创建了CNAME文件, 正确的配置了, 打包时依旧无法打包到 - name: Copy CNAME file to public run: cp ./CNAME ./public - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} # 如果为私人项目则需要添加授权访问token publish_dir: ./public
-
GitHub 上建立一个
{username}.github.io
的项目, 注意:username
为自己 Github 的用户名 -
推送到 Github
cd {项目文件夹根目录} npm run init git add . git commit -m "First Commit" git remote add origin <remote repository URL> git remote -v git push origin main
-
-
打开
https://{username}.github.io
尽情欣赏吧
-
修改博客默认生成的模板,
archetypes/blog.md
# 修改之后 --- title: "{{ replace .Name "-" " " | title }}" description: "" lead: "" date: {{ .Date }} lastmod: {{ .Date }} draft: false weight: 50 contributors: [作者名字] url: url: "/blog/{{ .Date | md5 }}" # 根据当前时间, 生成md5的自定义url路径 ---
-
# rimraf not found npm install rimraf --save-dev
-
# POSTCSS: failed to transform "main.css" npm install -g postcss-cli npm install autoprefixer npm audit fix
-
namecheap 购买域名, 并进入
Domain List
管理界面 -
# A Record的ip, dig 可进行查看 Type Host Value TTL A Record @ xxx.xxx.xxx.xxx 30min A Record @ xxx.xxx.xxx.xxx Automatic CNAME Record www clannadzsy.github.io Automatic CNAME Record www clannad.icu Automatic URL Redirect Record @ http://clannad.icu Automatic
-
Github 项目根目录添加文件,
CNAME
clannad.icu
-
Github:
Settings
->Pages
->Custom domain
clannad.icu
-
config/production/config.toml
修改如下baseurl = "https://clannad.icu/" canonifyURLs = true