Sept 21, 2020: Now a blog post at https://dfkaye.com/posts/2020/05/22/switching-to-hugo-reasons-resources-and-more/
I maintain a couple of github repositories which are nothing more than lists of interesting developer related links. This is one has been growing for nearly 5 years and I felt it was time to cut over to a an active list in a static site I could run a link checker on... et cetera.
I wanted to create a few working demos (CSS-only tabs, for example, or an aria-accessible modal with some JavaScript), and found that my free Wordpress instance (at https://dfkaye.wordpress.com) does not allow static JavaScript or inline JavaScript tags. A paid plan allows for that, but I wanted to see about alternatives.
Due to the hype in 2019 and a recommendation from a colleague, I started migrating my blog to Gatsby. After generating the basic blog from a starter project (and hooking up Netlify with github), I was dismayed to find that importing specific JavaScript files into posts works in GatsbyJS only when you enter the page URL directly in the browser — without loading the whole blog first. When you load the blog and navigate by hyperlinks controlled by ReactJS routing, the external JavaScript files and inline JavaScript elements fail to load because React scrubs them - see more about that at gatsbyjs/gatsby#833.
Gatsby is not a static site generator
Yes, Gatsby uses ReactJS on the server to create, not a static site, but a Single Page Application (SPA) using ReactJS on the client. Unless you are hosting a page that must handle multiple views of a single data source, SPAs have enormous accessibility and performance limitations, as witness Adam Silver's 2014 post, The disadvantages of single page applications.
After further searching (and emailing Chris Ferdinandi of the "Go Make Things" blog), I decided on Hugo, a static site generator written in the go programming language. Hugo supports HTML, CSS, JavaScript, markdown, and several others without a client-side framework getting in the way.
- Gregory Schier (2016), Why I Switched to Hugo → https://schier.co/blog/2016/07/30/why-i-switched-to-hugo/
- Greg changed his mind in December 2019, Abandoning the Static Site → https://schier.co/blog/abandoning-the-static-site
updating static sites is a pain. 🤕 Having to run a local server to preview content makes it difficult to publish updates quickly (especially from mobile devices) and even the slightest change requires re-deployment, resulting in wasted time.
- Sara Soueidan (2017), Migrating from Jekyll+Github Pages to Hugo+Netlify → https://www.sarasoueidan.com/blog/jekyll-ghpages-to-hugo-netlify/
- Benjamin Congdon (2018), Switching from Jekyll to Hugo → https://benjamincongdon.me/blog/2018/06/06/Switching-from-Jekyll-to-Hugo/
- Chris Ferdinandi (2018), Static Websites → https://gomakethings.com/static-websites/
Things that are difficult in WordPress are so easy in Hugo
- Christopher Kirk-Nielsen (2019), Switching From WordPress To Hugo → https://www.smashingmagazine.com/2019/05/switch-wordpress-hugo/
- Kasun Vithanage (2019), Moving to my own space → https://kasvith.github.io/posts/moving-to-my-own-space/
- Maëlle Salmon (2020), What to know before switching to Hugo/blogdown → https://www.r-bloggers.com/what-to-know-before-you-adopt-hugo-blogdown/
Awesome Hugo has a massive list of articles and resources for Hugo.
Brian Hogan (2020), Build Websites with Hugo - via bookshop.org
.
Highly recommend Brian's approach that introduces you to concepts as you need them rather than give you everything at once.
I wanted to cover a lot of bases before beginning the whole migration. Here's a spread out list:
- Use chocolatey
- install chocolatey (run as admin) https://chocolatey.org/courses/installation/installing#cmd
- install hugo using chocolatey https://gohugo.io/getting-started/installing/#chocolatey-windows
- verify hugo with
hugo help
- create/navigate to a directory that will serve as your hugo site
(ex. C:\projects\MyBlog) and execute
hugo
from there to generate
- YouTube video (2017), Install the Hugo binary → https://www.youtube.com/watch?v=sB0HLHjgQ7E
Watch the whole Hugo Tutorial series on YouTube by Mike Dane.
This series of 23 videos - about 5–10 minutes each - covers the basics of installing Hugo, explaining content, themes, templates, shortcodes, etc.
- HTML Skeleton - Josh W Comeau (2020), Starter HTML for every web page → https://joshwcomeau.com/snippets/html/html-skeleton
- minimal - Chris Ferdinandi's (2019) Hugo Starter Project → https://github.com/cferdinandi/hugo-starter#getting-started
- Chris's blog post about it → https://gomakethings.com/the-hugo-starter-kit/
- comprehensive - Ryan Watters' (2016) Hugo Starter with Gulp Asset Pipeline, SVG Icons, partials for global components, metadata, and social → https://github.com/rdwatters/hugo-starter
- bonus → rdwatters repo includes a linkchecker written in @golang → https://github.com/rdwatters/hugo-starter/blob/master/linkcheck.go
Hugo documentation steps are everywhere.
- When in doubt, start with the Hugo site → https://gohugo.io/
- gohugohq.com is an older (2017) site with quick tips → https://gohugohq.com/
- Zachary Wade Betz (2019), Make a Hugo blog from scratch → https://zwbetz.com/make-a-hugo-blog-from-scratch/
- Ben Robertson (2018), Designing Layouts for Screen Readers → https://benrobertson.io/accessibility/designing-layouts-for-screen-readers
- not Hugo-specific, but an early concern to keep in mind.
Themes are not strictly necessary, but they are shareable. You do one of the following:
- Go without a theme, meaning you will add things to the root-level folders
- Choose a theme to install in the themes folder
- Create your own theme
Insert raw html into markdown with shortcode.
Hugo generates its own RSS XML, here's how to include it in the <head>
tag → https://gohugo.io/templates/rss/#the-embedded-rss-xml
Start with Menu templates on the Hugo site → https://gohugo.io/templates/menu-templates/
Different ways to tackle pagination links.
- Hugo docs on pagination → https://gohugo.io/templates/pagination/
- Glenn McComb (2018), How to build custom Hugo pagination → https://glennmccomb.com/articles/how-to-build-custom-hugo-pagination/)
- James Kiefer (2018), Customized Hugo Pagination → https://jameskiefer.com/posts/hugo-pagination/
- Justin Dunham (2016), Implementing blog theme bells and whistles in Hugo: pagination, pages, related posts, and tag lists → http://justindunham.net/blog-bells-and-whistles-in-hugo/
Different ways to creates Content Security Policy (CSP) headers in Hugo.
First, check https://exploited.cz/xss/csp/strict.php for script-src "strict-dynamic"
support in your browser.
Then
- Roel Hogervorst (2019), Setting up CSP on your hugo (and netlify) site → https://blog.rmhogervorst.nl/blog/2019/03/13/setting-up-csp-on-your-hugo-site/
- Troy Hunt (2015), How to break your site with a content security policy: an illustrated example → https://www.troyhunt.com/how-to-break-your-site-with-content/
Report-uri
is a free (registration required) service for testing your CSP in production in report-only mode first → https://report-uri.com/- You can also test your site's CSP strength with https://securityheaders.com/ (sponsored by report-uri.com).
- Jeremy Likness (2019), Create a Content Security Policy (CSP) in Hugo → https://blog.jeremylikness.com/blog/create-content-security-policy-csp-in-hugo/
- James Kiefer (2019), Threaded comments for Hugo with Staticman v3 → https://jameskiefer.com/posts/threaded-comments-for-hugo-with-staticman-v3/
- James Kiefer (2018), Huge, SEO, and minification → https://jameskiefer.com/posts/hugo-seo-and-minification/
Hugo documentation on the sitemap template → https://gohugo.io/templates/sitemap-template/
Permalinks, aliases, canonical URLs → https://gohugo.io/content-management/urls/
You can use npm scripts
for building and deploying Hugo sites → https://www.aerobatic.com/blog/hugo-npm-buildtool-setup/
-
Use hugo archetypes to create a newsletter section → https://gohugo.io/content-management/archetypes/#create-a-new-archetype-template
-
Create a Newsletter with Mailchimp for free (2013) → https://business.tutsplus.com/articles/how-to-create-an-email-newsletter-with-mailchimp-for-free--fsw-39066
Add-This
social sharing icons in Hugo Sites (2017) → https://gohugohq.com/partials/add-this-social-sharing/- Gregory Schier (2014), Pure HTML Share Buttons → https://schier.co/blog/2014/10/22/pure-html-share-buttons.html
Hugo comes with really fast syntax highlighting from Chroma... → https://gohugo.io/content-management/syntax-highlighting/
- Zachary Wade Betz (2019),Syntax highlighting in Hugo with Chroma → https://zwbetz.com/syntax-highlighting-in-hugo-with-chroma/
- Maëlle Salmon (2020), How to showcase CSS+JS+HTML snippets with Hugo? → https://www.r-bloggers.com/how-to-showcase-cssjshtml-snippets-with-hugo/
See Chris Ferdinandi's site for
- How roll your own site search → https://gomakethings.com/how-to-create-a-vanilla-js-search-page-for-a-static-website/
- An implementation of search → https://gomakethings.com/search/?s=hello
- A Hugo Search partial → https://github.com/cferdinandi/go-make-things/blob/master/themes/gmt/layouts/search/single.html,
- The content markdown with a Search form → https://raw.githubusercontent.com/cferdinandi/go-make-things/master/content/search.md
See also Phil Hawksworth, Adding search to a JAMstack Site → https://www.hawksworx.com/blog/adding-search-to-a-jamstack-site/
- Peter LaValle (date not specified) describes how to create a shortcode for
mermaid
.
simple-icons
, Free SVG icons for popular brands → https://simpleicons.org/
- Greg Schier's blog - https://schier.co/blog/
- Garrick Aden-Buie's blog - https://www.garrickadenbuie.com/
- Chris Ferdinandi's daily tips - https://gomakethings.com/articles/
- Zachary Wade Betz's blog - https://zwbetz.com/blog/
- Isaac Levin's blog - https://www.isaaclevin.com/
- Simon Hearne's blog - https://simonhearne.com/
- Gergely Orosz's blog (links page 2) - https://blog.pragmaticengineer.com/page/2/
- Alison Hill (2019), A Spoonful of Hugo: Troubleshooting Your Build → https://alison.rbind.io/post/2019-03-04-hugo-troubleshooting/