Getting Starting with GitHub Pages

A preliminary guide to sustainable and extensible project websites

What is GitHub Pages?

Why GitHub Pages?

How to use this guide

These instructions explain how a GitHub Pages site works. It describes files and folders in your repository as well as how individual files work. It will be useful to have these instructions open in a separate browser window as you view and edit files on your website.

Build a website in 10 minutes

You now have a working website to build from!

Bookmark your website and repository

There are two web addresses (URLs) that you’ll be using throughout this guide, so let’s get our terminology straight. You might want to bookmark them for easy access—they are similar enough that they are easy to mix up.

Replace USERNAME with your GitHub username, and REPOSITORY with the name of the repository into which you copied the Jekylton site (which you might have kept as jekylton). For example, the Jekylton repository is at: https://github.com/fredgibbs/jekylton.


Anatomy of a Page

To understand the basics of how pages work, let’s investigate the index.md file. Go to your repository (not website), and click on the link for the index.md file to view its contents.

YAML headers

The top of the page looks like:

---
title: Getting Started
layout: base
date: 2019-10-03
---

All pages must have a similar metadata block at the very top, with the title customized for each page. This is called a YAML header. For now, it is enough to know that this block of metadata tells GitHub Pages that it should be part of your website. Be sure you have the 3 hyphens --- before and after your metadata on their own lines.

The index page uses the base layout, as do all pages except the directory page; layouts will be discussed in the next section.

You’ll notice that you have a few sample pages in the root directory of your repository, like credits and directory. They work the same way.

Markdown

One of the great features of GitHub Pages is that it allows you to write pages in Markdown rather than HTML.

«comparison»

If you are new to Markdown, complete this Markdown tutorial. If you need syntax help, check out this cheat sheet.

Previewing Markdown

If you want to write online and preview your Markdown text as you write, use Dillinger. It saves your work as you go. When you are done writing, you can simply copy and paste your text from Dillinger into the edit window on GitHub.


Basic Site Components

Now that we’ve looked at a page, let’s see what else is in the repository. Go to your own Jeklyton repository at http://USERNAME.github.io/jekylton (again, replacing USERNAME with your GitHub username). All of the files are important in their own way, but we’re going to focus on the folders and files that most directly create our website.

_includes directory

This directory hold files that are typically small bits of code that appear on more than one page, like a nav bar or footer. This way, if you want to change the footer on all your site pages, you can change it in just one spot.

_layouts directory

This directory provides the basic layouts for different kinds of pages. We want all our pages to have well-formed HTML, which means they need to start with <!DOCTYPE html>. So you see that’s the first line of code on the

These pages will include bits of code from the _includes directory to assemble a complete webpage.

essays directory

This directory could be named anything–it’s just a place to put separate essays. You might have many of these directories for essays on different topics, like ads, newspapers, historic sites, campus buildings, etc.


Editing your site

Edit your homepage

Add a new page


Edit the top nav bar

Edit the base template

Jekyll uses layouts and includes to reuse common components across your site You’ll notice in the YAML header for the index page, there is a line layout: base Let’s look at the base template, which of course is in the templates directory

This is the template for all your pages. Once you’re more comfortable with templates, you can write your own, or find someone else’s and modify it.

Including Images

Images instructions are on their own page.

Other typographic features

Look in the _includes folder and you’ll see a number of code snippets. These are all small chunks of code of HTML and the special language that Jekyll uses to help make pages more flexible. These make it easy to embed other things on your pages, like videos and pull quotes. They work the same way as do including images, although the parameters you’ll set in the code snippets are naturally a little different.

All the include files that you might want to use are explained on the code examples page.


Testing your site locally (without GitHub pages)

Waiting for your changes to show up on the live, public website can be annoying, to say the least. It works fine for small, infrequent updates, but any kind of testing or experimentation requires you to run your website on your computer. In other words, to run it locally (as opposed to remotely on the GitHub servers).

There are a number of independent software applications that work together. They all do one thing very well, which makes installation a bit more work than just having everything bundled together, but it also makes everything work more effectively in the long run. You don’t need to understand how all these work, and once they are installed you don’t need to think about them very much.

These instructions outline exactly what to do. It looks like a lot of steps, but they are all simple and go quickly.

Using the Command Line

Mac

These instructions are based on these xcode-select --install

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" A program called Homebrew helps us install some required software very easily.

To tie your website to your GitHub website, we’ll need the application that helps run GitHub, called git. Install Git: https://git-scm.com/download/mac.

Windows

These instructions are based on these