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),
'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),
S = {
'index': 0,
'vindex': 0,
+ 'ilustr': 0,
'id': defaultdict(lambda: 0),
'stack': [],
'front1': [],
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
+ }