How to for dummies: creating a static website with Jekyll and GitHub Pages
Prerequisites:
- A bit of knowledge on git
- A bit of knowledge on Markdown (HTML is useful but not necessary)
- Time
There are different ways to create a static website with Jekyll, probably a lot that I don’t know about! Here are the steps I followed myself, a bit more fine-grained than on the Jekyll website itself. I hope they’re useful! If not, then I’ve made some documentation for my future self 😊
Step 1: Install Ruby, RubyGems and Jekyll
Note: if you are using Windows (like me ☹), consider downloading the Ubuntu app from the Windows store (i.e., using the Linux Subsystem for Windows). Then follow the steps from this instruction video.
Use a command prompt or the Ubuntu app for the commands listed.
We need to install:
Ruby, a programming language that can run Jekyll
- Check your version:
ruby -v
(preferably version 2.1 or higher) - Download it for Windows here (Mac already has it installed)
- Check your version:
RubyGems: a package manager for Ruby that can install, update and maintain Ruby programs. We later use it to install Jekyll
- Check your version:
gem -v
- Check your version:
Jekyll through using RubyGems:
gem install Jekyll bundler
- Check your version:
jekyll -v
- Check your version:
Step 2: Create a Jekyll site in a git repository
If you haven’t already, install git and make a GitHub account
Now, you can go two ways: either A) create a Jekyll website from scratch, without any prespecified formatting or B) copy a repository using a specific theme and personalize it.
A) Create a Jekyll website from scratch
Move to the local folder where you want to store your local site files:
cd /my/folder/
- Note: if using Ubuntu on Windows, it took me some time to figure out how to move through folders. My C drive was for example reachable through
cd /mnt/c/Users/dorie/
- Note 2: Use the
TAB
key to autofill commands!
- Note: if using Ubuntu on Windows, it took me some time to figure out how to move through folders. My C drive was for example reachable through
Create a new Jekyll site:
jekyll new [nameofsite]
- Note: aptly name the project!
- If you want to use GitHub Pages to host your website, the easiest way is to create a project named
githubusername.github.io
Version control the Jekyll folder by typing:
git init
. The folder is now a git repository: all contents are now tracked by git (except what is listed in the .gitignore file)You can now either create completely new layouts, or install a Jekyll theme. They are available via multiple websites, read all about themes here. For example, for the theme minimal mistakes, see the installation steps here and a preview here
Edit your files, see Step 3
add
(stage) andcommit
your changes (basic instructions here)Finally,
push
your changes to GitHub (instructions)
B) Copy a repository of an existing theme to your GitHub account
Choose a theme for your Jekyll website. They are available via multiple websites, read all about themes here.
Once you have chosen a theme,
fork
(i.e., copy) the repository belonging to that theme to your personal GitHub account.In the repository settings, change the repository name to
githubusername.github.io
Now in order to work on your website on your local PC,
clone
the repository to your PCMove to the folder location where you want to clone your repository to:
cd /my/folder
- Note: if you use Ubuntu on Windows, it took me some time to figure out how to move through folders. My C drive was for example reachable through
cd /mnt/c/Users/dorie/
- Note 2: Use the
TAB
key to autofill commands!
- Note: if you use Ubuntu on Windows, it took me some time to figure out how to move through folders. My C drive was for example reachable through
Clone the repository to that location:
git clone https://github.com/username/username.github.io.git
Step 3: Customizing your website
It will probably take some time to get used to the way a Jekyll website is built, especially if you want to change more structural parts of it. In the latter case, some html knowledge would be useful, but I can assure you that Google is your best friend in this case (as it was for me)!
Standard folders in a Jekyll website can be found here. Here’s some introductory tips how to personalize your website.
General steps during customization
Make sure to move into the folder of the repository:
cd githubusername.github.io
Make sure you are working on the correct branch:
git checkout [branchname]
(e.g.,master
)To see your changes locally, run
bundle exec jekyll serve
and open the URL that Jekyll provides in a browser, probably something likehttp://127.0.0.1:4000/
If you are happy with your change, stage the change:
git add [filename]
orgit all -A .
(if you want to stage ALL changes made)Commit your staged files:
git commit -m "Edit x"
Push your changes to your fork (online repository):
git push origin [branch name]
Editing pages and blogposts
Open the markdown (.md) files of the pages you want to edit - these may or may not be located in a
pages
folder (note that theindex.md
files is always the homepage.If you want to create a blog post, create a new .md files in the
_posts
folder. Or if you don’t want to publish your post yet, in the_drafts
folder.Use Atom, Typora or any other markdown editor (cheat sheet) to edit the pages
In order for your pages and posts to display correctly, be sure to include correct
front matter
in each page file (more info here)
Editing the structure of the website
The structure of your website is determined largely by the following files:
_config.yml
contains all your website’s configuration details. You may want to set yourtitle: “your website’s title”
,slogan: “your slogan here”
,description: “site description here
and other detailsThe
_data
folder may include anavigation.yml
file (or something similar) that defines the navigation menu on your website. It may also contain other data files that you can personalize, depending on the theme you are using. And of course you can create new ones to be used in pages throughsite.data.*nameOfDatafile*
If you keep including the same component on several pages, you can create
includes
. These are files that can be included on multiple pages without having to edit that component multiple times. Includes are therefore a way to make your website more modular, flexible and efficient as they prevent creating enormous page files.
Note on .yml
files: .yml
files are terribly precise and give an error if you type even an extra space. Use a yaml validator (like this one to check where your .yml error is!
Editing the looks of your website
The
_layouts
folder contains html files with layouts in which content is wrapped. If you change anything in these layouts, all pages using that layout are changed accordinglyLayouts can also include files from the
_includes
folder, e.g., asidebar.html
orfooter.html
. Again, this increases the modularity and efficiency of your website, since all those components are specified separatelyIf you want to change colors, fonts, etc., you should go to the
_sass
folder. This usually contains some.scss
files (a more modern version of the.css
file) which specify all this.
Step 4: Publishing your website
If you are happy with your website,
push
all changes to the branch of your GitHub repository that you want to publishGo to the settings of your GitHub repository
Scroll down to “GitHub Pages”
Select the branch that you want published on GitHub Pages
If you want, use a custom domain for your website (instead of
username.github.io
)Wait a few minutes and tadaa! Your website is published.
Good luck and have fun! Any questions are welcome.