Build Your Personal Websites with Jekyll & GitHub Pages- 11 mins
Having a personal website is a trend these days. It also becomes an important tool if you belong to a profession that requires a showcase for your portfolio items e.g Designer, Developer, Artist etc. Even if you are not one of them, you might still want to spread your ideas through a personal blog. However, most of us never bother trying to get one. Mainly due to one of the following reasons:
- Hosting cost a few bucks and paying for a ‘not-so-necessary’ thing might feel like an overkill to you.
- Or may be, you don’t know how to build a website (and don’t want to pay someone for it).
- Getting Started with GitHub Pages
- Setting Up Your Blog/Website
- (Optional) Configuring Jekyll For Local Testing
- (Optional) Redirect Your Custom Domain To Your Jekyll Site
Getting Started with GitHub Pages
GitHub is a web-based Git repository hosting service. It offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. After it’s launch in April 2008, the company continued to make improvements to the existing service as well as introducing new features. GitHub Pages is one of those additions.
What is GitHub Pages
GitHub Pages is designed to host your personal, organization, or project pages directly from a GitHub repository. In order to get started with GitHub Pages, you’ll need to set up a GitHub repository. This is where your content will reside and be served from.
Setting up a GitHub Repository
Let’s start by creating a new GitHub repository. If you already have a GitHub account, skip to step 4:
- First, create a free GitHub account.
- Make sure you pick a proper username (even better if you could find your own name available).
- Download and install GitHub desktop, especially if you are not comfortable working with CLI.
- Now that you have your GitHub account set up. Go to your GitHub account and create a new repository and name it in this format: yourusername.github.io.
- Next, create a copy of your empty repository in your local GitHub repositories folder. To do this:
- If you are using GitHub desktop, click the Set up in Desktop button on your repository page.
- or if you are using CLI, navigate to the folder where you want to store your project, and clone the new repository:
- Go to the folder where you have stored your project and create a new file index.html.
- Open the file in text editor of your choice and paste the following
HTMLin it, this is just to indicate that our site is working expectedly.
- Finally, commit and push changes by:
- If you are using GitHub Desktop, first write a message in summary field and press Commit To Master and then pressing the Sync button.
- Or if you are on CLI, use the following commands
- Once the changes have been pushed, type in the url yourusername.github.io in your browser and you should see your page.
Congratulations! You’ve successfully created your website, now is the time give it a pleasing look and feel.
Setting Up Your Blog/Website
Now that your site basic website is up and running, it’s time to make it look like an actual website with the help of Jekyll.
What is Jekyll
At this point you might be wondering
'so what is Jekyll anyway?'. It is an awesome blog-aware website generator that is designed for building minimal, static sites to be hosted on GitHub Pages. I recently migrated my personal site from Wordpress to Jekyll and got to admit that I’m loving it.
So how does Jekyll differs from Wordpress?
Firstly, if you have used Wordpress, you can tell that it has it’s flaws, plus it’s sort of an overkill if you want to put only simple static content. Also, it has been a hot target for hackers in recent years.
Oh! and did I tell you that it’s waaaay faster than Wordpress?
Wordpress suffers badly as the load grows on the site. However, Jekyll being static-website-centric, completely ends that problem as static files put very little load on the server.
Another important point for me was Markdown support, if you are like me and hate writing
HTML then Jekyll is your friend. Jekyll supports Markdown out of the box, which is a very simple and intuitive text-to-HTML conversion tool. It allows you to write using an easy-to-read, easy-to-write plain text format, then converts it to structurally valid XHTML (or HTML).
Give Your Site Personal Touch With Themes
Just like Wordpress, Jekyll supports customizable themes. You can find plenty of free themes at JekyllThemes.org, Themes.JekyllRC.org, JekyllThemes.io or at this GitHub repository. Our next step will be to apply a theme to our website and then customize it. So go to these sites, play with demo and pick one that you like.
Once you have found the right theme for your website, download the zip file and extract all of its content to your local repository folder.
If the archive contains a top level folder and has all the files in it. Then exclude the folder and copy all contents from it to your repository containing folder.
Finally, once again commit and push your changes and open your browser to see your newly furnished site in action.
Customizing & Testing Your Website
Jekyll themes come with a _config.yml file which contains all the meta data about the website such as title, description, favicon, author info, pages etc. Edit this file with your data e.g.
Contents of file may differ based on the theme you choose
Once again commit and push your changes and open your browser to see the changes. That’s it! You have your own website up and running totally free of cost. You can continue customizing your theme or learn about writing posts on Jekyll’s official documentation.
(Optional) Configuring Jekyll For Local Testing
At this point, you’re all set to start customizing and publishing your content, but isn’t it tedious to commit and push every time to preview even the slightest of changes?
Confession: I had to push the code over 50 times while customizing my site without knowing there’s an easy way. Make sure you don’t do something as silly as that.
Well good news is that you can set up a local version of your Jekyll GitHub Pages site to test changes to your site locally. It is highly recommended by GitHub to install Jekyll in order to preview your site and troubleshoot failed Jekyll builds.
Installing Bundler for Ruby
- Open Git Bash.
- Check whether you have Ruby 2.1.0 or higher installed:
- If you don’t have Ruby installed, install Ruby 2.1.0 or higher.
- After that, install Bundler:
Installing Jekyll using Bundler
Check to see if you have a Gemfile in your local Jekyll site repository. If you have a Gemfile, skip to step 4.
If you don’t have a Gemfile, open a text editor of your choice, and add these lines to a new file:
Name the file Gemfile and save it to the root directory of your local Jekyll site repository. Skip to step 5 to install Jekyll.
If you already have a Gemfile, open it in a text editor of your choice, and add these lines:
- Finally, install Jekyll and other dependencies from the GitHub Pages gem:
Build your local Jekyll site
- Navigate into the root directory of your local Jekyll site repository.
- Run your Jekyll site locally:
- Preview your local Jekyll site in your web browser at http://localhost:4000.
(Optional) Redirect Your Custom Domain To Your Jekyll Site
If you own a custom domain (say
yourusername.com) then you can redirect this existing domain to your GitHub Pages website so it replaces the yourusername.github.io address with this more personal one.
- First of all create a new file named CNAME (all caps, without any spaces or extension)
- Open this file in a text editor of your choice and add your domain name. e.g.
- Save the file and once again commit and push!
- Next, go to your hosting provider and find the Manage DNS section. Add two records there.
- Add a A record that points to
- Add a CNAME record that points to your GitHub Pages site:
- And that’s it, wait for changes to propagate and you’ll be able to reach your Jekyll site using your custom domain address.