Initial commit

Noah 5 years ago
commit 41c80533cd
  1. 3
  2. 13
  3. 3
  4. 142
  5. BIN
  6. 28
  7. 41
  8. 25
  9. 100
  10. 14

.gitignore vendored

@ -0,0 +1,3 @@

@ -0,0 +1,13 @@
all: build
@PHONY: build
@PHONY: watch
@PHONY: clean
rm -rf public

@ -0,0 +1,3 @@
all: build

@ -0,0 +1,142 @@
#!/usr/bin/env python3
import codecs
import logging
import os
from shutil import copyfile
import jinja2
log = logging.getLogger("build")
class App(object):
# Global template variables.
def vars(self):
return {
"site": {
"name": "",
def __init__(self):
# Jinja environment.
self.env = jinja2.Environment(
# Collect all the templates and all the static files.
self.templates = self.crawl("./templates") # TODO: remove list() wrapper
self.static = self.crawl("./static")
# Copy all of the static files into the public root.
if not os.path.isdir("./public"):
for static in self.static:
public = static.replace("./static/", "./public/")
self.mkdir(public.rsplit("/", 1)[0]) # ensure the path will exist
if self.should_copy_static(static, public):"COPY STATIC FILE %s -> %s", static, public)
copyfile(static, public)
# And render all of the templates.
for template in self.templates:
if template.startswith("./templates/layout"): # don't create these
public = self.template_to_public(template)
self.mkdir(public.rsplit("/", 1)[0]) # ensure the path will exist"RENDER TEMPLATE: %s -> %s", template, public)
self.render_template(template, public)
def render_template(self, template, public):
Render a template to the public path.
template (str): path in ./templates
public (str): path in ./public
tpl = self.env.get_template(template.replace("./templates/", ""))
html = tpl.render(self.vars())
with, "w", "utf-8") as fh:
def crawl(self, path):
Crawl a directory recursively and return a list of file paths.
path (str)
filepaths (list[str])
for root, dirs, files in os.walk(path):
for file in files:
yield os.path.join(root, file)
def should_copy_static(self, static_file, public_file):
Determine if a static file should be copied over to the public folder.
This means the public file either does not exist yet, or is older
than the static file and so the new static file should be copied over it.
static_file (str)
public_file (str)
bool: True if public_file doesn't exist or is older than static_file.
if not os.path.exists(public_file):
return True
return os.stat(static_file).st_mtime > os.stat(public_file).st_mtime
def template_to_public(self, template_filename):
Convert a template filename into a public name, preferring clean URL
paths without file extension suffixes.
* /index.html -> /index.html
* /about.html -> /about/index.html
* /photos/index.html -> /photos/index.html
* /photos/2018.html -> /photos/2018/index.html
The `.html` and `.md` file types will suppress suffixes in this way.
template_filename: like ``./templates/about.html``
public_filename: like ``./public/about/index.html``
public = template_filename.replace("./templates/", "./public/")
path, filename = public.rsplit("/", 1)
basename, ext = filename.rsplit(".", 1)
if ext not in ["html", "md"]:
# Not a web page so just keep the path literal.
return public
print("template_to_public:", template_filename, public)
# See if it's already an index page or if we need to create one.
if filename in ["index.html", ""]:
return public # already a good name
print("HERE:", os.path.join(path, basename, "index."+ext))"basename=%r path=%r filename=%s", basename, path, filename)
return os.path.join(path, basename, "index."+ext)
def mkdir(self, path):
"""Create a directory and log it."""
if not os.path.isdir(path):"mkdir: %s", path)
os.makedirs(path, mode=0o755)
if __name__ == "__main__":

Binary file not shown.


Width:  |  Height:  |  Size: 117 KiB

@ -0,0 +1,28 @@
{% extends "layout/base.html" %}
{% block title %}Contact Me{% endblock %}
{% block content %}
<section class="first">
<h1>Contact Me</h1>
Below are some places you can find me on the Internet and ways you can
contact me.
<td align="right">Email:</td>
<a href="">Send me an e-mail here</a>
<h2>External Links</h2>
<li><a href=""></a>, my web blog.</a></li>
<li><a href="">GitHub</a></li>
{% endblock %}

@ -0,0 +1,41 @@
{% extends "layout/base.html" %}
{% block title %}Welcome{% endblock %}
{% block content %}
<section class="first">
<img src="/images/photo.jpg" class="circle center" width="320">
<h1>Hello world!</h1>
This is the personal homepage of <strong>Noah Petherbridge</strong>.
I'm a software developer in California. I write about random stuff on
my <a href="" target="_blank">web blog</a> and
maintain a handful of open source projects on
<a href="" target="_blank">GitHub</a>
and <a href="" target="_blank"></a>.
<h2>Software Development</h2>
I'm a full stack web developer and I program in Go, Python, and
JavaScript. One of my largest personal projects is
<a href="" target="_blank">RiveScript</a>,
a scripting language for programming chat bots &mdash; matching a user's
message to a certain response.
My web blog, <a href="" target="_blank"></a>,
is written in Go and I keep that source code <a href="" target="_blank">here</a>
for now. Previously it was written in
<a href="" target="_blank">Python</a>
and its <a href="" target="_blank">HTML pages</a>
are readable too. The site you're reading is a simple Python-generated
static site <a href="">here</a>.
{% endblock %}

@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>{% block title %}Untitled{% endblock %} - {{ }}</title>
<link rel="stylesheet" type="text/css" href="/theme/style.css">
<li><a href="/">Home</a></li>
<li><a href="/contact">Contact</a></li>
<h1><a href="/">{{ }}</a></h1>
{% block content %}{% endblock %}

@ -0,0 +1,100 @@
html, body {
height: 100%;
margin: 0;
body {
background-color: #0099FF;
font-family: Arial, Helvetica, sans-serif;
font-size: medium;
line-height: 1.6rem;
color: #222;
margin: 0 auto;
max-width: 950px;
a:link, a:visited {
color: #006699;
a:hover, a:active {
color: #0099FF;
h1 {
font-size: 24pt;
h2 {
font-size: 14pt;
img {
max-width: 100%;
height: auto;
} {
border-radius: 50%;
header {
position: fixed;
top: 0;
left: 0;
right: 0;
line-height: 3rem;
background-color: rgba(255, 153, 255, 0.8);
box-shadow: 0px 2px 2px #000;
header h1 {
margin: 0;
font-size: larger;
font-style: italic;
header nav {
max-width: 860px;
margin: 0 auto;
padding: 0 2rem;
font-size: large;
header nav ul {
list-style: none;
float: right;
margin: 0;
header nav ul li {
display: inline;
padding-left: 8px;
header nav a {
color: #000 !important;
font-weight: bold;
text-decoration: none;
main {
min-height: 100%;
margin: 0 24px;
background-color: #FFF;
box-shadow: 0px 0px 4px #000;
section {
padding: 2rem;
section.first {
padding-top: 4rem;
footer {
max-width: 860px;
padding: 0 4rem;
margin: 2rem auto;
color: #036;
font-weight: bold;
text-align: center;
font-style: italic;
.center {
display: block;
text-align: center;
margin-left: auto;
margin-right: auto;

@ -0,0 +1,14 @@
function die() {
echo >&2 $1
exit 1
# Before we crash and burn, make sure necessary programs are installed!
command -v inotifywait || die "I need the inotifywait command (apt install inotify-tools)"
while inotifywait -r -e modify,move,create,delete static templates; do