GitHub Pages Code Snippets

07 Feb 2020

Snippet 1: index.html

<!DOCTYPE html>
<html>
	<head>
		<title>NAME, Web Developer</title>
	</head>
	<body>
		<nav>
    		<ul>
        		<li><a href="/">Home</a></li>
	        	<li><a href="/about">About</a></li>
        		<li><a href="/cv">CV</a></li>
        		<li><a href="/blog">Blog</a></li>
    		</ul>
		</nav>
		<div class="container">
    		<div class="blurb">
        		<h1>Hi there, I'm NAME!</h1>
				<p>Here's a blurb about me and my site!</p>
    		</div><!-- /.blurb -->
		</div><!-- /.container -->
		<footer>
    		<ul>
        		<li><a href="mailto:your-email@gmail.com">email</a></li>
        		<li><a href="https://github.com/NAME">github.com/NAME</a></li>
			</ul>
		</footer>
	</body>
</html>

Snippet 2: css/main.css

body {
    margin: 60px auto;
    width: 70%;
}
nav ul, footer ul {
    font-family:'Helvetica', 'Arial', 'Sans-Serif';
    padding: 0px;
    list-style: none;
    font-weight: bold;
}
nav ul li, footer ul li {
    display: inline;
    margin-right: 20px;
}
a {
    text-decoration: none;
    color: #999;
}
a:hover {
    text-decoration: underline;
}
h1 {
    font-size: 3em;
    font-family:'Helvetica', 'Arial', 'Sans-Serif';
}
p {
    font-size: 1.5em;
    line-height: 1.4em;
    color: #333;
}
footer {
    border-top: 1px solid #d5d5d5;
    font-size: .8em;
}

ul.posts { 
    margin: 20px auto 40px; 
    font-size: 1.5em;
}

ul.posts li {
    list-style: none;
}

Snippet 3: _layouts/default.html

<!DOCTYPE html>
	<html>
		<head>
			<title>{{ page.title }}</title>
			<!-- link to main stylesheet -->
			<link rel="stylesheet" type="text/css" href="/css/main.css">
		</head>
		<body>
			<nav>
	    		<ul>
	        		<li><a href="/">Home</a></li>
		        	<li><a href="/about">About</a></li>
	        		<li><a href="/cv">CV</a></li>
	        		<li><a href="/blog">Blog</a></li>
	    		</ul>
			</nav>
			<div class="container">
			
			{{ content }}
			
			</div><!-- /.container -->
			<footer>
	    		<ul>
	        		<li><a href="mailto:your-email@gmail.com">email</a></li>
	        		<li><a href="https://github.com/NAME">github.com/NAME</a></li>
				</ul>
			</footer>
		</body>
	</html>

Snippet 4: New index.html

---
layout: default
title: "NAME, Web Developer"
---
<div class="blurb">
	<h1>Hi there, I'm NAME!</h1>
	<p>Here's a blurb about me and my site!</p>
</div><!-- /.blurb -->

Snippet 5: _layouts/post.html

---
layout: default
---
<h1>{{ page.title }}</h1>
<p class="meta">{{ page.date | date_to_string }}</p>

<div class="post">
  {{ content }}
</div>

Snippet 6: _posts/2019-02-22-my-site-launched.md

---
layout: post
title: "NAME, Web Developer, launches site"
date: 2019-02-22
---

Here is my GitHub Pages website! It's powered by [Jekyll](http://jekyllrb.com) and I can use Markdown to author my posts. It actually is a lot easier than I thought it was going to be.

Snippet 7: blog/index.html

---
layout: default
title: "NAME's Blog"
---
	<h1>{{ page.title }}</h1>
	<ul class="posts">

	  {% for post in site.posts %}
	    <li><span>{{ post.date | date_to_string }}</span> » <a href="{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></li>
	  {% endfor %}
	</ul>

Snippet 8: blog/atom.xml

---
layout: feed
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

	<title>NAME's Blog</title>
	<link href="http://NAME.github.io/blog/atom.xml" rel="self"/>
	<link href="http://NAME.github.io/blog"/>
	<updated>{{ site.time | date_to_xmlschema }}</updated>
	<id>http://NAME.github.io/blog</id>
	<author>
		<name>NAME</name>
		<email>your-email@gmail.com</email>
	</author>

	{% for post in site.posts %}
		<entry>
			<title>{{ post.title }}</title>
			<link href="http://NAME.github.io{{ post.url }}"/>
			<updated>{{ post.date | date_to_xmlschema }}</updated>
			<id>http://NAME.github.io{{ post.id }}</id>
			<content type="html">{{ post.content | xml_escape }}</content>
		</entry>
	{% endfor %}

</feed>

A helpful resource on all things GitHub