V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
jyjmrlk
V2EX  ›  分享创造

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

  •  
  •   jyjmrlk ·
    masakichi · 2022-09-18 12:15:10 +08:00 · 1985 次点击
    这是一个创建于 583 天前的主题,其中的信息可能已经有所发展或是发生改变。
    写了一篇用 Huginn 加上 Cloudflare Pages 的 API 实现自动使用最新版 Hugo 生成博客的文章。有升级强迫症的 Hugo 用户也许会感兴趣。

    https://blog.gimo.me/posts/always-using-latest-hugo-to-build-my-blog/
    6 条回复    2022-09-20 00:55:08 +08:00
    ybyl
        1
    ybyl  
       2022-09-18 13:32:56 +08:00
    小白看不懂,不会整。
    arch9999
        2
    arch9999  
       2022-09-18 19:39:45 +08:00 via iPhone
    cfpages 可以指定 hugo 版本
    stevenshum
        3
    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
        4
    jyjmrlk  
    OP
       2022-09-19 10:03:25 +08:00
    @arch9999 @stevenshum 你好,可能是我写的不太清楚,文章写的不是怎么部署或者怎么指定 Hugo 版本,而是一旦 Hugo 发布了新版本,就自动用最新版 Hugo 重新编译并部署博客。
    czyt
        5
    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
        6
    czyt  
       2022-09-20 00:55:08 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5412 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 07:28 · PVG 15:28 · LAX 00:28 · JFK 03:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.