I recently migrated my blog to GitHub Pages using an awesome open source project Jekyll. It’s really fun blogging with Jekyll. If you are not enjoying blogging with other CMS platform then you should really try Jekyll.
After reading a lot of documentation, I found following quickest way to set up a Jekyll powered blog on GitHub Pages:
Jekyll’s simple purpose
Tom Preston-Werner created Jekyll to enable people to blog using a simple static HTML website, with all of the content hosted and version-controlled on GitHub. The goal was to eliminate the complexity of other blogging platforms by creating a workflow that allows you to blog like a hacker.
Jekyll takes your content written in Markdown, passes it through your templates and spits it out as a complete static website, ready to be served. GitHub Pages conveniently serves the website directly from your GitHub repository so that you don’t have to deal with any hosting.
So what is Jekyll, exactly?
According to Jekyll wiki,
Jekyll is a simple, blog-aware, static site generator. It takes a template directory containing raw text files in various formats, runs it through Markdown (or Textile) and Liquid converters, and spits out a complete, ready-to-publish static website suitable for serving with your favorite web server. Jekyll also happens to be the engine behind GitHub Pages, which means you can use Jekyll to host your project’s page, blog, or website from GitHub’s servers for free.
GitHub Pages uses the following dependencies:
- jekyll, jekyll-sass-converter, kramdown, jekyll-commonmark-ghpages, liquid, rouge, github-pages-health-check, jekyll-redirect-from, jekyll-sitemap, jekyll-feed, jekyll-gist, jekyll-paginate, jekyll-coffeescript, jekyll-seo-tag, jekyll-github-metadata, jekyll-avatar, jekyll-remote-theme, jemoji, jekyll-mentions, jekyll-relative-links, jekyll-optional-front-matter, jekyll-readme-index, jekyll-default-layout, jekyll-titles-from-headings, listen, activesupport, minima, jekyll-swiss, jekyll-theme-primer, jekyll-theme-architect, jekyll-theme-cayman, jekyll-theme-dinky, jekyll-theme-hacker, jekyll-theme-leap-day, jekyll-theme-merlot, jekyll-theme-midnight, jekyll-theme-minimal, jekyll-theme-modernist, jekyll-theme-slate, jekyll-theme-tactile, jekyll-theme-time-machine, ruby, github-pages, html-pipeline, sass, safe_yaml, nokogiri
Who are using Jekyll?
Here are some websites/blog that were created with Jekyll:
- Jekyll - itself and most of the GitHub’s subpages
- HealthCare.gov - landing page and content subpages
- Font Awesome
- Mark Dotto
- Zach Holman
- Todd Motto
… and many other awesome projects and blogs are using Jekyll and hosted on GitHub Pages.
There are various ways to get started with Jekyll.
Install Jekyll locally via the command line, create a new boilerplate website using
jekyll new, build it locally with
jekyll build, and then serve it just make sure you’ve Ruby installed on your machine (further information visit Jekyll docs).
Or, here’re the simple steps to blog with Jekyll on GitHub Pages without touching the single command line:
Make GitHub account and create repo
username.github.io, remember your repo username must be match with GitHub account username.
Download and install GitHub Desktop app (Currently available for Mac and Windows)
Download and setup a good themes from the following popular sites:
- Jekyll Themes Wiki
- Jekyll Themes - a Jekyll theme collection site
- Jekyll Now
- There’re other many theme collection site for Jekyll.
Jekyll directory structure
A basic Jekyll site usually looks something like this:
. ├── CNAME # Contains your custom domain name (optional). ├── _config.yml ├── _drafts # To preview your posts. │ ├── begin-with-the-crazy-ideas.textile │ └── on-simplicity-in-technology.markdown ├── _includes # Snippets of code that can be used throughout your templates. │ ├── footer.html │ └── header.html ├── _layouts │ ├── default.html # The main template. │ └── page.html # Static page layout. │ └── post.html # Blog post layout. ├── _posts # All posts go in this directory! │ ├── 2007-10-29-why-every-programmer-should-play-nethack.markdown │ └── 2009-04-26-barcamp-boston-4-roundup.textile ├── _data │ └── members.yml ├── _site # After Jekyll builds the website, it puts the static HTML output here. This is what's served! │ ├── CNAME │ ├── about.html │ └── feed.xml │ ├── index.html │ └── sitemap.xml │ └── style.css ├─ .jekyll-metadata ├─ about.md # A static "About" page that I created. ├─ feed.xml # Powers the Atom/RSS feed. ├─ images # All of your images are stored here. │ ├── first-post.jpg ├─ index.html # Home page layout. ├─ scss # The Sass style sheets for your website. │ ├─ _highlights.scss │ ├─ _reset.scss │ ├─ _variables.scss │ └─ style.scss └── index.html └── 404.html # Custom 404 page. └── sitemap.xml # Site map for the website.
- With the help of GitHub Desktop app, clone your
username.github.ioand sync/push your theme.
- Congratulation! You are done.
- Now after few minutes (less than 15 min) you’ll see your changes at your
Setting up a custom domain with GitHub Pages
Follow the following process to setup custom domain name with your GitHub Pages.
Configuring an A record with your DNS provider
With your DNS provider, create A records that resolve to the following IP addresses:
Configuring a www subdomain
Again add following CNAME record to your DNS provider:
Note: Do not use wildcard DNS records (e.g.
*.example.com) with GitHub Pages! A wildcard DNS record will allow anyone to host a GitHub Pages site at one of your subdomains.
Create a CNAME file name
Now push a CNAME (with out any extention) file name in your GitHub Pages with your desire redirect:
- If your CNAME file contains
www.example.comwill redirect to
- If your CNAME file contains
example.comwill redirect to
Publish your first blog post
The front matter is where Jekyll starts to get really cool. Any file that contains a YAML front matter block will be processed by Jekyll as a special file. The front matter must be the first thing in the file and must take the form of valid YAML set between triple-dashed lines. Here is a basic example:
--- layout: post title: Blogging Like a Hacker ---
Note: For the proper setup, don’t use
Thanks to Liquid (Jekyll uses the Liquid templating language to process templates) that you can add your desire front matter:
--- layout: title: subtitle: date: author: categories: tags: id: excerpt: permalink: featured_image: ---
Save the file under the format
2014-12-30-blogging-like-a-hacker.md which is in
Now if you set your permalink as
_config.yml then above post will published as
Using Jekyll Plugins with GitHub Pages
GitHub Pages officially supports several Jekyll plugins. Add a list of enabled gems (plugins) to your site’s
_config.yml file, such as:
gems: - jekyll-feed - jekyll-mentions - jekyll-redirect-from - jekyll-sitemap - jemoji
This is simple proccess to blog with Jekyll on GitHub Pages. You can learn more about Jekyll at jekyllrb.com.