diff --git a/photogallery.py b/photogallery.py index 5f23e78..5a4f091 100644 --- a/photogallery.py +++ b/photogallery.py @@ -10,430 +10,444 @@ from voussoirkit import vlogging log = vlogging.getLogger(__name__, 'imagegallery') +TEMPLATE = jinja2.Template(''' + + +{% if title %} +{{title}} +{% endif %} + + + + + +
+ scrollbar on/off +
+ {% if title %} +

{{title}}

+ {% endif %} + +

Click each photo to view its full resolution. Click the number to download it.

+ + {% for file in files %} +
+ + {% if with_download_links %} + #{{loop.index}}/{{files|length}} + {% endif %} +
+ {% endfor %} + + + + +''') + +def imagegallery(files, title, urlroot, with_download_links): + html = TEMPLATE.render( + files=files, + title=title, + urlroot=urlroot, + with_download_links=with_download_links, + ) + return html + def imagegallery_argparse(args): patterns = pipeable.input_many(args.patterns) files = list(pathclass.glob_many_files(patterns)) files.sort() - html = jinja2.Template(textwrap.dedent(''' - - - {% if title %} - {{title}} - {% endif %} - - - - - -
- scrollbar on/off -
- {% if title %} -

{{title}}

- {% endif %} - -

Click each photo to view its full resolution. Click the number to download it.

- - {% for file in files %} -
- - #{{loop.index}}/{{files|length}} -
- {% endfor %} - - - - - ''')).render( + html = imagegallery( files=files, title=args.title, urlroot=args.urlroot or '', + with_download_links=True, ) pathclass.Path('gallery.html').open('w', encoding='utf-8').write(html) return 0