Section 0: Get the course
Reference material for the course, Migrating WordPress to Hugo, Step by Step.
Section 1: Introduction
Hugo: the origin story
Official Hugo site: https://gohugo.io
Google uses site speed in web search ranking: https://webmasters.googleblog.com/2010/04/using-site-speed-in-web-search-ranking.html
WP Engine costs: https://wpengine.com/plans/
Jekyll: https://jekyllrb.com/
Hexo: https://hexo.io/
Is Hugo the best fit for your site?
My Hugo-based blog: https://tygertec.com
Disqus: https://disqus.com/
Shopify: https://www.shopify.com/
Course prerequisites
Windows PowerShell basics: https://docs.microsoft.com/en-us/powershell/scripting/getting-started/fundamental/windows-powershell-basics?view=powershell-6
Mac/Linux Bash scripting basics: https://ryanstutorials.net/bash-scripting-tutorial/
Section 2: Set up your tools
Install Chocolatey package manager (Windows only)
Site: https://chocolatey.org/install
Make sure it works: choco
*Don’t forget to run choco
commands as an administrator.
Attribution:
- “chocolatey” logo by Julian Krispel-Samsel
Install Hugo
- Windows:
choco install hugo
- macOS:
brew install hugo
- Ubuntu Linux:
sudo apt-get install hugo
More complex installs: https://gohugo.io/getting-started/installing
Install Visual Studio Code and extensions
https://code.visualstudio.com/
- Windows:
choco install visualstudiocode
- Alternate/Manual: https://code.visualstudio.com/download
Extensions
EditorConfig
Recommended .editorconfig for Hugo sites: https://gist.github.com/tygerbytes/2773f928bb5202669e14210d2b79c488
Installing Git
Windows
Using Chocolatey: choco install git
Manual: https://git-scm.com/downloads
Mac
Using Brew: brew install git
Manual: https://git-scm.com/download/mac
Linux (Debian-based)
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git
Linux (Red Hat-based)
sudo yum upgrade
sudo yum install git
Learning Git
Basic Git commands:
- git status
- git add .
- git commit -m “some message”
- git clone
- git push
- git pull
Learning more about Git: https://try.github.io/
Helpful VS Code extension, GitLens: https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens
Install posh-git (Windows, Optional)
Official site: https://github.com/dahlbyk/posh-git
Port to Bash: https://github.com/lyze/posh-git-sh
GitKraken: https://www.gitkraken.com/
Installing on Windows
choco install poshgit
Install Node.js
Windows
choco install nodejs
choco upgrade nodejs
For a manual install or other platforms, visit: https://nodejs.org/en/download/
Install 7-Zip (Windows only)
Section 3: Groundwork: Configure repository on GitLab
Meet GitLab
GitLab: https://www.gitlab.com
Create a GitLab account
Create a new private repo on GitLab
Setup your SSH keys
ssh-keygen -t rsa -C "your.email@example.com" -b 4096
cat ~/.ssh/id_rsa.pub | clip
More information: https://docs.gitlab.com/ee/ssh/README.html
Clone the repo on your machine
Commands we used in the lecture:
mkdir demo
cd demo
git clone git@gitlab.com:youraccount/your-repo.git
Sidebar: Hey, what about GitHub?
Places we visited in this lecture
Section 4: Build a new Hugo site to move into
Create a new Hugo site with "hugo new site"
hugo new site sitename
Baby Steps: Save your work with "git commit"
git add .
git commit -m "Add a message here"
git push
Add .editorconfig for consistent file formatting
Sample .editorconfig
file
Yes, this is the same as the one referenced under Tools
Gitignore: Telling files to "talk to the hand"
.gitignore
file generator: https://www.gitignore.io/
Section 5: Choose and configure a theme
Why do I need a new theme
Choosing a Hugo theme
Hugo “theme park”: https://themes.gohugo.io/
Google Lighthouse: https://developers.google.com/web/tools/lighthouse/
Install your new Hugo theme
Note: If you’re following along with the course, clone my fork of the theme to avoid issues.
It’s at https://github.com/tygerbytes/HugoMDL
The SSH url is: https://github.com/tygerbytes/HugoMDL.git
clone method
git clone --depth 1 https://github.com/tygerbytes/HugoMDL.git ./themes/HugoMDL
Delete the .git
directory:
Windows PowerShell: rm --recurse --force .\themes\HugoMDL\.git
Mac/Linux: rm -rf ./themes/HugoMDL/.git
submodule method
git submodule add https://github.com/tygerbytes/HugoMDL.git ./themes/HugoMDL
Showing .gitignore
from the command line:
cat ./.gitignore
Configure the theme using the `config.toml` File
Running hugo server: hugo server
Stopping the running server: Ctrl-C
Force most web browser’s, including Google Chrome and Firefox, to do a hard refresh: Ctrl F5
A hard refresh means that nothing is loaded from the local cache; a new request is sent to the webserver.
Discovering Front Matter
Section 6: Write a new post with Hugo
Meet markdown - the easiest way to format text
Essential markdown cheatsheet: https://www.tygertec.com/markdown-cheatsheet/
Create a new post with Hugo
hugo new post/some-post.md
Live site preview with the Hugo server
hugo server
Include draft posts: hugo server -D
Add a picture with {{ figure }}
The figure shortcode: https://gohugo.io/content-management/shortcodes/#figure
Unleash your draft post
Alternative: Create a new post as a page bundle
Create a post as a page bundle: hugo new post/some-post/index.md
More information: https://gohugo.io/content-management/page-bundles/
Section 7: Manually move posts and pages from WordPress to Hugo
Migrate a single post
Preserve your post metadata
Migrate post images
Alternative: Migrate post images as a page bundle
Clean up your markdown
Figure shortcode again: https://gohugo.io/content-management/shortcodes/#figure
Migrate the About page
hugo new about/index.md
Section 8: Deploy Site with GitLab Pages
Configure CI/CD with a .gitlab-ci.yml file
Watch your site build in the CI pipeline
Viewing your deployed site (404 Not Found)
My site has no style! Troubleshoot locally with HTTP Server
install http-server: npm install http-server -g
Configure a custom domain name
Google domains: https://domains.google
Section 9: Deploy Site with Netlify
Meet Netlify
A note about security
How much will Netlify cost?
Configure a custom domain name
- Netlify Managed DNS: https://www.netlify.com/docs/dns/
- Custom domain name on Netlify: https://www.netlify.com/docs/custom-domains/
- SSL/DNS troubleshooting: https://www.netlify.com/docs/ssl/#troubleshooting
Attribution:
- “Domain names” picture by JanBaby on pixabay
Automatic deploy previews for Merge Requests
Create a new Git branch:
git checkout -b UglyTitles
Silly CSS that we add to custom.css
:
.mdl-card__media h3 {
/* I set the color to red… */
color: red;
/* transform the text to uppercase… */
text-transform: uppercase;
}
/* And our client wants some goofy emoji after each title. We add:*/
.mdl-card__media h3:after {
content: "💯🍌"
}
Update submodules:
git submodule foreach git pull
Deleting the UglyTitles
branch:
git checkout master
git branch -D UglyTitles
More control: Netlify.toml
netlify.toml: Branch-specific deploy settings
Creating the branch and pushing it to GitLab:
git checkout -b draft-post-preview
git push --set-upstream origin draft-post-preview
# netlify.toml
[build]
command = "hugo"
publish = "public"
# Branch Deploy context: all deploys that are not from a pull/merge request or
# from the Production branch will inherit these settings.
[context.branch-deploy]
command = "hugo -D"
# Specific branch context: all deploys from this specific branch will inherit
# these settings.
[context.draft-post-preview] # 'staging' is a branch name
command = "hugo -D"