雨果:从GitHub导入sass /代码的最佳方法?

问题描述

我试图弄清楚Hugo如何在运行hugo server时(自动)从Github文件夹中提取最新文件。特别是,我喜欢通过GitHub从Primer CSS提取css文件。最好的实现方法是什么,这样我就不必总是在我的Git上手动更新Primer CSS?

我当时以为模块是一种方法(config.yaml):

module:
  imports:
    - disable: false
      path: github.com/primer/css
      mounts:
          - source: src/scss
            target: assets/scss/primer

但是,将其添加config.yaml时似乎无效:

Error: module "github.com/primer/css" not found; either add it as a Hugo Module or store it in "/Users/user/code/my-theme/themes".: module does not exist

是否有简单的最佳实践,可以自动https://github.com/primer/css/(/ src)中提取最新文件并将其加载到/assets文件夹中?或者是使用npm节点模块的唯一方法,例如:https://github.com/lucperkins/hugo-primer

谢谢!

解决方法

我为此苦了很长时间。关键是通过运行hugo mod init {anything}将您的站点初始化为“运行模块”。这将创建一个go.mod文件。因此,如果您运行hugo mod init mywebsite会生成看起来像这样的go.mod

module mywebsite

go 1.14

require github.com/primer/css v1.0.0 // indirect

之后,这些模块将为您工作。