Update /photography.
This commit is contained in:
parent
121b77d021
commit
42abf48530
1 changed files with 36 additions and 26 deletions
|
@ -8,9 +8,18 @@ from voussoirkit import pathclass
|
||||||
from voussoirkit import spinal
|
from voussoirkit import spinal
|
||||||
|
|
||||||
PHOTOGRAPHY_ROOTDIR = pathclass.Path(__file__).parent
|
PHOTOGRAPHY_ROOTDIR = pathclass.Path(__file__).parent
|
||||||
|
ATOM_FILE = PHOTOGRAPHY_ROOTDIR.with_child('photography.atom')
|
||||||
DOMAIN_ROOTDIR = PHOTOGRAPHY_ROOTDIR.parent
|
DOMAIN_ROOTDIR = PHOTOGRAPHY_ROOTDIR.parent
|
||||||
CSS_CONTENT = PHOTOGRAPHY_ROOTDIR.with_child('dark.css').read('r', encoding='utf-8')
|
CSS_CONTENT = PHOTOGRAPHY_ROOTDIR.with_child('dark.css').read('r', encoding='utf-8')
|
||||||
DOMAIN_WEBROOT = ('file:///' + DOMAIN_ROOTDIR.absolute_path) if '--test' in sys.argv else 'https://voussoir.net'
|
DOMAIN_WEBROOT = ('file:///' + DOMAIN_ROOTDIR.absolute_path) if '--test' in sys.argv else 'https://voussoir.net'
|
||||||
|
DOMAIN_WEBROOT = DOMAIN_WEBROOT.replace('\\', '/')
|
||||||
|
|
||||||
|
def webpath(path, anchor=None):
|
||||||
|
path = path.relative_to(DOMAIN_ROOTDIR, simple=True).replace('\\', '/').lstrip('/')
|
||||||
|
path = DOMAIN_WEBROOT.rstrip('/') + '/' + path
|
||||||
|
if anchor is not None:
|
||||||
|
path += '#' + anchor.lstrip('#')
|
||||||
|
return path
|
||||||
|
|
||||||
class Photo:
|
class Photo:
|
||||||
def __init__(self, filepath):
|
def __init__(self, filepath):
|
||||||
|
@ -21,21 +30,19 @@ class Photo:
|
||||||
self.published = imagetools.get_exif_datetime(filepath)
|
self.published = imagetools.get_exif_datetime(filepath)
|
||||||
|
|
||||||
def render_web(self, relative_directory=None):
|
def render_web(self, relative_directory=None):
|
||||||
href = self.filepath.relative_to(DOMAIN_ROOTDIR, simple=True).replace('\\', '/')
|
|
||||||
thumb = self.thumbnail.relative_to(DOMAIN_ROOTDIR, simple=True).replace('\\', '/')
|
|
||||||
return f'''
|
return f'''
|
||||||
<article id="{self.article_id}" class="photograph">
|
<article id="{self.article_id}" class="photograph">
|
||||||
<a href="{DOMAIN_WEBROOT}/{href}" target="_blank"><img src="{DOMAIN_WEBROOT}/{thumb}" loading="lazy"/></a>
|
<a href="{webpath(self.filepath)}" target="_blank"><img src="{webpath(self.thumbnail)}" loading="lazy"/></a>
|
||||||
</article>
|
</article>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def render_atom(self):
|
def render_atom(self):
|
||||||
href = f'{DOMAIN_WEBROOT}/photography{self.anchor}'
|
href = webpath(PHOTOGRAPHY_ROOTDIR, anchor=self.anchor)
|
||||||
imgsrc = f'{DOMAIN_WEBROOT}/' + self.thumbnail.relative_to(DOMAIN_ROOTDIR, simple=True)
|
imgsrc = webpath(self.thumbnail)
|
||||||
return f'''
|
return f'''
|
||||||
<id>{self.article_id}</id>
|
<id>{self.article_id}</id>
|
||||||
<title>{self.article_id}</title>
|
<title>{self.article_id}</title>
|
||||||
<link rel="alternate" type="text/html" href="{DOMAIN_WEBROOT}/photography{self.anchor}"/>
|
<link rel="alternate" type="text/html" href="{href}"/>
|
||||||
<updated>{self.published.isoformat()}</updated>
|
<updated>{self.published.isoformat()}</updated>
|
||||||
<content type="html">
|
<content type="html">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
|
@ -48,7 +55,7 @@ class Album:
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
self.article_id = path.basename
|
self.article_id = path.basename
|
||||||
self.link = '/' + path.relative_to(PHOTOGRAPHY_ROOTDIR, simple=True).replace('\\', '/')
|
self.link = webpath(path)
|
||||||
self.published = imagetools.get_exif_datetime(sorted(path.glob_files('*.jpg'))[0])
|
self.published = imagetools.get_exif_datetime(sorted(path.glob_files('*.jpg'))[0])
|
||||||
self.photos = list(spinal.walk(
|
self.photos = list(spinal.walk(
|
||||||
self.path,
|
self.path,
|
||||||
|
@ -70,7 +77,7 @@ class Album:
|
||||||
|
|
||||||
return jinja2.Template('''
|
return jinja2.Template('''
|
||||||
<article id="{{article_id}}" class="album">
|
<article id="{{article_id}}" class="album">
|
||||||
<h1><a href="/{{album_path}}">{{directory.basename}}</a></h1>
|
<h1><a href="{{album_path}}">{{directory.basename}}</a></h1>
|
||||||
{% for photo in firsts %}
|
{% for photo in firsts %}
|
||||||
{{photo.render_web()}}
|
{{photo.render_web()}}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -82,7 +89,7 @@ class Album:
|
||||||
''').render(
|
''').render(
|
||||||
article_id=self.article_id,
|
article_id=self.article_id,
|
||||||
directory=self.path,
|
directory=self.path,
|
||||||
album_path=self.path.relative_to(DOMAIN_ROOTDIR, simple=True).replace('\\', '/'),
|
album_path=webpath(self.path),
|
||||||
next_after_more=next_after_more,
|
next_after_more=next_after_more,
|
||||||
firsts=firsts,
|
firsts=firsts,
|
||||||
remaining=len(remaining),
|
remaining=len(remaining),
|
||||||
|
@ -91,8 +98,8 @@ class Album:
|
||||||
def render_atom(self):
|
def render_atom(self):
|
||||||
photos = []
|
photos = []
|
||||||
for photo in self.photos:
|
for photo in self.photos:
|
||||||
href = f'{DOMAIN_WEBROOT}/photography/' + photo.filepath.relative_to(PHOTOGRAPHY_ROOTDIR, simple=True)
|
href = webpath(photo.filepath)
|
||||||
imgsrc = f'{DOMAIN_WEBROOT}/photography/' + photo.thumbnail.relative_to(PHOTOGRAPHY_ROOTDIR, simple=True)
|
imgsrc = webpath(photo.thumbnail)
|
||||||
line = f'<article><a href="{href}"><img src="{imgsrc}"/></a>'.replace('\\', '/')
|
line = f'<article><a href="{href}"><img src="{imgsrc}"/></a>'.replace('\\', '/')
|
||||||
photos.append(line)
|
photos.append(line)
|
||||||
photos = '\n'.join(photos)
|
photos = '\n'.join(photos)
|
||||||
|
@ -100,7 +107,7 @@ class Album:
|
||||||
return f'''
|
return f'''
|
||||||
<id>{self.article_id}</id>
|
<id>{self.article_id}</id>
|
||||||
<title>{self.article_id}</title>
|
<title>{self.article_id}</title>
|
||||||
<link rel="alternate" type="text/html" href="{DOMAIN_WEBROOT}/photography{self.link}"/>
|
<link rel="alternate" type="text/html" href="{self.link}"/>
|
||||||
<updated>{self.published.isoformat()}</updated>
|
<updated>{self.published.isoformat()}</updated>
|
||||||
<content type="html">
|
<content type="html">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
|
@ -120,8 +127,8 @@ def write(path, content):
|
||||||
path.write('w', content, encoding='utf-8')
|
path.write('w', content, encoding='utf-8')
|
||||||
|
|
||||||
def write_directory_index(directory):
|
def write_directory_index(directory):
|
||||||
do_rss = directory == PHOTOGRAPHY_ROOTDIR
|
rss_link = webpath(ATOM_FILE) if directory == PHOTOGRAPHY_ROOTDIR else None
|
||||||
do_back = directory != PHOTOGRAPHY_ROOTDIR
|
back_link = webpath(PHOTOGRAPHY_ROOTDIR) if directory != PHOTOGRAPHY_ROOTDIR else None
|
||||||
sort_reverse = directory == PHOTOGRAPHY_ROOTDIR
|
sort_reverse = directory == PHOTOGRAPHY_ROOTDIR
|
||||||
|
|
||||||
items = list(spinal.walk(
|
items = list(spinal.walk(
|
||||||
|
@ -147,7 +154,9 @@ def write_directory_index(directory):
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
<link rel="alternate" type="application/atom+xml" href="/photography/photography.atom"/>
|
{% if rss_link %}
|
||||||
|
<link rel="alternate" type="application/atom+xml" href="{{rss_link}}"/>
|
||||||
|
{% endif %}
|
||||||
<title>{{directory.basename}}</title>
|
<title>{{directory.basename}}</title>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -159,13 +168,13 @@ def write_directory_index(directory):
|
||||||
<header>
|
<header>
|
||||||
<div id="keyboardhint">hint: <kbd>←</kbd> / <kbd>→</kbd></div>
|
<div id="keyboardhint">hint: <kbd>←</kbd> / <kbd>→</kbd></div>
|
||||||
<a id="scrollbartoggle" onclick="return toggle_scrollbar();">scrollbar on/off</a>
|
<a id="scrollbartoggle" onclick="return toggle_scrollbar();">scrollbar on/off</a>
|
||||||
{% if do_rss %}
|
{% if rss_link %}
|
||||||
<a href="/photography/photography.atom">Atom</a>
|
<a href="{{rss_link}}">Atom</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if do_back %}
|
{%- if back_link -%}
|
||||||
<a href="/photography">Back</a>
|
<a href="{{back_link}}">Back</a>
|
||||||
{% endif %}
|
{%- endif -%}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
|
@ -307,13 +316,13 @@ def write_directory_index(directory):
|
||||||
''').render(
|
''').render(
|
||||||
css_content=CSS_CONTENT,
|
css_content=CSS_CONTENT,
|
||||||
directory=directory,
|
directory=directory,
|
||||||
do_rss=do_rss,
|
rss_link=rss_link,
|
||||||
do_back=do_back,
|
back_link=back_link,
|
||||||
items=items,
|
items=items,
|
||||||
)
|
)
|
||||||
write(directory.with_child('index.html'), page)
|
write(directory.with_child('index.html'), page)
|
||||||
|
|
||||||
if do_rss:
|
if rss_link:
|
||||||
write_atom(items)
|
write_atom(items)
|
||||||
|
|
||||||
def write_atom(items):
|
def write_atom(items):
|
||||||
|
@ -321,7 +330,7 @@ def write_atom(items):
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
<title>voussoir.net/photography</title>
|
<title>voussoir.net/photography</title>
|
||||||
<link href="{DOMAIN_WEBROOT}/photography"/>
|
<link href="webpath(PHOTOGRAPHY_ROOTDIR)}"/>
|
||||||
<id>voussoir.net/photography</id>
|
<id>voussoir.net/photography</id>
|
||||||
|
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
|
@ -331,7 +340,7 @@ def write_atom(items):
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</feed>
|
</feed>
|
||||||
'''.strip()).render(items=items)
|
'''.strip()).render(items=items)
|
||||||
write(PHOTOGRAPHY_ROOTDIR.with_child('photography.atom'), atom)
|
write(ATOM_FILE, atom)
|
||||||
|
|
||||||
def make_thumbnail(photo):
|
def make_thumbnail(photo):
|
||||||
small_name = photo.replace_extension('').basename + '_small'
|
small_name = photo.replace_extension('').basename + '_small'
|
||||||
|
@ -340,9 +349,10 @@ def make_thumbnail(photo):
|
||||||
return small_name
|
return small_name
|
||||||
image = PIL.Image.open(photo.absolute_path)
|
image = PIL.Image.open(photo.absolute_path)
|
||||||
(image_width, image_height) = image.size
|
(image_width, image_height) = image.size
|
||||||
|
exif = image.getexif()
|
||||||
(width, height) = imagetools.fit_into_bounds(image_width, image_height, 1440, 1440)
|
(width, height) = imagetools.fit_into_bounds(image_width, image_height, 1440, 1440)
|
||||||
image = image.resize((width, height), PIL.Image.LANCZOS)
|
image = image.resize((width, height), PIL.Image.LANCZOS)
|
||||||
image.save(small_name.absolute_path, quality=75)
|
image.save(small_name.absolute_path, quality=75, exif=exif)
|
||||||
print(small_name)
|
print(small_name)
|
||||||
return small_name
|
return small_name
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue