Extending configuration/params

I would like to make (for instance) my javascript pipeline extendable over modules and themes. For example:

  • module video adds a video.js
  • module search adds a search.js
  • theme adds theme.js
  • the resulting pipeline concatenates all files/minifies/hashes etc.

The problem I can’t wrap my head around is, how to tell the “generator” (probably the theme’s js-pipe) to add the javascript files from the modules. It is not possible (as far as I understand) to extend configuration parameters. An idea I had was to add a parameter extend_modulename and then iterate somehow over the existing modules and check for this parameter. But there seems to be no way (yet) to iterate over available modules.

How would you approach the problem? It would be nice to have a way to extend parameters or layouts somehow.

Note: It’s about one single JS file per site. Speed. SEO.

Not sure if this is what you are looking for but I do something like this. So you can manage the logic wherever you want and the params in your config. And this is location (theme/module) agnostic.

go-html-template
{{ "<!-- Essentiel Script -->" | safeHTML }}
{{- $js := slice }}
{{- range where .Site.Params.plugins.js "defer" false }}
  {{- $js = $js | append (resources.Get .link) }}
{{- end }}
<!-- Création du .js réellement utilisé -->
{{- $scripts := $js | resources.Concat "js/scripts_essentiels.min.js" | minify | fingerprint "sha384" }}
<script src="{{ $scripts.RelPermalink }}" integrity="{{ $scripts.Data.Integrity }}"></script>

{{ "<!-- Defer Script -->" | safeHTML }}
{{- $js := slice }}
{{- range where .Site.Params.plugins.js "defer" true }}
  {{- $js = $js | append (resources.Get .link) }}
{{- end }}
<!-- Création du .js réellement utilisé -->
{{- $scripts := $js | resources.Concat "js/scripts_defer.min.js" | minify | fingerprint "sha384" }}
<script src="{{ $scripts.RelPermalink }}" integrity="{{ $scripts.Data.Integrity }}" defer ></script>
# JS Plugins
[[params.plugins.js]]
link = "plugins/jQuery/jquery.min.js"
defer = false
[[params.plugins.js]]
link = "plugins/bootstrap/bootstrap.min.js"
defer = false
[[params.plugins.js]]
link = "plugins/slick/slick.min.js"
defer = false
[[params.plugins.js]]
link = "plugins/venobox/venobox.min.js"
defer = false
[[params.plugins.js]]
link = "plugins/search/fuse.min.js"
defer = true
[[params.plugins.js]]
link = "plugins/search/mark.js"
defer = true
[[params.plugins.js]]
link = "plugins/aos/aos.js"
defer = true

Can I have:

config.toml:

[[params.plugins.js]]
link = "plugins/jQuery/jquery.min.js"
defer = false

and

modules/video/config.toml

[[params.plugins.js]]
link = "plugins/bootstrap/bootstrap.min.js"
defer = false

and they get merged? I thought one will override the other.

Ah … yes I think so, unfortunately.

The module/theme parameter will be override if present in your main config.

My workaround for that was to have a unique name-space for my module parameters.
But my code need to take care of this with some IsSet & al.

For example having several range:

  • range where .Site.Params.plugins.js
  • range where .Site.Params.mynamespace.plugins.js

Hmm… that’s the problem. I want to “blindly” add js files from “maybe they are there” modules without knowing their names/paths.

Maybe mounting a folder with identical name in all the modules and then reading all files in that folder - I just don’t know how to read all the files in an assets folder. I wonder if I could “hack” a way to add a folder mount in content and then “ab”-using page ressources… hmm… testing around.

Using mounts does not work either. I was trying to merge a subfolder of data with individually named files and then checking if their filename starts with a certain string to load them and merge them… not working :wink: There must be a way to add configuration or content without having to manually configure it in the root repo.