So yesterday I announced a new feature in Conductor called Filters. Little built-in commands for performing simple tasks without having to write whole scripts for them. In the process of writing the feature, I forgot what might be the most useful function of all: injecting JavaScripts.

So I’ve added insertScript(path) as a filter. You can give it a full path to a JavaScript file, or you can create a directory at ~/.config/conductor/javascript, add the file there, and then just reference it by name like filter: insertScript(mermaid) (the .js is added automatically if needed). You can insert multiple scripts at once by separating the paths with commas, e.g. insertScript(blog,mermaid).

I also added an insertTitle filter that will attempt to pull a title out of metadata (YAML or MMD), and failing that use the filename, converting a slug into a titlecased title (e.g. 2024-05-24-my-blog-post.md becomes My Blog Post), and insert it as an H1 at the beginning of the content (after any front matter/metadata).

An example config for using this (assuming the scripts blog.js and mermaid.js exist in the above directory) would look like:

tracks:
  - condition: phase is pre
    tracks:
    - title: Blog post preprocess
      condition: path contains _post AND has yaml
      sequence:
        - filter: setStyle(BrettTerpstra.com)
        - filter: addTitle
        - filter: insertScript(blog,mermaid)

That config would require no scripting at all. The style would be set, an h1 title would be added, and two scripts would be injected before running through the default Marked processor.

If you think of any more that would be useful, please let me know!