Some notes on hugo templates and taxonomies #16
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
While working on supporting custom searching and filtering functionality on the
/publicationspage, I took some time to figure out the differences between the following:kind=taxonomy)kind=section)kind=term)because all of them work from the
_index.mdsource.So what I determined (because I finally read the docs thoroughly... but perhaps not even enough yet):
index.mdit is a regular page and haskind=pageand will be rendered by thepage.htmltemplate (orsingle.htmlif the former does not exist)_index.mdit is either:content/books/_index.md), and this will be rendered by thesection.htmltemplate ; orcontent/projects/_index.md), and this will be rendered by thetaxonomy.htmltemplate ; or_index.md), is part of a configured taxonomy (e.g. taxonomy could bepersonsandstephan-heuniswould be the term), and this would then be rendered by theterm.htmltemplate, orSome further important notes:
list.htmltemplate is the fallback for all of:section.html,taxonomy.html,term.html_index.mdsource is available (for either a section or a taxonomy), Hugo will still use the relevant template to render a section or taxonomy page at the relevant path (e.g. ifpersonsis a taxonomy, Hugo will render thetaxonomy.htmltemplate for<website-domain>/persons/even if nocontent/persons/_index.mdexists)I needed to figure all of this out for the filtering/searching functionality on the
/publicationspage because:publicationsis a configured taxonomy or not will influence which template,section.htmlortaxonomy.html, should be customizedjsondata file), and we need to know whether we are working with regular pages or term pages in order to customize that template correctlySo, after working through all of the above, my approach going forward will be:
publicationsas a taxonomy (already done)update_publications_data.yamlworkflow that currently generates adata/publications.jsonfile used by the current filtering/searching functionalityupdate_publication_pages.yamlwofklow that generates individual publication pages, same as persons, projects etc. These will becontent/publications/<pid>/_index.mdpages, and their front matter will contain information about the publication.layouts/publications/taxonomy.htmlpage to contain the functionality for filtering/searching publications; this includes code to fetch all front matter from all publication term pages (i.e. pages atcontent/publications/<pid>/_index.md) and put that into a json object for the page to use furtherSpme notes on hugo templates and taxonomiesto Some notes on hugo templates and taxonomiesRegarding:
The challenge here is: I currently use javascript for injecting html elements on the fly based on the result after searching/filtering. However, this is a convoluted way to structure html. I rather want to use hugo templating for the layout of a single publication element in the list. But the problem is that hugo templating renders once on build, not at runtime.
How I think I will approach this is to use a hugo partial to render every publication on build, and then use the javascript just to handle publication element visibility based on the results of searching/filtering at runtime.
This keeps the components separated and every tool does what it is good at.
This might become a problem for very large data arrays, but I don't want to optimise for that prematurely. What we could consider when we need to do this is to extend the current approach:
I.e. can use the partial to return the html for a given element, and add that into the json. And then let the javascript do filtering and inject the html of the element back into the DOM.