Replace hand-rolled site generator with Zola

This commit is contained in:
kayomn 2023-08-19 15:22:59 +01:00
parent db94c8e225
commit 0c3fe4ba6b
16 changed files with 115 additions and 155 deletions

6
.gitignore vendored
View File

@ -1,5 +1 @@
output/
bin/
lib/
lib64
pyvenv.cfg
public/

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"editor.insertSpaces": false
}

11
config.toml Normal file
View File

@ -0,0 +1,11 @@
base_url = "https://pizzawednes.day"
title = "Pizza Wednesday"
# Features
compile_sass = false
build_search_index = true
[markdown]
highlight_code = true
[extra]

3
content/_index.md Normal file
View File

@ -0,0 +1,3 @@
+++
title = "Hello world"
+++

5
content/feed/_index.md Normal file
View File

@ -0,0 +1,5 @@
+++
title = "Feed"
generate_feed = true
template = "feed.html"
+++

View File

@ -1,3 +1,8 @@
+++
title = "hello world"
date = 2023-08-16
+++
# Hello, World
This is a test of the new announcement feed system.

View File

@ -1,84 +0,0 @@
import datetime
import jinja2
import markdown
import os
import strip_markdown
import typing
class Post(typing.NamedTuple):
title: str
path: str
pub_date: datetime.datetime
base_url = "https://pizzawednes.day/"
cwd_path = os.getcwd()
output_path = os.path.join(cwd_path, "output")
if not os.path.exists(output_path):
os.mkdir(output_path)
feed_path = os.path.join(output_path, "feed")
if not os.path.exists(feed_path):
os.mkdir(feed_path)
jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.join(cwd_path, "templates")))
posts_path = os.path.join(cwd_path, "posts")
post_template = jinja_env.get_template("site_post.html")
datetime_format_len = 10
markdown_extension = ".md"
posts: list[Post] = []
for filename in os.listdir(posts_path):
if not filename.endswith(markdown_extension):
continue
if len(filename) < datetime_format_len:
continue
pub_date = datetime.datetime.min
try:
pub_date = datetime.datetime.strptime(filename[0:datetime_format_len], "%Y-%m-%d").replace(
hour=0,
minute=0,
second=0,
microsecond=0,
)
except ValueError:
pass
with open(os.path.join(posts_path, filename)) as source_file:
content = source_file.read()
title = ""
try:
first_newline_index = content.index('\n')
title = strip_markdown.strip_markdown(content[0:first_newline_index])
except ValueError:
pass
slug = filename[:-len(markdown_extension)]
posts.append(Post(
title=title,
path=os.path.join("feed", slug),
pub_date=pub_date,
))
with open(f"{os.path.join(feed_path, slug)}.html", "w") as output_file:
output_file.write(post_template.render(
title = title,
content = markdown.markdown(content),
))
with open(f"{feed_path}.rss", "w") as file:
file.write(jinja_env.get_template("rss_feed.rss").render(
base_url = base_url,
posts = posts,
))
with open(f"{feed_path}.html", "w") as file:
file.write(jinja_env.get_template("site_feed.html").render(
posts = posts,
))

View File

@ -1,17 +1,15 @@
# Pizza Wednesday Site
This repo contains the scripts, templates, and blog posts necessary to build the Pizza Wednesday landing site from scratch.
This repo contains the templates, assets, and blog posts necessary to build the Pizza Wednesday landing site.
While only intended to be used by contributors for publishing new articles and changes to the website, the source files are publicly viewable for transparency and posterity.
While only intended to be used by contributors for publishing new articles and changes to the website, the source files are publicly viewable for posterity.
## Building
The website uses the [Zola static site generator](https://www.getzola.org/) for building. Though it is available in most package managers across the various Unix-like systems, the project maintainers also provide pre-built binaries on their [Github relases page](https://github.com/getzola/zola/releases).
Once installed, executing the `zola build` terminal command from within the repository root builds the website. Alternatively, `zola serve` launches a live testing server with hot-reloading of changes for local development.
## Publishing
Being a python script that is doing somewhat non-trivial stuff, `publish.py` will require some non-standard dependencies to run properly.
* `markdown` for parsing the markdown source files into HTML.
* `strip_markdown` for converting markdown source file content into plain text.
* `jinja2` for template generation of the site contents. Without tools like it, creating static websites is a fairly miserable experience
And of course a Python interpreter will be required - specifically any compatible with CPython libraries like the ones listed above.
Once these dependencies are satisifed, generating the website should be as simple as running `publish.py`. If it does fail to run at this point, please file a bug report.
Any changes merged into the main branch of the Sauce Control repository are published to the live server.

31
templates/base.html Normal file
View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{% block title %}{{ config.title }}{% endblock %}</title>
{% block links %}
{% endblock %}
</head>
<body>
<header>
<a href="/"><div>Pizza Wednesday</div></a>
<nav>
<a href="/feed">Feed</a>
<a href="https://sauce.pizzawednes.day">Sauce Control</a>
</nav>
</header>
<main>
{% block content %}{% endblock %}
</main>
<footer>
Copyright sucks ass
</footer>
</body>
</html>

20
templates/feed.html Normal file
View File

@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block links %}
<link rel="alternate" type="application/rss+xml" title="RSS" href="{{ get_url(path="rss.xml", trailing_slash=false) }}">
{% endblock %}
{% block content %}
<h1>Feed</h1>
{% for page in section.pages %}
<a href="{{ page.permalink }}">
<div>
<h2>{{ page.title }}</h2>
<div>{{ page.date }}</div>
<p>{{ page.content | striptags | truncate(length=255) }}</p>
</div>
</a>
{% endfor %}
{% endblock %}

20
templates/index.html Normal file
View File

@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block content %}
{{ section.content | safe }}
<h1>Latest</h1>
{% set feed_section = get_section(path="feed/_index.md") %}
{% for page in feed_section.pages %}
<a href="{{ page.permalink }}">
<div>
<h2>{{ page.title }}</h2>
<div>{{ page.date }}</div>
<p>{{ page.content | striptags | truncate(length=255) }}</p>
</div>
</a>
{% endfor %}
{% endblock %}

5
templates/page.html Normal file
View File

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block content %}
{{ page.content | safe }}
{% endblock %}

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Pizza Wednesday Feed</title>
<link>{{ base_url }}</link>
<description>Announcements regarding pizzawednes.day and related services</description>
{% for post in posts %}
<item>
<title>{{ post.title }}</title>
<link>{{ base_url }}{{ post.path }}</link>
<pubDate>{{ post.pub_date.strftime('%a, %d %b %Y %H:%M:%S %z') }}</pubDate>
</item>
{% endfor %}
</channel>
</rss>

View File

@ -1,19 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}Pizza Wednesday{% endblock %}</title>
</head>
<body>
<div>Pizza Wednesday</div>
<nav>
<a href="/feed">Feed</a>
</nav>
<main>
{% block content %}{% endblock %}
</main>
</body>
</html>

View File

@ -1,13 +0,0 @@
{% extends "site_base.html" %}
{% block title %}Pizza Wednesday Feed{% endblock %}
{% block content %}
{% for post in posts %}
<div>
<div>{{ post.title }}</div>
<div>{{ base_url }}{{ post.path }}</div>
<div>{{ post.pub_date.strftime('%a, %d %b %Y %H:%M:%S %z') }}</div>
</div>
{% endfor %}
{% endblock %}

View File

@ -1,7 +0,0 @@
{% extends "site_base.html" %}
{% block title %}{{ title }} - Pizza Wednesday Feed{% endblock %}
{% block content %}
{{ content }}
{% endblock %}