From: Radek Czajka Date: Tue, 1 Dec 2026 13:44:01 +0000 (+0100) Subject: Ilustr sizes in json for app X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/634e6dfe9359e7cf59849c48ba731a0206b12042?ds=sidebyside Ilustr sizes in json for app --- diff --git a/src/catalogue/api/tojson.py b/src/catalogue/api/tojson.py index d3b7ab539..691ee3d70 100644 --- a/src/catalogue/api/tojson.py +++ b/src/catalogue/api/tojson.py @@ -3,7 +3,14 @@ import json import re from sys import argv from lxml import etree -from catalogue.utils import absolute_url, gallery_url +from catalogue.utils import get_ilustr_sizes + + +def ilustr_sizes_getter(e, S): + sizes = get_ilustr_sizes(e.attrib['src'], S['slug'], S['ilustr']) + S['ilustr'] += 1 + return sizes + tags = { 'utwor': ('_pass', False, None, None, None), @@ -125,7 +132,9 @@ tags = { 'kol': ('td', True, None, None, None), 'ilustr': ('img', False, None, { - 'src': lambda e, S: absolute_url(gallery_url(S['slug'])) + e.attrib['src'].rsplit('/', 1)[-1], + 'src': lambda e, S: e.attrib['src'], + 'sizes': ilustr_sizes_getter, + 'alt': 'alt', }, False), 'tab': ('span', False, {'class': 'tab'}, {'szer': 'szer'}, False), @@ -254,6 +263,7 @@ def conv(tree, slug): S = { 'index': 0, 'vindex': 0, + 'ilustr': 0, 'id': defaultdict(lambda: 0), 'stack': [], 'front1': [], diff --git a/src/catalogue/utils.py b/src/catalogue/utils.py index 2469d6cdb..60de5556f 100644 --- a/src/catalogue/utils.py +++ b/src/catalogue/utils.py @@ -332,3 +332,14 @@ def iter_file(field_file, chunk_size=CHUNK_SIZE): else: with field_file.open("rb") as f: yield from f.chunks(chunk_size) + + +# TODO: this should be recorded when generated. +ILUSTR_SIZES = [360, 600, 1200, 1800, 2400] +def get_ilustr_sizes(src, slug, index): + ext = src.rsplit('.', 1)[-1] + gallery = absolute_url(gallery_url(slug)) + return { + str(size): f"{gallery}{index}.W{size}.{ext}" + for size in ILUSTR_SIZES + }