Hugo: Best way to import sass / code from GitHub?

Viewed 393

I'm trying to figure out how Hugo can (automatically) pull the most recent files from a Github folder when running hugo server. In particular, I like to pull css files from Primer CSS by GitHub. What is the best way to implement that, so that I do not always have to update the Primer CSS manually on my Git?

I was thinking modules would be a way (config.yaml):

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

However, when adding this to config.yaml, it does not appear to work:

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

Is there any simple best practice in automatically pulling the most recent files from https://github.com/primer/css/(/src) and loading it into the /assets folder? Or is the only way to work with npm node modules, like here: https://github.com/lucperkins/hugo-primer

Thanks in advance!

1 Answers

I struggled with this for a long time. The key is to initialize your your site as a "go module" by running hugo mod init {anything}. That will create a go.mod file. So if you ran hugo mod init mywebsite that generate a go.mod that looks something like this:

module mywebsite

go 1.14

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

After that, the modules should work for you.

Related