Pull template out to global.
This commit is contained in:
parent
6e3fea4160
commit
86692904a3
1 changed files with 430 additions and 416 deletions
|
@ -10,12 +10,7 @@ from voussoirkit import vlogging
|
|||
|
||||
log = vlogging.getLogger(__name__, 'imagegallery')
|
||||
|
||||
def imagegallery_argparse(args):
|
||||
patterns = pipeable.input_many(args.patterns)
|
||||
files = list(pathclass.glob_many_files(patterns))
|
||||
files.sort()
|
||||
|
||||
html = jinja2.Template(textwrap.dedent('''
|
||||
TEMPLATE = jinja2.Template('''
|
||||
<html>
|
||||
<head>
|
||||
{% if title %}
|
||||
|
@ -293,7 +288,9 @@ def imagegallery_argparse(args):
|
|||
{% for file in files %}
|
||||
<article class="photograph">
|
||||
<a target="_blank" href="{{urlroot}}{{file.relative_to('.', simple=True)}}"><img loading="lazy" src="{{urlroot}}thumbs/small_{{file.relative_to('.', simple=True)}}"/></a>
|
||||
{% if with_download_links %}
|
||||
<a class="download_link" download="{{file.basename}}" href="{{urlroot}}{{file.relative_to('.', simple=True)}}">#{{loop.index}}/{{files|length}}</a>
|
||||
{% endif %}
|
||||
</article>
|
||||
{% endfor %}
|
||||
</body>
|
||||
|
@ -430,10 +427,27 @@ def imagegallery_argparse(args):
|
|||
document.addEventListener("DOMContentLoaded", on_pageload);
|
||||
</script>
|
||||
</html>
|
||||
''')).render(
|
||||
''')
|
||||
|
||||
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 = 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
|
||||
|
|
Loading…
Reference in a new issue