.js from module is not being copied to public


one more question from my side regarding plugins. I want to use the following plugin: hugo-modules/search at master · gethugothemes/hugo-modules · GitHub

I included it in the params.toml:

link = "js/search.js"

It is being loaded in the theme’s module.toml:

path = "github.com/gethugothemes/hugo-modules/search"

I can access its partials and also its (vendored) scss. I run it without vendoring, but that way I can use postcss to separate code a bit better (otherwise it cannot access it during build).

Any ideas why the .js is not loaded? It also does not show up in the public directory.

Repo: GitHub - Sapp00/hugo_dummy

Thank you for your help! Really enjoy the helpful community here!

Start your troubleshooting in theme/layouts/partials/head.html…

  {{ if templates.Exists "search-index.html" }}
    {{ partial "search-index.html" . }}
  {{ else }}
    {{ errorf "Unable to find the partial named search-index.html" }}
  {{ end }}

That is actually quite surprising since the content of “search-index.html” is included in the output.

Does that have to do something with the vendoring? So that it cannot find it during building the theme, but later it can be replaced when building the main mod?

I think that this is the same issue that I wanted to overcome by using the vendoring and referencing the full path, I dont think that this is “best practice”:

// theme/assets/css/styles.scss

@import "node_modules/tailwindcss/base";
@import "node_modules/tailwindcss/components";
@import "node_modules/tailwindcss/utilities";

@import "_vendor/github.com/gethugothemes/hugo-modules/search/assets/scss/search.scss";

I think that it could work if I would reference the js in a similar way, but somehow it cannot resolve the partial that way. Is there a better way to achieve this, what would be the best practice?

And one side question: is there a functionality within hugo, so that it throws warnings when partials cannot be resolved? Unfortunately it seems like even in verbose / debug mode, it does not inform the user.

See my previous comment about the templates.Exists function.

Disregard the templates.Exists guidance for troubleshooting this problem. I forget that the arg is relative to the layouts component, not layouts/partials. Sorry about that.

Back to the original question:

Yes. These instructions are insufficient, perhaps intended for use with themes provided by Gethugothemes.

To include the script element within your head element, and to publish the script to disk, place this in head.html:

{{ range site.Params.plugins.js }}
  {{ with resources.Get .link }}
    <script src="{{ .RelPermalink }}"></script>
  {{ end }}
{{ end }}