create author-list, tag-list, etc pages

This commit is contained in:
xenofem 2024-01-23 00:00:15 -05:00
parent c1c1813c88
commit 666c6d3acf
5 changed files with 51 additions and 10 deletions

View file

@ -308,6 +308,7 @@ def publish(args):
) )
viewer_template = jenv.get_template("viewer.html") viewer_template = jenv.get_template("viewer.html")
list_template = jenv.get_template("list.html") list_template = jenv.get_template("list.html")
categorization_template = jenv.get_template("categorization.html")
con = sqlite3.connect(args.destdir / 'meta.db') con = sqlite3.connect(args.destdir / 'meta.db')
cur = con.cursor() cur = con.cursor()
@ -342,36 +343,51 @@ 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): def make_categorization(categorization, query, work_filter):
categorization_dir = args.destdir / 'site' / categorization
cats = [cat for (cat,) in cur.execute(query)] cats = [cat for (cat,) in cur.execute(query)]
cat_samples = {}
for cat in cats: 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('/', ' ') 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) cat_dir.mkdir(parents=True, exist_ok=True)
with open(cat_dir / 'index.html', 'w') as f: with open(cat_dir / 'index.html', 'w') as f:
f.write(list_template.render( f.write(list_template.render(
depth=2, depth=2,
works=list(filter(work_filter(cat), works)), works=cat_works,
title=cat, 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', 'authors',
'SELECT DISTINCT author FROM authors ORDER BY author', 'SELECT DISTINCT author FROM authors ORDER BY author',
lambda author: lambda work: author in work['authors'], lambda author: lambda work: author in work['authors'],
) )
make_categories( make_categorization(
'tags', 'tags',
'SELECT DISTINCT tag FROM tags ORDER BY tag', 'SELECT DISTINCT tag FROM tags ORDER BY tag',
lambda tag: lambda work: tag in work['tags'], lambda tag: lambda work: tag in work['tags'],
) )
make_categories( make_categorization(
'circles', 'circles',
'SELECT DISTINCT circle FROM works WHERE circle NOT NULL ORDER BY circle', 'SELECT DISTINCT circle FROM works WHERE circle NOT NULL ORDER BY circle',
lambda circle: lambda work: work['circle'] == circle, lambda circle: lambda work: work['circle'] == circle,
) )
make_categories( make_categorization(
'series', 'series',
'SELECT DISTINCT series FROM works WHERE series NOT NULL ORDER BY series', 'SELECT DISTINCT series FROM works WHERE series NOT NULL ORDER BY series',
lambda series: lambda work: work['series'] == series, lambda series: lambda work: work['series'] == series,

View file

@ -32,6 +32,11 @@ body {
max-height: 100%; max-height: 100%;
} }
.card.category {
font-size: 26px;
max-width: 240px;
}
/* viewer stuff */ /* viewer stuff */
#viewer-images { #viewer-images {

View file

@ -5,7 +5,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark"> <meta name="color-scheme" content="dark">
<title>{% if title %}{{ title }} - {% else %}{% endif %}DLibrary</title> <title>{% block title %}{% if title %}{{ title }} - {% else %}{% endif %}DLibrary{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{{ root() }}static/dlibrary.css"> <link rel="stylesheet" type="text/css" href="{{ root() }}static/dlibrary.css">
{% block head %}{% endblock %} {% block head %}{% endblock %}
</head> </head>

View file

@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block title %}{{ categorization.capitalize() }} - DLibrary{% endblock %}
{% block body %}
{% from 'utils.html' import root with context %}
<h1 id="list-title"><a href="{{ root() }}">DLibrary</a> &gt; <a href="{{ root() }}{{ categorization }}">{{ categorization.capitalize() }}</a></h1>
<div class="card-listing">
{% for cat in categories %}
<div class="card category">
<a href="{{ root() }}{{ categorization }}/{{ cat | replace('/', ' ') | urlencode }}/">
<div class="card-title">
{{ cat }}
</div>
{% if samples[cat] %}
<img src="{{ root() }}thumbnails/{{ samples[cat]['id'] }}.jpg">
{% endif %}
</a>
</div>
{% endfor %}
</div>
{% endblock %}

View file

@ -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>{% if category %} &gt; <a href="{{ root() }}{{ category }}">{{ category.capitalize() }}</a>{% endif %}{% if title %} &gt; {{ title }}{% endif %}</h1> <h1 id="list-title"><a href="{{ root() }}">DLibrary</a>{% if categorization %} &gt; <a href="{{ root() }}{{ categorization }}">{{ categorization.capitalize() }}</a>{% endif %}{% if title %} &gt; {{ 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">