How to Create a Multi-page Website using Github Pages
To Create the Template
- Create the page normally following pages.github.com, but use
CONTENTas the content of the page - Choose a theme and publish the page
- Fetch and checkout the gh-pages branch on your local repository
- Create a directory
_layoutsin the repository - Rename
index.htmltotemplate.htmland move it into the_layoutsdirectory - Open
template.htmland replace the<p>CONTENT</p>placeholder with{{ content }}(this is Jekyll syntax to grab the content from the MarkDown pages you will create) - Identify the navigation/button section of HTML
- Copy one navigation/button item (probably a
<a href="">or similar tag) - Insert this code at the top of the navigation/button item section:
{% for page in site.pages %}
<a href={{ page.filename }}>{{ page.title }}</a>
{% endfor %}
To match your theme, paste the copied navigation/button item in place of <a href=howto>How To</a>, but use howto for the href and How To for the content (as shown in the example in step 9)
To Create Your First Page
- Make a new file called
index.mdin your repository - Copy the content of your
readme.mdor write a new home page in MarkDown into this file - At the top of this file, add the following:
---
title: PAGE TITLE HERE
layout: template
filename: NAME OF THIS .md FILE HERE
---
Commit your changes and push them to the gh-pages branch
Now, when you go to YOURGITHUBNAME.github.io/YOURPROJECTNAME, you should see the contents of your index.md formatted with the theme that you chose.
To Create Additional Pages
- Make a new file called
PAGENAME.mdin your repository (where PAGENAME is the name of your new page) - Write the content for this new page in MarkDown
- At the top of this file, add the following:
---
title: PAGE TITLE HERE
layout: template
filename: NAME OF THIS .md FILE HERE
---
Commit your changes and push them to the gh-pages branch
Now, when you go to YOURGITHUBNAME.github.io/YOURPROJECTNAME, you should see a link to your new page. When you click this link, you should see your new page formatted with the theme that you chose.