[SSG] Move archives, subscribe, donate into directories.

Allow templates to be relative using {{ relative }} which can be set by
caller.
This commit is contained in:
Ceda EI 2020-03-10 21:21:54 +05:30
parent 401e1b64f0
commit 329039541a
4 changed files with 36 additions and 24 deletions

View File

@ -2,6 +2,6 @@
{% block left_content %} {% block left_content %}
<ul class="archives"> <ul class="archives">
{% for episode in episodes %} {% for episode in episodes %}
<li><a href="{{ episode.slug }}">{{ episode.title }}</a></li> <li><a href="../{{ episode.slug }}">{{ episode.title }}</a></li>
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}

View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{% block title %}{{ title }} | Redacted Life{% endblock %}</title> <title>{% block title %}{{ title }} | Redacted Life{% endblock %}</title>
<link href="assets/css/index.css" rel="stylesheet" type="text/css"> <link href="{{ relative }}/assets/css/index.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="assets/plyr/plyr.css" /> <link rel="stylesheet" href="{{ relative }}/assets/plyr/plyr.css" />
<!-- Metadata --> <!-- Metadata -->
<meta name="description" content="An audiocast on Linux and libre software with a hard spin on personal privacy and security"> <meta name="description" content="An audiocast on Linux and libre software with a hard spin on personal privacy and security">
@ -32,26 +32,26 @@
<meta property="og:image" content="/assets/media/cover-site.png" /> <meta property="og:image" content="/assets/media/cover-site.png" />
<!-- Favicons --> <!-- Favicons -->
<link rel="apple-touch-icon" sizes="180x180" href="/assets/favicons/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="180x180" href="{{ relative }}/assets/favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/favicons/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="32x32" href="{{ relative }}/assets/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/favicons/favicon-16x16.png"> <link rel="icon" type="image/png" sizes="16x16" href="{{ relative }}/assets/favicons/favicon-16x16.png">
<link rel="manifest" href="/assets/favicons/site.webmanifest"> <link rel="manifest" href="{{ relative }}/assets/favicons/site.webmanifest">
<link rel="mask-icon" href="/assets/favicons/safari-pinned-tab.svg" color="#46ad83"> <link rel="mask-icon" href="{{ relative }}/assets/favicons/safari-pinned-tab.svg" color="#46ad83">
<link rel="shortcut icon" href="/assets/favicons/favicon.ico"> <link rel="shortcut icon" href="{{ relative }}/assets/favicons/favicon.ico">
<meta name="msapplication-TileColor" content="#2b5797"> <meta name="msapplication-TileColor" content="#2b5797">
<meta name="msapplication-config" content="/assets/favicons/browserconfig.xml"> <meta name="msapplication-config" content="{{ relative }}/assets/favicons/browserconfig.xml">
<meta name="theme-color" content="#ffffff"> <meta name="theme-color" content="#ffffff">
</head> </head>
<body> <body>
<img src="assets/images/cloud.svg" class="clouds" id="cloud1" /> <img src="{{ relative }}/assets/images/cloud.svg" class="clouds" id="cloud1" />
<img src="assets/images/cloud.svg" class="clouds" id="cloud2" /> <img src="{{ relative }}/assets/images/cloud.svg" class="clouds" id="cloud2" />
<div class="top_bg"></div> <div class="top_bg"></div>
<div class="bottom_bg"></div> <div class="bottom_bg"></div>
<div class="top"> <div class="top">
<div class="wrapper"> <div class="wrapper">
<div class="content"> <div class="content">
<h1><a href=".">Redacted Life</a></h1> <h1><a href="{{relative}}">Redacted Life</a></h1>
{% block left_content %} {% block left_content %}
{% endblock %} {% endblock %}
</div> </div>
@ -60,11 +60,11 @@
<div class="bottom"> <div class="bottom">
<div class="wrapper"> <div class="wrapper">
<div class="content"> <div class="content">
<a class="button" href="subscribe.html">Subscribe</a> <a class="button" href="{{relative}}/subscribe/">Subscribe</a>
<a class="button" href="mailto:hello@redacted.life">Contact</a> <a class="button" href="mailto:hello@redacted.life">Contact</a>
<a class="button" href="archives.html">Archives</a> <a class="button" href="{{relative}}/archives/">Archives</a>
</div> </div>
<a class="donate-link" href="donate.html">Consider supporting these individuals and organisations</a> <a class="donate-link" href="{{relative}}/donate/">Consider supporting these individuals and organisations</a>
<footer> <footer>
Designed by <a href="https://webionite.com">Ceda EI</a><br /> Designed by <a href="https://webionite.com">Ceda EI</a><br />
Source available on <a href="https://git.webionite.com/ceda_ei/redacted.life">Webionite</a><br /> Source available on <a href="https://git.webionite.com/ceda_ei/redacted.life">Webionite</a><br />
@ -72,10 +72,10 @@
</footer> </footer>
</div> </div>
</div> </div>
<script src="assets/plyr/plyr.js"></script> <script src="{{ relative }}/assets/plyr/plyr.js"></script>
<script> <script>
const player = new Plyr("#player", { const player = new Plyr("#player", {
iconUrl: "assets/plyr/plyr.svg", iconUrl: "{{ relative }}/assets/plyr/plyr.svg",
}); });
</script> </script>
</body> </body>

