HUGO

Asset pipelines with page resources?

Do pipelines work with resources for a local page?

I’ve got a simple site like the following:

- content/
    - posts/
        - foo/
            - bar.md
            - bar.scss
- layouts/
  - _default/
    - baseof.html
- assets/
  - main.scss

The body of bar.md is like:

---
title: Foo Bar
resources:
  - src: "**/*.scss"
styles:
  - main
  - ./bar
---
Hello Foo Bar

And in my _default/baseof.html file (in my layouts directory) I’ve got something like the following:

...
  <head>
    ...

    {{ range .Params.styles }}
        {{ $resource := false }}
        {{ if hasPrefix . "./" }}
            {{ $resource = $.Resources.GetMatch (printf "%s.scss" .) }}
        {{ else }}
            {{ $resource = resources.Get (printf "%s.scss" .) }}
        {{ end }}

        {{ if $resource }}
            <link rel="stylesheet"
                href="{{- ($resource | resources.ExecuteAsTemplate (printf "styles/%s" .) $.Site | toCSS | postCSS (dict "config" "etc/postcss.config.js") | minify | resources.Fingerprint).Permalink -}}" />
        {{ else }}
            {{ warnf "failed to find resource: %s" . }}
        {{ end }}
    {{ end }}

    ...
  </head>
...

NOTE: the ellipses represent filler information that isn’t really important.

What I was trying to implement was a smart style system, if the stylesheet you
want to include was prefixed with a ./ it was loaded from the local pages
resources, otherwise it was loaded from the global resources directory.

Only I’ve found that none of the pipeline steps work with bar.scss, they work
fine with main.scss.

bar.scss is placed into the output document as is, without
being converted to css, minified or fingerprinted.

I can only surmise none of the pipeline features of regular resources are working
with page resources, is this expected?

S.N.

I’m on Hugo Static Site Generator v0.68.3/extended linux/amd64 BuildDate: unknown.

Okay, weird, I restarted my server and it seems to be working fine.

Maybe it was my browsers caching policy or something.

Okay, evidently it’s not a browser issue. It’s a hugo server issue. Changes to page resources does cause the site to be rebuilt, but the pipeline isn’t run again on the new file. Meaning only the original file is present. To get it to update, you have to restart the server; I’m not quite sure why this is happening :cry:.

I think I just ran into this. Were you able to determine the cause, or more importantly, a solution?

@jmooring I ran into similair issues with a webpack setup where I changed some javascript files, webpack-dev-server processed and spat out some new files to my assets directory and then I ran those through the hugo pipelines. The scripts seem to be cached by hugo so the new scripts weren’t being loaded. But I’ve upgraded Hugo Static Site Generator v0.72.0/extended linux/amd64 BuildDate: unknown and this isn’t an issue for me anymore. I haven’t tried with pageResources but I’d suspect it should be fixed there as well.

Maybe not…