Recently I created a website for my wife for her paintings as my first Hugo project. A really nice experience. Among other things, I created a small tool for creating labels for here painting and drawings. For that purpose, I added a property in the front matter of each page describing the painting indicating if the painting should be part of the exhibition or not. From a data modelling perspective, that was not a very sensible nor scalable approach, so I have extracted all information about exhibitions and instead placed in a data file.
The approach is pretty simple:
-
In https://github.com/stavnstrup/la-art/blob/master/data/udstilling.json, I have created two arrays.
-
In https://github.com/stavnstrup/la-art/blob/master/layouts/shortcodes/makelabels.html, I first merged the two arrays into an array called $exibitionArray. Each painting and drawing located in the subfolders maleri and tegning has an id attribute and the approach is to filter out all pages which does not have an id, which is part of the $exibitionArray as shown below:
$exibitionPages := where site.RegularPages .Params.id “in” $exibitionArray
but instead, it filters out all pages. Note the shortcode makelabels are called from the pages ark1, ark2 and ark3 page located in contents/tools folder.
- I have used the same idea on another page on the site. However, instead of using the in operator, I use the in function.