How to add a Jekyll blog to an existing github pages website
I wrote this blog at the Open Science Retreat. Thanks to the organizers for giving me the time and inspiration to finally get this done!
Yesterday I added a blog to my website, because I wanted to write a blog post. I couldn’t find clear instructions for doing this, and I ended up going down several dead ends, so here’s what worked for me.
I already had a website, which was very simple (pretty much just a single html page), but I recently started wanting to write a blog. I’d previously written some things on Medium, but I wanted to move away from using a third party, and I figured “how hard could it be to make one on my website?”. Spoiler: it took some faffing.
Jekyll seemed like a sensible option, so without much further thought I dove in.
jekyll new --skip-bundle --force .(
--forceis needed because jekyll expects an empty repo)
- Opening the Gemfile in a text editor (I used Notepad++)
- Comment out line 10
# gem "jekyll", "~> 4.3.2"in the Gemfile
- Modify line 15 to
gem "github-pages", "~> 228", group: :jekyll_plugins(checking the version here)
- Comment out line 10
- Modify the config file. For me the important part was:
Then to test my site locally I continued with these instructions and ran:
bundle exec jekyll serve. At first it threw an error (
cannot load such file -- webrick) which I resolved with
bundle add webrick (info here), and then it worked!
Well, it sort of worked, in that it showed my original site, and if I went to
http://127.0.0.1:4000/blog/ it showed a 404…
To tell Jekyll that I wanted to keep my original home page, and that I wanted to have the blog at
dannygarside.co.uk/blog I did the following:
- added this line to the config file:
permalink: /blog/:title/(this also makes it so that the URL for each blog is just the title, rather than the date and title, which I prefer).
- Copied my previous html homepage into a new folder (
_layouts) and renamed it
blog.htmlto my root directory. I honestly don’t remember where from, somewhere near here I think…
And that was all the heavy lifting done! 🎉
I then did a couple of snazzy extra things like:
This post is published under a CC BY 2.0 licence.