Proper use of Shortcodes/Templates

I create a documentation site for most of my Linux knowledge. Some stuff is about window managers, which need additional installations of packages. So it would be neat to have something like:

The software ich recommend:
Package_Name_A, Package_Name_B, etc.

Install it on Arch-distributions with:
sudo pacman -S package_name_a package_name_b etc

Since each Package gets its article I would like to link them to get something like:

The software ich recommend:
[Package_Name_A]{{< relref "Package_Name_A" >}}, [Package_Name_B]{{< relref "Package_Name_B" >}}, etc.

Install it on Arch-distributions with:
sudo pacman -S package_name_a package_name_b etc

All of that should happen automatically. So my plan, in the end, is to have a shortcode which reads a YAML-file (those files will differ), reads from there the package names, creates the links, and adds a {{< highlight bash >}} around sudo pacman -S.

My first idea was to create a shortcode which calls the YAML-file, extracts the relevant information and finally, uses HTML and does something like:

<p> I recommend the following software:</p>
    {{ range $element_val := $software_names }}
    {{ end }}

{{< highlight bash >}}
    $pm_command {{ range $element_val := $package_names_standard }} {{$element_val}} {{ end }}
{{< /highlight >}}

However, the problem is that shortcodes work only on content files. Which makes somehow sense, I guess. My question now: How do I realize that?

I thought about partials, but I can’t pass parameters like the YAML-file to them. In addition to that, those seem to be more on the static side, right? I can let them render content but only from the current site? And again, those are HTML files anyway.

Ideally, I could use something with Markdown. Still, I’m clueless about how to achieve that.

Do you guys have any ideas?


I built a Hugo site to store package installer commands for me, and I listed the packages as a content type with the package name as front matter, then for “installation profiles” (a content type) I created a list of packages in front matter and use the installation profiles single template to grab the packages and list their package names in a line for all the distros.

I didn’t keep the site, but that’s the shape of it. Good luck! :slight_smile:

1 Like