create listing pages per author/tag/etc

This commit is contained in:
xenofem 2024-01-22 23:20:42 -05:00
parent a290c2c4e7
commit c1c1813c88
2 changed files with 39 additions and 4 deletions

View file

@ -306,14 +306,16 @@ def publish(args):
loader=PackageLoader("dlibrary"),
autoescape=select_autoescape()
)
viewer_template = jenv.get_template("viewer.html")
list_template = jenv.get_template("list.html")
con = sqlite3.connect(args.destdir / 'meta.db')
cur = con.cursor()
collated_work_ids = {p.name for p in (args.destdir / 'site' / 'images').iterdir()}
actual_series = {series for (series,) in cur.execute('SELECT series FROM works GROUP BY series HAVING count(series) > 1')}
works = []
for (work_id, title, circle, date, description, series) in cur.execute('SELECT id, title, circle, date, description, series FROM works ORDER BY date DESC').fetchall():
if work_id not in collated_work_ids:
@ -340,11 +342,44 @@ def publish(args):
with open(work_dir / 'index.html', 'w') as f:
f.write(viewer_template.render(depth=2, work=work, title=title, images=images))
def make_categories(category_type, query, work_filter):
cats = [cat for (cat,) in cur.execute(query)]
for cat in cats:
safeish_cat = cat.replace('/', ' ')
cat_dir = args.destdir / 'site' / category_type / safeish_cat
cat_dir.mkdir(parents=True, exist_ok=True)
with open(cat_dir / 'index.html', 'w') as f:
f.write(list_template.render(
depth=2,
works=list(filter(work_filter(cat), works)),
title=cat,
category=category_type,
))
make_categories(
'authors',
'SELECT DISTINCT author FROM authors ORDER BY author',
lambda author: lambda work: author in work['authors'],
)
make_categories(
'tags',
'SELECT DISTINCT tag FROM tags ORDER BY tag',
lambda tag: lambda work: tag in work['tags'],
)
make_categories(
'circles',
'SELECT DISTINCT circle FROM works WHERE circle NOT NULL ORDER BY circle',
lambda circle: lambda work: work['circle'] == circle,
)
make_categories(
'series',
'SELECT DISTINCT series FROM works WHERE series NOT NULL ORDER BY series',
lambda series: lambda work: work['series'] == series,
)
with resources.as_file(resources.files("dlibrary")) as r:
copy_contents(r / 'static', args.destdir / 'site' / 'static')
list_template = jenv.get_template("list.html")
with open(args.destdir / 'site' / 'index.html', 'w') as f:
f.write(list_template.render(depth=0, works=works))

View file

@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% block body %}
{% from 'utils.html' import root with context %}
<h1 id="list-title"><a href={{ root() }}>DLibrary</a> {% block list_title %}{% endblock %}</h1>
<h1 id="list-title"><a href="{{ root() }}">DLibrary</a>{% if category %} &gt; <a href="{{ root() }}{{ category }}">{{ category.capitalize() }}</a>{% endif %}{% if title %} &gt; {{ title }}{% endif %}</h1>
<div class="card-listing">
{% for work in works %}
<div class="card">