Hugo

Dynamic table of contents with Intersection Observer

My Hugo theme had a jQuery-powered dynamic table of contents. I thought it didn’t make much sense to keep the jQuery library (even a small version) if I’m just using it for that. So, out it went, and in went a JavaScript version with Intersection Observer. This is based on Ben Frain’s version, simplified a bit since we get the table of contents statically embedded. Code The full code (in layouts/partials/article.

Check if a static site is moved correctly

The lazy person’s guide to confirming that a move to a static site worked. Overview: Download all relevant URLs from Search Console Convert download to a URL list Check for http to https redirects Check for valid final URLs Download all relevant URLs I’m picking one approximate source of truth - the URLs that received impressions in Google Search. This list doesn’t need to be comprehensive, just something more than I’d manually pick.

Simple site-search for Hugo, using Google

Want a simple search functionality for your Hugo site? Here’s the setup I used here. It uses the Google search advanced query operators (which you can get if you go to Tools / Advanced Search) to add the site as a separate parameter. as_q = the query you want as_sitesearch = the site you want to search in It opens up in a separate window, if you’re ok with that.

Adding archive.org links to old posts in Hugo

Since there’s so much old content here, I thought I’d add links to archive.org in links in older posts. At least this way people have a chance to see what might have been there earlier. Following adding nofollow in hugo I added the following to the render-link.html file: {{- if strings.HasPrefix $linkurl "http" }} {{- if gt (sub now.Year .Page.Date.Year) 5 }} (<a href="https://web.archive.org/web/{{ .Page.Date.Year }}*/{{ $linkurl }}" {{- with $relval}} rel="{{ trim .

Using nofollow links in Hugo's Markdown

I seem to have more posts about nofollow links than actual nofollow links, but here’s one more. Markdown doesn’t support nofollow links by default, so you either have to write them in HTML or tweak your template to handle them. Update: after reviewing the options, I ended up using a bounce-URL instead. Nofollow links with HTML This is kinda simple. Just write HTML directly in markdown: anchor <a href="https://example.com" rel="nofollow">anchor</a> Nofollow links with markdown There are probably easier ways to do this, but I didn’t spot any off-hand.