Having softly launched this page on 1st January 2022 some of those I had sought early reviews from have already asked how I put this site together. While a lot of the information on this question is already available from a number of sources I didn’t find a single, concise, source bringing together the whole process, so it seems like a good subject to discuss.
Criteria
While getting started I considered the following criteria and reasoning:
- Cheap to host
- Easy to secure with https
- Use my existing domains
- Primary function as a blog
- Easy ongoing maintenance
- Good learning experience
- Use tools I’m already familiar with
I looked at but rejected a number of off the shelf sites, such as SquareSpace. I was hoping not to pay (call me cheap!); this choice does mean I am responsible for more maintenance than an off the shelf solution, you pay your money (or not) and take your choice I guess. My needs are relatively simple and a simple static site seemed to cover what I needed. I already had some domains registered and wanted to leave the registrations untouched. I knew I wanted to include a blog too.
I’m not a web developer by trade and my skills with HTML/CSS etc. are not strong, I didn’t want to have to focus on learning web dev. I am however very familiar with Markdown and use it a lot already. It seemed to cover everything I needed, if only there was a way to build a website that would ingest and publish markdown files.
Chosen Solution
- Azure Static Web Apps
- I came across the Azure Static Web Apps which provides a Free Personal tier
- This covers the cheap to host, it also includes free SSL certificates and custom domains (although not apex domains, e.g.
grahamwatts.co.uk
won’t work butwww.grahamwatts.co.uk
will) - This solution also tightly integrates with GitHub and can automatically create GitHub Actions to build and publish the site, including staging environments.
- Using a new solution in Azure also seems like a good fit for a learning experience while also using my existing GitHub setup
-
Jekyll
- Now that I had a hosting solution in mind I needed a static website generator that would leverage Markdown. Jekyll which has a specific selling point around use of Markdown
- It’s free and open-source.
- It provides either HTML or Markdown for content creation and includes themes.
- I can learn a bit of HTML and CSS when I want/need to but stick to Markdown and YAML for the rest…perfect!
-
Minimal Mistakes
- It won for me for 3 reasons
- A clean look
- Dark theme option
- Great documentation!
- Seriously, Michael, the creator has gone to great lengths to document working with the theme
- Good documentation is both a rarity and a vital tool
- It won for me for 3 reasons
-
Markdown
- OK, I’ve mentioned it a lot already. If you’re not familiar with what Markdown is check out the Codecademy: What is markdown article
- Put simply; it’s a language for writing structured text. So, rather than using a tool like, say, Word and having it embed a bunch of proprietary metadata alongside your code to determine the format of the file, Markdown allows you to define the format inline with your text
- e.g. writing
**some text in bold**
in a Markdown file will result in your text being rendered as bold text
- e.g. writing
-
GitHub
- For anyone not familiar with any form of computer development this is where the code, geeky, what is this bit comes in. I won’t try and teach it here, there are plenty of good resources available and maybe I’ll come back to this specifically in another article.
- In simple terms GitHub is a place to safely store, share and version control things you write. It’s typically used for software but could equally just hold documents you create (although there are probably better solutions for that specific use case)
- Azure Static Web Apps are built around modern software development practices and so you need to have your code hosted, GitHub is the default choice and choosing it allows the solution itself to automate a lot for you. Unless you’re tied into another platform I’d recommend GitHub for this project.
Process
A few disclaimer notes before I get started. I use Windows 11 as my workstation machine, however Jekyll can have some issues on Windows and so I actually developed my site in an Ubuntu 20.04 instance on Windows Subsystem for Linux (WSL).
I will skip over some steps like working with git and WSL as I can’t hope to do those fundamental skill subjects justice in this article. I’ll look to cover them in future posts and try to come back and link them here.
I also wanted to have some files in the repo but outside of my site source files so I created my site in a directory inside of my git repo rather than initializing the repo at the site level. If you want to do this simply create your repo directory first and initialize it, then follow the Jekyll steps for creating a site. It does mean that you may need to add the _site directory to your .gitignore file.
Prerequisites
-
Git
- Also see my article discussing getting started with git
- A code editor; I recommend Visual Studio Code
-
Microsoft Doc Authoring Pack extension
- Useful extension for working with and previewing Markdown files
-
YAML extension
- Adds syntax highlighting for YAML
- I’d also recommend that you check out other useful extensions for working with Git and writing clean code
- See my article on getting started with VS Code
-
Microsoft Doc Authoring Pack extension
- Jekyll prerequisites
- Azure account
- GitHub account
Getting started
- Create a working directory
- e.g.
C:\Users\<username>\Development
or~\Development
- e.g.
- Start with the Jekyll Step-by-Step Tutorial
- This page even covers initializing a git repo in your site directory
- Below is a view of my working directory where the
src
directory is the root directory referred to in the Jekyll tutorial
- Much of this structure you will build out as you work through the tutorial and build you site, so don’t worry if this looks like more than you have at this early stage. I include this as an example for what you’re working towards. - Make sure that you add jekyll to your ruby gemfile
source "https://rubygems.org" # Core site gem "jekyll"
📦GrahamWattsWeb ┣ 📂src ┃ ┣ 📂_data ┃ ┃ ┣ 📜authors.yml ┃ ┃ ┣ 📜navigation.yml ┃ ┃ ┗ 📜ui-text.yml ┃ ┣ 📂_drafts ┃ ┃ ┗ 📜2022-01-03-how-i-built-this-site.md ┃ ┣ 📂_pages ┃ ┃ ┣ 📜about.md ┃ ┃ ┣ 📜blog.md ┃ ┣ 📂_posts ┃ ┃ ┗ 📂general ┃ ┃ ┃ ┣ 📜2021-12-31-first-post.md ┃ ┃ ┃ ┗ 📜2022-01-01-why-knowledge.md ┃ ┣ 📂assets ┃ ┃ ┣ 📂images ┃ ┃ ┃ ┣ 📂blog ┃ ┃ ┃ ┃ ┣ 📜blog-teaser.webp ┃ ┃ ┃ ┗ 📂core ┃ ┃ ┃ ┃ ┣ 📜bio-photo.webp ┃ ┣ 📜404.md ┃ ┗ 📜index.html ┣ 📜.gitignore ┣ 📜Gemfile ┣ 📜Gemfile.lock ┣ 📜_config.yml ┣ 📜readme.md
- If you haven’t already initialized your repo, do so now
- e.g.
git init
- e.g.
- If you haven’t already created your remote repository on GitHub, do so now and push your repo to GitHub
- You’re now ready to begin building your site!
Theme
- If you’re using Minimal Mistakes add a ruby gem to your Gemfile
- e.g.
gem 'minimal-mistakes-jekyll'
- Other themes are available; see Jekyll: Themes for more information
- e.g.
source "https://rubygems.org"
# Core site
gem "jekyll"
# theme
gem "minimal-mistakes-jekyll"
- See Ruby Gems for working with gems
- See Testing for starting a local server and testing your site
- The Minimal Mistakes Docs pages describe the theme and how to customize it.
Ruby Gems
- Ruby supports add-on features, or plugins, which are referred to as gems
- Gems are declared in the Gemfile and are installed using
bundle install
or updated usingbundle update
- Gems are processed in the order they are declared in the gemfile
- So if you have plugins that require other plugins, you’ll need to declare them in the order you want them to be installed and processed
- For example if you’re using jekyll-redirect-from to add optional redirection URLs, and you want to use jekyll-sitemap to generate a sitemap, then you’ll need to declare jekyll-redirect-from before jekyll-sitemap
Example Jekyll Gemfile
source "https://rubygems.org"
# Core site
gem "jekyll"
# theme
gem "minimal-mistakes-jekyll"
# plugins
group :jekyll_plugins do
gem "jekyll-gist"
gem "jekyll-feed"
gem "jekyll-paginate"
gem "jekyll-include-cache"
gem "jekyll-coffeescript"
gem "jekyll-archives"
gem "jekyll-redirect-from"
gem "jekyll-sitemap"
end
Testing
- In a terminal, navigate to the root of your site
- e.g.
cd C:\Users\<username>\Development\<your-site-name>
- e.g.
- Run the command
bundle exec jekyll serve
- Your site is now running on port 4000 and will be available at (http://localhost:4000/)
- This also applies when using WSL
- In general, the site will hot reload as you add and edit pages.
- The main exception to this is changes to the
_config.yml
file. - If you make changes to the
_config.yml
file, you’ll need to restart the server. -
Ctrl + C
to stop the server -
bundle exec jekyll serve
to restart the server
- The main exception to this is changes to the
- As you build out your site and start working with posts you may want to either include draft posts or future dated posts
- Draft posts are not visible on the site until they are published
- To include draft posts run
bundle exec jekyll serve --drafts
- To include draft posts run
- Future dated posts are not published until their date has been reached
- To include future dated posts run
bundle exec jekyll serve --future
- To include future dated posts run
- You can combine command switches
- e.g.
bundle exec jekyll serve --drafts --future
- e.g.
- Draft posts are not visible on the site until they are published
Configuration
_config.yml
- Configuration for Jekyll is done in the
_config.yml
file. - You can find a sample _config.yml here
- Core site information such as title and URL go in this file
- Add as much default configuration as possible to this file
- If you’re a single author site add your profile details and social links here
- Define default layouts and page configuration such as allowing sharing or showing the date
Front Matter
- Front matter is a feature of a technology called Liquid which is used by Jekyll
- Liquid consumes header information, Front Matter, and uses it to render the page content in formatted HTML output
- Include the following at the top of your pages
---
---
- Between these two
---
lines you can define any metadata you want in YAML format
e.g.
---
author: {{ site.author }} # Or other author as listed in /_data/authors.yml
title: "Title" # Optional if the page name is not ideal
excerpt: "Brief synopsis of the page" # Optional
---
Variables
-
Variables are called using the
{{
and}}
characters- e.g. “{{ site.author }}”
- Many items can be variables sourced from either _config.yml such as
site.author
or default values provided by Jekyll- e.g.
author: {{ site.author }}
- e.g.
title: "{{ page.title }}"
- e.g.
excerpt: "{{ page.excerpt }}"
- e.g.
- Variables can also be used in page content
- Queries based on variables can also be written
---
layout: posts
permalink: /blog/
title: "Blog"
entries_layout: grid
---
# Latest Posts
{% for post in site.posts %}
- ## [ {{ post.title }} ]({{ post.url }})
{{ post.excerpt }}
{% endfor %}
Pages and Navigation
- Pages can go in the site root directory, or as I prefer in a
_pages
directory - For static pages I recommend using Permalinks
- e.g.
/about/
- e.g.
- You can write in Markdown or HTML
- But let’s be honest if you’re using HTML you probably don’t need to be using Jekyll 😜
- See Jekyll: Pages for more information
Posts
- Posts go into the
_posts
directory under your site root - Posts should have the naming convention YYYY-MM-DD-title-of-post.md for Jekyll to process them
- This also allows Jekyll to assign a publish date and provide a title for the article - although you can override these using Front Matter if you wish
- As with Pages posts can be written in Markdown or HTML
- See Jekyll: Posts for more information
Deployment
I’m not going to spend a lot of time here; the folks at Microsoft already have an excellent article on deploying Jekyll to Azure Static Web Apps using GitHub.
Check it out here: (https://docs.microsoft.com/en-us/azure/static-web-apps/publish-jekyll)
Top Tip: remember to push your changes to GitHub before deploying to Azure
Summary
As with everything there is more to it; however I hope this gets you started and saves you the time and searching I went through while researching making this site. I’ve tried to link to resources inline as much as possible and below are some of the key resources that got me through this.
In particular checkout Scott Hanselman and his YouTube channel. He covers loads of great topics and his video on Azure Static Web Apps got me started on this track.
If this article helped inspire you please consider sharing this article with your friends and colleagues, or let me know via LinkedIn or X / Twitter. If you have any ideas for further content you might like to see please let me know too.