22
nova.py
View File

@ -137,13 +137,18 @@ class EpisodeList(UserList):
def generate_archives(self): def generate_archives(self):
"Generates archives page" "Generates archives page"
with open(self.output + "archives.html", "w") as file: if not path.isdir(self.output + "archives"):
logging.info("Creating directory archives")
os.mkdir(self.output + "archives")
with open(self.output + "archives/index.html", "w") as file:
episodes = [{ episodes = [{
"slug": gen_name(i.date, i.slug) + ".html", "slug": gen_name(i.date, i.slug) + ".html",
"title": i.title "title": i.title
} for i in self.data[::-1]] } for i in self.data[::-1]]
file.write(self.archives.render(episodes=episodes, file.write(self.archives.render(episodes=episodes,
title="Archives")) title="Archives",
relative=".."
))
def generate_site(self, root): def generate_site(self, root):
"Generates the entire site" "Generates the entire site"
@ -205,12 +210,13 @@ class Episode:
logging.info(f"New episode: {date=} {slug=} {title=} {self.video=} " logging.info(f"New episode: {date=} {slug=} {title=} {self.video=} "
f"{self.audio=} {config=} {self.length=} {self.show_notes=}") f"{self.audio=} {config=} {self.length=} {self.show_notes=}")
def render(self, template, thumbnail_src): def render(self, template, thumbnail_src, relative="."):
"Renders the Episode with the given template" "Renders the Episode with the given template"
return template.render( return template.render(
title=self.title, title=self.title,
show_notes=jinja2.Markup(self.show_notes), show_notes=jinja2.Markup(self.show_notes),
thumbnail_src=thumbnail_src, thumbnail_src=thumbnail_src,
relative=relative,
video_src=f"assets/videos/{path.basename(self.video)}" video_src=f"assets/videos/{path.basename(self.video)}"
) )
@ -346,17 +352,23 @@ def main(args):
) )
) )
if not path.isdir(output_dir + "subscribe"):
os.mkdir(output_dir + "subscribe")
logging.info("Generating subscribe page") logging.info("Generating subscribe page")
with open(input_dir + "subscribe.json") as subscribe, \ with open(input_dir + "subscribe.json") as subscribe, \
open(output_dir + "subscribe.html", "w") as html: open(output_dir + "subscribe/index.html", "w") as html:
html.write(env.get_template("subscribe.html").render( html.write(env.get_template("subscribe.html").render(
relative="..",
subscribtions=json.load(subscribe) subscribtions=json.load(subscribe)
)) ))
if not path.isdir(output_dir + "donate"):
os.mkdir(output_dir + "donate")
logging.info("Generating donate page") logging.info("Generating donate page")
with open(input_dir + "donate.json") as donate, \ with open(input_dir + "donate.json") as donate, \
open(output_dir + "donate.html", "w") as html: open(output_dir + "donate/index.html", "w") as html:
html.write(env.get_template("donate.html").render( html.write(env.get_template("donate.html").render(
relative="..",
donations=json.load(donate) donations=json.load(donate)
)) ))

View File

@ -1,7 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block title %}Subscribe | Redacted Life{% endblock %} {% block title %}Subscribe | Redacted Life{% endblock %}
{% block stylesheets %} {% block stylesheets %}
<link href="assets/fork-awesome/css/fork-awesome.min.css" rel="stylesheet" type="text/css"> <link href="{{relative}}/assets/fork-awesome/css/fork-awesome.min.css" rel="stylesheet" type="text/css">
{% endblock %} {% endblock %}
{% block left_content %} {% block left_content %}
<div class="subscribe"> <div class="subscribe">