create listing pages per author/tag/etc
This commit is contained in:
parent
a290c2c4e7
commit
c1c1813c88
|
@ -306,14 +306,16 @@ def publish(args):
|
||||||
loader=PackageLoader("dlibrary"),
|
loader=PackageLoader("dlibrary"),
|
||||||
autoescape=select_autoescape()
|
autoescape=select_autoescape()
|
||||||
)
|
)
|
||||||
|
|
||||||
viewer_template = jenv.get_template("viewer.html")
|
viewer_template = jenv.get_template("viewer.html")
|
||||||
|
list_template = jenv.get_template("list.html")
|
||||||
|
|
||||||
con = sqlite3.connect(args.destdir / 'meta.db')
|
con = sqlite3.connect(args.destdir / 'meta.db')
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
|
|
||||||
collated_work_ids = {p.name for p in (args.destdir / 'site' / 'images').iterdir()}
|
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 = []
|
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():
|
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:
|
if work_id not in collated_work_ids:
|
||||||
|
@ -340,11 +342,44 @@ def publish(args):
|
||||||
with open(work_dir / 'index.html', 'w') as f:
|
with open(work_dir / 'index.html', 'w') as f:
|
||||||
f.write(viewer_template.render(depth=2, work=work, title=title, images=images))
|
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:
|
with resources.as_file(resources.files("dlibrary")) as r:
|
||||||
copy_contents(r / 'static', args.destdir / 'site' / 'static')
|
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:
|
with open(args.destdir / 'site' / 'index.html', 'w') as f:
|
||||||
f.write(list_template.render(depth=0, works=works))
|
f.write(list_template.render(depth=0, works=works))
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% from 'utils.html' import root with context %}
|
{% 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 %} > <a href="{{ root() }}{{ category }}">{{ category.capitalize() }}</a>{% endif %}{% if title %} > {{ title }}{% endif %}</h1>
|
||||||
<div class="card-listing">
|
<div class="card-listing">
|
||||||
{% for work in works %}
|
{% for work in works %}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
|
|
Loading…
Reference in a new issue