create author-list, tag-list, etc pages
This commit is contained in:
parent
c1c1813c88
commit
666c6d3acf
|
@ -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,
|
||||
|
|
|
@ -32,6 +32,11 @@ body {
|
|||
max-height: 100%;
|
||||
}
|
||||
|
||||
.card.category {
|
||||
font-size: 26px;
|
||||
max-width: 240px;
|
||||
}
|
||||
|
||||
/* viewer stuff */
|
||||
|
||||
#viewer-images {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<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">
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
|
|
20
dlibrary/templates/categorization.html
Normal file
20
dlibrary/templates/categorization.html
Normal 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> > <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 %}
|
|
@ -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>{% if category %} > <a href="{{ root() }}{{ category }}">{{ category.capitalize() }}</a>{% endif %}{% if title %} > {{ title }}{% endif %}</h1>
|
||||
<h1 id="list-title"><a href="{{ root() }}">DLibrary</a>{% if categorization %} > <a href="{{ root() }}{{ categorization }}">{{ categorization.capitalize() }}</a>{% endif %}{% if title %} > {{ title }}{% endif %}</h1>
|
||||
<div class="card-listing">
|
||||
{% for work in works %}
|
||||
<div class="card">
|
||||
|
|
Loading…
Reference in a new issue