Skip to content

Commit

Permalink
feat: workflow & blog
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzhizhia committed Jan 6, 2025
1 parent cb5d4bd commit 41decf4
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 17 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/deploy-public.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy public

on:
push:
branches: ["main"]
workflow_dispatch:
inputs:
hugoVersion:
description: 'Hugo version to use'
required: false
default: '0.128.0'
type: string

permissions:
contents: write

jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
HUGO_VERSION: ${{ inputs.hugoVersion || '0.128.0' }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Hugo
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${{ env.HUGO_VERSION }}/hugo_extended_${{ env.HUGO_VERSION }}_linux-amd64.deb
sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Build
run: hugo --minify --gc

- name: Deploy to public branch
uses: s0/git-publish-subdir-action@develop
env:
REPO: self
BRANCH: public
FOLDER: public
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MESSAGE: "Build: ({sha}) {msg}"
SQUASH_HISTORY: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Folders
_obj
_test
public

# Architecture specific extensions/prefixes
*.[568vq]
Expand All @@ -21,6 +22,7 @@ _testmain.go

*.exe
*.test
*.cmd

.vscode
.DS_Store
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

24 changes: 23 additions & 1 deletion content/en/posts/hugo-blog-setup-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defaultContentLanguageInSubdir: true
- Affects the URL structure generated by Hugo
- Determines the language identifier for default content

It is recommended not to modify this configuration.
The above configuration should not be modified unless you specifically need to change the default language.

`defaultContentLanguageInSubdir: true`

Expand Down Expand Up @@ -239,6 +239,28 @@ git push
cd ..
```

Due to maintenance difficulties, I switched to using separate source and deployment branches within the same repository. Therefore:

```shell
# Create public branch in main repository
git checkout --orphan public
git reset --hard
git commit --allow-empty -m "Init public branch"
git push origin public
git checkout main
# Link public directory to public branch
git worktree add -B public public origin/public
# Generate site and push
hugo -D
cd public
git add -A
git commit -m "Push %date%"
git push origin public
cd ..
```

With Cloudflare Pages CI/CD, a single script can push updates with one command.

Do not configure `baseURL` in `hugo.yaml`; otherwise, all unique preview URLs will be redirected to `baseURL`.
Expand Down
2 changes: 1 addition & 1 deletion content/zh-cn/archive.md → content/zh/archive.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "归档"
layout: "archives"
url: "/zh-cn/archives"
url: "/zh/archives"
summary: "archives"
---
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ params:
### 多语言
这里配置很容易出问题。如果你像我一样喜欢搞多语言博客,请关注以下配置:
这里的配置很容易出问题。如果你像我一样喜欢搞多语言博客,请关注以下配置:
```yaml
defaultContentLanguage: zh-cn
Expand All @@ -37,7 +37,7 @@ defaultContentLanguageInSubdir: true
- 影响 Hugo 生成的 URL 结构
- 决定默认内容的语言标识

以上配置建议不要修改
以上配置不要修改,除非的确要修改默认语言

`defaultContentLanguageInSubdir: true`

Expand Down Expand Up @@ -221,7 +221,7 @@ params:

敲打 `hugo -D` 命令后,Hugo 会在 `/public` 目录下构建静态博客。每次构建前一般会将 `/public` 删掉来确保新构建的内容不出问题。

在这种情况下,我希望只部署静态博客而不是整个 Hugo 框架。于是写了一个 Shell 脚本:
在这种情况下,我希望只部署静态博客到仓库中,而不是整个 Hugo 框架。于是写了一个 Shell 脚本:

```shell
@echo off
Expand All @@ -239,6 +239,28 @@ git push
cd ..
```

因为不方便维护,我又改用同一仓库中单独创建源码分支和部署分支的方法。于是乎:

```shell
# 在主仓库创建 public 分支
git checkout --orphan public
git reset --hard
git commit --allow-empty -m "Init public branch"
git push origin public
git checkout main
# 将 public 目录关联到 public 分支
git worktree add -B public public origin/public
# 生成网站并推送
hugo -D
cd public
git add -A
git commit -m "Push %date%"
git push origin public
cd ..
```

结合 Cloudflare Pages 自带 CI/CD,只需一个脚本即可实现一键推送更新。

不要在 `hugo.yaml` 中配置 `baseURL`,这会导致所有部署唯一预览 URL 被重定向到 `baseURL`。
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions hugo.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
languageCode: zh-cn
languageCode: zh
theme: PaperMod

pagination:
Expand Down Expand Up @@ -76,13 +76,13 @@ params:
limit: 10
keys: ["title", "permalink", "summary", "content"]

defaultContentLanguage: zh-cn
defaultContentLanguage: zh
defaultContentLanguageInSubdir: true

languages:
zh-cn:
zh:
languageName: "简体中文"
contentDir: "/content/zh-cn"
contentDir: "/content/zh"
weight: 1
title: "致之 | zzzhizhi"
description: "致之的博客"
Expand Down Expand Up @@ -116,10 +116,10 @@ languages:
- name: email
url: "mailto:[email protected]"
- name: rss
url: "/zh-cn/index.xml"
url: "/zh/index.xml"

editPost:
URL: "https://github.com/zzzhizhiw/zzzhizhi-blog/content/zh-cn"
URL: "https://github.com/zzzhizhiw/zzzhizhi-blog/tree/main/content/zh"
Text: "编辑"
appendFilePath: true

Expand Down Expand Up @@ -181,7 +181,7 @@ languages:
url: "/en/index.xml"

editPost:
URL: "https://github.com/zzzhizhiw/zzzhizhi-blog/content/en"
URL: "https://github.com/zzzhizhiw/zzzhizhi-blog/tree/main/content/en"
Text: "Edit"
appendFilePath: true

Expand Down
1 change: 0 additions & 1 deletion public
Submodule public deleted from 90b3f2
2 changes: 1 addition & 1 deletion themes/PaperMod
Submodule PaperMod updated from 3f4fb5 to 9d16e7

0 comments on commit 41decf4

Please sign in to comment.