How to Run

警告
本文最后更新于 2023-03-04,文中内容可能已过时。

https://www.runoob.com/go/go-environment.html

https://github.com/gohugoio/hugo

1
CGO_ENABLED=1 go install --tags extended github.com/gohugoio/hugo@latest

新建私有仓库 https://github.com/xxx/xxx

1
2
3
git clone https://github.com/xxxx/xxx
cd xxxx
hugo new site . --force
1
2
git submodule add https://github.com/HEIGE-PCloud/DoIt.git themes/DoIt
echo 'theme = "DoIt"' >> config.toml

https://hugodoit.pages.dev/zh-cn/theme-documentation-basics/

https://giscus.app/zh-CN

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
[params.page.comment.giscus]
  enable = true
  # owner/repo
  dataRepo = "xxxx/xxxx.github.io"
  dataRepoId = "xxxx"
  dataCategory = "Announcements"
  dataCategoryId = "xxxxx"
  dataMapping = "pathname"
  dataReactionsEnabled = "1"
  dataEmitMetadata = "0"
  dataInputPosition = "top"
  lightTheme = "light"
  darkTheme = "dark"
  dataLang = "en"
1
2
hugo new posts/how-to-run.md
vim content/posts/how-to-run.md

默认情况下, 所有文章和页面均作为草稿创建. 如果想要渲染这些页面, 请从元数据中删除属性 draft: true, 设置属性 draft: false 或者为 hugo 命令添加 -D/–buildDrafts 参数.

由于本主题使用了 Hugo 中的 .Scratch 来实现一些特性, 非常建议你为 hugo server 命令添加 –disableFastRender 参数来实时预览你正在编辑的文章页面.

hugo serve 的默认运行环境是 development, 而 hugo 的默认运行环境是 production. 由于本地 development 环境的限制, 评论系统, CDN 和 fingerprint 不会在 development 环境下启用. 你可以使用 hugo serve -e production 命令来开启这些特性.

1
hugo server -D --disableFastRender -e production

https://zhuanlan.zhihu.com/p/568764664

在私有仓库中配置 PERSONAL_TOKEN

https://github.com/xxxx/xxx.github.io

vim .github/workflows/gh-pages.yml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
name: GitHub Pages

on:
  push:
    branches:
      - main  # Set a branch to deploy
  pull_request:

jobs:
  deploy:
    runs-on: ubuntu-latest
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: true  # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0    # Fetch all history for .GitInfo and .Lastmod

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: '0.111.1'
          extended: true

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        if: ${{ github.ref == 'refs/heads/main' }}
        with:
          external_repository: xxx/xxx.github.io
          publish_dir: ./public
          publish_branch: gh-page
          personal_token: ${{ secrets.PERSONAL_TOKEN }}
          commit_message: ${{ github.event.head_commit.message }}
1
2
3
git add .
git commit -m "add workflow"
git push