自动使用最新版 Hugo 生成博客

2022-09-18 12:15:10 +08:00
 jyjmrlk
写了一篇用 Huginn 加上 Cloudflare Pages 的 API 实现自动使用最新版 Hugo 生成博客的文章。有升级强迫症的 Hugo 用户也许会感兴趣。

https://blog.gimo.me/posts/always-using-latest-hugo-to-build-my-blog/
1988 次点击
所在节点    分享创造
6 条回复
ybyl
2022-09-18 13:32:56 +08:00
小白看不懂,不会整。
arch9999
2022-09-18 19:39:45 +08:00
cfpages 可以指定 hugo 版本
stevenshum
2022-09-19 09:00:46 +08:00
楼上正解
还有一个方法就是,使用 [peaceiris/actions-gh-pages]( https://github.com/peaceiris/actions-gh-pages) 的 github actions 自动生成 Hugo 静态文件,推送到 gh-pages 或者 Cloudflare Pages ,以实现自动化部署
jyjmrlk
2022-09-19 10:03:25 +08:00
@arch9999 @stevenshum 你好,可能是我写的不太清楚,文章写的不是怎么部署或者怎么指定 Hugo 版本,而是一旦 Hugo 发布了新版本,就自动用最新版 Hugo 重新编译并部署博客。
czyt
2022-09-20 00:49:17 +08:00
cloudflare 的 go api 自己写个
```go

func updateHugoVersionEnv(project cloudflare.PagesProject, api *cloudflare.API) error {
release, err := GetGithubLatestRelease("gohugoio/hugo")
if err != nil {
release = "0.103.1"
}
release = release[1:]

ProductionEnv := make(map[string]cloudflare.PagesProjectDeploymentVar)
ProductionEnv["HUGO_VERSION"] = cloudflare.PagesProjectDeploymentVar{Value: release}
project.DeploymentConfigs.Production.EnvVars = ProductionEnv
api.UpdatePagesProject(context.Background(), accountId, project.Name, project)
return err
}


func GetGithubLatestRelease(repoName string) (string, error) {
type Tag struct {
ReleaseTag string `json:"tag_name"`
}
repo := fmt.Sprintf("https://api.github.com/repos/%s/releases/latest", repoName)
resp, err := http.Get(repo)
defer resp.Body.Close()
if err != nil {
return "", err
}

all, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
var t Tag
if err := json.Unmarshal(all, &t); err != nil {
return "", err
}
return t.ReleaseTag, nil
}
```
czyt
2022-09-20 00:55:08 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/880993

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX