From 666c6d3acfdd595f283fc13c451506d88d794fbe Mon Sep 17 00:00:00 2001 From: xenofem Date: Tue, 23 Jan 2024 00:00:15 -0500 Subject: [PATCH] create author-list, tag-list, etc pages --- dlibrary/dlibrary.py | 32 +++++++++++++++++++------- dlibrary/static/dlibrary.css | 5 ++++ dlibrary/templates/base.html | 2 +- dlibrary/templates/categorization.html | 20 ++++++++++++++++ dlibrary/templates/list.html | 2 +- 5 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 dlibrary/templates/categorization.html diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index 3c544d3..8959eb5 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -308,6 +308,7 @@ def publish(args): ) viewer_template = jenv.get_template("viewer.html") list_template = jenv.get_template("list.html") + categorization_template = jenv.get_template("categorization.html") con = sqlite3.connect(args.destdir / 'meta.db') cur = con.cursor() @@ -342,36 +343,51 @@ 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): + def make_categorization(categorization, query, work_filter): + categorization_dir = args.destdir / 'site' / categorization + cats = [cat for (cat,) in cur.execute(query)] + cat_samples = {} for cat in cats: + cat_works = list(filter(work_filter(cat), works)) + cat_samples[cat] = cat_works[0] if len(cat_works) > 0 else None + safeish_cat = cat.replace('/', ' ') - cat_dir = args.destdir / 'site' / category_type / safeish_cat + cat_dir = categorization_dir / 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)), + works=cat_works, title=cat, - category=category_type, + categorization=categorization, )) - make_categories( + categorization_dir.mkdir(parents=True, exist_ok=True) + with open(categorization_dir / 'index.html', 'w') as f: + f.write(categorization_template.render( + depth=1, + categorization=categorization, + categories=cats, + samples=cat_samples, + )) + + make_categorization( 'authors', 'SELECT DISTINCT author FROM authors ORDER BY author', lambda author: lambda work: author in work['authors'], ) - make_categories( + make_categorization( 'tags', 'SELECT DISTINCT tag FROM tags ORDER BY tag', lambda tag: lambda work: tag in work['tags'], ) - make_categories( + make_categorization( 'circles', 'SELECT DISTINCT circle FROM works WHERE circle NOT NULL ORDER BY circle', lambda circle: lambda work: work['circle'] == circle, ) - make_categories( + make_categorization( 'series', 'SELECT DISTINCT series FROM works WHERE series NOT NULL ORDER BY series', lambda series: lambda work: work['series'] == series, diff --git a/dlibrary/static/dlibrary.css b/dlibrary/static/dlibrary.css index 6edb8d2..af0b971 100644 --- a/dlibrary/static/dlibrary.css +++ b/dlibrary/static/dlibrary.css @@ -32,6 +32,11 @@ body { max-height: 100%; } +.card.category { + font-size: 26px; + max-width: 240px; +} + /* viewer stuff */ #viewer-images { diff --git a/dlibrary/templates/base.html b/dlibrary/templates/base.html index 558de22..40cb671 100644 --- a/dlibrary/templates/base.html +++ b/dlibrary/templates/base.html @@ -5,7 +5,7 @@ - {% if title %}{{ title }} - {% else %}{% endif %}DLibrary + {% block title %}{% if title %}{{ title }} - {% else %}{% endif %}DLibrary{% endblock %} {% block head %}{% endblock %} diff --git a/dlibrary/templates/categorization.html b/dlibrary/templates/categorization.html new file mode 100644 index 0000000..0aaf4c7 --- /dev/null +++ b/dlibrary/templates/categorization.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} +{% block title %}{{ categorization.capitalize() }} - DLibrary{% endblock %} +{% block body %} +{% from 'utils.html' import root with context %} +

DLibrary > {{ categorization.capitalize() }}

+
+ {% for cat in categories %} + + {% endfor %} +
+{% endblock %} diff --git a/dlibrary/templates/list.html b/dlibrary/templates/list.html index 4b0e344..8ab18ee 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{% if category %} > {{ category.capitalize() }}{% endif %}{% if title %} > {{ title }}{% endif %}

+

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

{% for work in works %}