本文介绍了如何通过一键式Netlify CMS示例使用容器Hugo版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Netlify CMS社区聊天中,问题不断出现,如何在不使用Hugo版本的情况下进行管理一个bin文件夹和可执行文件.

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

one-click-hugo-cms 示例是一个部署以生成一个Hugo静态网站,并使用Netlify CMS能够为该网站添加帖子.

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.

问题:为了简单起见,站点设置使用bin文件夹存储Hugo可执行文件,但开发人员希望使用其他版本的Hugo并保持最新状态,而不必继续复制Hugo bin文件夹中添加了新的可执行文件.

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.

推荐答案

Hugo的bin文件夹是不需要.生成时,Netlify根据环境变量(HUGO_VERSION)管理容器中的Hugo版本安装.

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:

  • 从项目中删除bin文件夹和可执行文件
  • 将命令更改为bin路径并全局调用
  • 让Netlify知道您要在netlify.toml
  • 中使用哪个版本.
  • 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

编辑此行

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

成为

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

这篇关于如何通过一键式Netlify CMS示例使用容器Hugo版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 22:29