Hello Again - Notes on Site Move
Welcome again to the blog. This is still running on Hugo, but after considering how to get recent posts onto my main site, I decided to just incorporate my main site into the blog where it is so much easier to include blog posts anywhere I like in any format I like. I hope to make “cards” for posts on the home page whenever I have a moment to do some more development. So here we are. Below are some notes I made as I worked out some decisions during this development process.
Vanilla JavaScript is Enough
Before today’s modern browsers’ compliance with standards, the jQuery library was a huge help in reliably manipulating web pages via the DOM on what are now legacy browsers. Today’s JavaScript frameworks such as Angular and React need their own build separate from the Hugo build, adding a non-trivial step to deployment during development and production. For a site like this, using plain vanilla JavaScript is sufficient and much easier, though not nearly as much fun.
Put Reusable Content into Hugo Partials Wrapped by Shortcodes
The issue of resuable code in Hugo
At first glance, I questioned why this does not happen automatically within Hugo. Why can’t we have a single reusable bit of functionality that
- Can be called from a markdown page which can only make direct references to shortcodes,
- AND can be called from a shortcode which cannot call other shortcodes Shortcodes can call partials,
- AND can be called from partials which can only call other partials? Partials cannot call shortcodes nor can they make direct refences to markdown pages.
The solution
- I believe the answer is the context of a single reusable type of code would be ambiguous and output confusing to developers. The context might be a page, a section (folder full of pages) or other group of pages.
- Because the attributes available change depending context, generic code reuse is tricky.
- However, code reuse from markdown pages, shortcodes and partials are possible by putting the reusable code into partials and wrapping the partials in shortcodes for use in markdown pages.
- The markdown page calls the shortcode.
- That shortcode and other shortcodes call the partial.
- Other partials can call the partial.
CSV File to Drive content
- I reuse a comma-separated-value file to drive the services summary on the home page and the detail on the services page via shortcodes and partials. I find it easier to maintain these CSV files for some structured site content rather than doing it all in markdown.
- Hugo’s resources.Get
defaults to reading as if you are in the assets folder. For example, if the file you want to read is in /assets/site-data/services.csv, use
resources.Get "site-data/services.csv"
Hugo Themes
- Use local layouts folder to override your theme’s files. This is dangerous and tricky if you ever want to switch themes. It is somewhat helpful if you want to implement updates from the source theme, but if you have already overwritten a particular file that is later updated, well, you’ll have figure that out and redo your override.
- This site is based on the Doit theme, but the much older version 0.4.0 which still supports the “dark” theme which I like a lot. I could not get the dark theme to work on the current code in Gitub, only black and the default white.
- Unfortunately, for these two reasons, my code is so far away from the original theme that it seems unlikely that I’ll be able to merge my changes with the original theme.
As I write this post, the site is barely professional-looking enough with the appropriate content, what you might call a minimal viable site. My to-do list is quite long. This is a fun project. I hope to have more content, functionality and flair soon.