How to use the container Hugo version with One Click Netlify CMS example

别等时光非礼了梦想. 提交于 2020-01-06 09:56:29

问题


In the Netlify CMS community chat, the question keeps coming up how to manage the Hugo version without a bin folder and executable.

The one-click-hugo-cms example is a deploy to generate a Hugo static site and use Netlify CMS to be able to add posts for the site.

The Issue: The site setup uses a bin folder to store the Hugo executable for simplicity, but the developer wants to use a different version of Hugo and keep it up to date without having to keep copying new executables to the Hugo bin folder.


回答1:


The bin folder for Hugo is NOT required. Netlify manages a Hugo version install in the container based on the environment variable (HUGO_VERSION) when there is a build.

Basically follow these steps:

  • Remove the bin folder and executable out of the project
  • Change the command to the bin path and call it globally
  • Let Netlify know what version you want to use in the netlify.toml

Remove the bin path

Edit this line

const hugoBin = `./bin/hugo.${process.platform === "win32" ? "exe" : process.platform}`;

to be

const hugoBin = 'hugo';

netlify.toml

[build]
  command = "yarn build"
  publish = "dist"
[build.environment]
  YARN_VERSION = "1.3.2"
  HUGO_VERSION = "0.36.1"

[context.deploy-preview]
  command = "yarn build-preview"

NOTES:

  • Make sure on your local development to have Hugo installed in a global path location
  • Netlify installs Hugo version 0.17 by default, so use HUGO_VERSION to specify version
  • Optional way to manage Hugo versions explained here
  • one-click-hugo-cms example repo without bin folder


来源:https://stackoverflow.com/questions/48999330/how-to-use-the-container-hugo-version-with-one-click-netlify-cms-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!