diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index eec8ea4..3c544d3 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -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)) diff --git a/dlibrary/templates/list.html b/dlibrary/templates/list.html index ea3cd6e..4b0e344 100644 --- a/dlibrary/templates/list.html +++ b/dlibrary/templates/list.html @@ -1,7 +1,7 @@ {% extends 'base.html' %} {% block body %} {% from 'utils.html' import root with context %} -

DLibrary {% block list_title %}{% endblock %}

+

DLibrary{% if category %} > {{ category.capitalize() }}{% endif %}{% if title %} > {{ title }}{% endif %}

{% for work in works %}