在 Netlify 构建上更改 Hugo 版本 [英] Changing Hugo version on Netlify build

查看:88
本文介绍了在 Netlify 构建上更改 Hugo 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚发布了 Hugo 的新版本(目前为 0.32).

There is a new (0.32 at this time) version of Hugo that has just been released.

社区中有人询问如何处理这种情况以在 Netlify 版本上测试新版本.

It was asked in the community how to handle this situation to test out the new version on a Netlify build.

推荐给 Netlify 用户的行动方案是什么?

What is the recommended course of action for Netlify users?

推荐答案

如果你没有在 Netlify 上设置一个变量 HUGO_VERSION 它默认为版本 0.17<HUGO 的/code>.

If you do not setup a variable HUGO_VERSION on Netlify it defaults to version 0.17 of HUGO.

为了定位您的构建,Netlify 在您网站的在线控制台中有一个自定义变量字段.这对于需要针对所有工作流构建的简单站点来说已经足够了.

To target your builds Netlify has a custom variables field in the online console for your site. This will be enough for simple sites that need to target all workflow builds.

Netlify 允许在构建包路径的根目录下放置一个配置文件 (netlify.toml),该文件将告诉它使用哪些配置并覆盖任何构建环境您在上面的简单示例中设置的变量.

Netlify allows for a config file (netlify.toml) at the root of your build package path that will tell it what configurations to use and will overwrite any build environment variables you setup in the simple example above.

netlify.toml Hugo

    [build]
      publish = "public"
      command = "hugo"
    # build a preview of the site [hugo --buildFuture]
    [context.deploy-preview]
      command = "hugo --buildFuture"
    # The default version you use for production if you don't use context
    [build.environment]
      HUGO_VERSION = "0.29"
    # The version you use for production
    [context.production.environment]
      HUGO_VERSION = "0.29"
    # you can lock a version of hugo for a deploy preview
    [context.deploy-preview.environment]
      HUGO_VERSION = "0.32"
    # you can lock a version of hugo for a branch-deploy (other than previews)
    [context.branch-deploy.environment]
      HUGO_VERSION = "0.32"

注意事项:

  • 有不同版本的分支部署以测试新版本的 Hugo
  • 还针对 Netlify 允许的其他环境变量,例如 NODE_VERSION
  • 为目标构建设置自定义环境变量,详见这篇文章 可以从您的 Hugo 模板中访问!
  • 阅读Netlify 的部署上下文此处
  • Things to note:

    • Have different versions for a branch deploy for testing a new version of Hugo
    • Also target other environment variables that Netlify allows like NODE_VERSION
    • Setup custom environment variables to target builds explained in this writeup that can be accessed from within your Hugo templates!
    • Read about deploy contexts for Netlify Here
    • 这篇关于在 Netlify 构建上更改 Hugo 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