Update /photography.

This commit is contained in:
voussoir 2022-09-09 17:13:54 -07:00
parent 7ab7b079ff
commit 0a825a6cd2
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
2 changed files with 35 additions and 22 deletions

View file

@ -64,18 +64,20 @@ header > *
background-color: var(--color_bodybg); background-color: var(--color_bodybg);
} }
.photograph, .album .album,
.photograph
{ {
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
margin-top: 40px; margin-top: 8vh;
margin-bottom: 40px; margin-bottom: 8vh;
} }
.photograph .photograph
{ {
padding: 2vh; padding: 2vh;
background-color: var(--color_bodybg); background-color: var(--color_bodybg);
border-radius: 16px;
} }
article .photograph:first-of-type article .photograph:first-of-type
{ {
@ -88,6 +90,7 @@ article .photograph:last-of-type
.photograph img .photograph img
{ {
max-height: 92vh; max-height: 92vh;
border-radius: 8px;
} }
article .morelink article .morelink
{ {

View file

@ -15,29 +15,25 @@ class Photo:
self.filepath = filepath self.filepath = filepath
self.thumbnail = make_thumbnail(filepath) self.thumbnail = make_thumbnail(filepath)
self.article_id = filepath.replace_extension('').basename self.article_id = filepath.replace_extension('').basename
self.link = f'#{self.article_id}' self.anchor = f'#{self.article_id}'
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):
if relative_directory is None: href = self.filepath.relative_to(DOMAIN_ROOTDIR, simple=True).replace('\\', '/')
basename = self.filepath.basename thumb = self.thumbnail.relative_to(DOMAIN_ROOTDIR, simple=True).replace('\\', '/')
thumb = self.thumbnail.basename
else:
basename = self.filepath.relative_to(relative_directory, simple=True).replace('\\', '/')
thumb = self.thumbnail.relative_to(relative_directory, simple=True).replace('\\', '/')
return f''' return f'''
<article id="{self.article_id}" class="photograph"> <article id="{self.article_id}" class="photograph">
<a href="{basename}" target="_blank"><img src="{thumb}" loading="lazy"/></a> <a href="https://voussoir.net/{href}" target="_blank"><img src="/{thumb}" loading="lazy"/></a>
</article> </article>
''' '''
def render_atom(self): def render_atom(self):
href = f'https://voussoir.net/photography{self.link}' href = f'https://voussoir.net/photography{self.anchor}'
imgsrc = 'https://voussoir.net/photography/' + self.thumbnail.relative_to(PHOTOGRAPHY_ROOTDIR, simple=True) imgsrc = 'https://voussoir.net/' + self.thumbnail.relative_to(DOMAIN_ROOTDIR, simple=True)
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="https://voussoir.net/photography{self.link}"/> <link rel="alternate" type="text/html" href="https://voussoir.net/photography{self.anchor}"/>
<updated>{self.published.isoformat()}</updated> <updated>{self.published.isoformat()}</updated>
<content type="html"> <content type="html">
<![CDATA[ <![CDATA[
@ -50,7 +46,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 = f'/{self.article_id}' self.link = '/' + path.relative_to(PHOTOGRAPHY_ROOTDIR, simple=True).replace('\\', '/')
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,
@ -72,9 +68,9 @@ 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(relative_directory=directory.parent)}} {{photo.render_web()}}
{% endfor %} {% endfor %}
{% if remaining > 0 %} {% if remaining > 0 %}
@ -84,7 +80,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.basename, album_path=self.path.relative_to(DOMAIN_ROOTDIR, simple=True).replace('\\', '/'),
next_after_more=next_after_more, next_after_more=next_after_more,
firsts=firsts, firsts=firsts,
remaining=len(remaining), remaining=len(remaining),
@ -119,9 +115,7 @@ def write(path, content):
if path not in PHOTOGRAPHY_ROOTDIR: if path not in PHOTOGRAPHY_ROOTDIR:
raise ValueError(path) raise ValueError(path)
print(path.absolute_path) print(path.absolute_path)
f = path.open('w', encoding='utf-8') path.write('w', content, encoding='utf-8')
f.write(content)
f.close()
def write_directory_index(directory): def write_directory_index(directory):
do_rss = directory == PHOTOGRAPHY_ROOTDIR do_rss = directory == PHOTOGRAPHY_ROOTDIR
@ -185,12 +179,27 @@ def write_directory_index(directory):
if (document.body.classList.contains("noscrollbar")) if (document.body.classList.contains("noscrollbar"))
{ {
document.body.classList.remove("noscrollbar"); document.body.classList.remove("noscrollbar");
localStorage.setItem("show_scrollbar", "yes");
} }
else else
{ {
document.body.classList.add("noscrollbar"); document.body.classList.add("noscrollbar");
localStorage.setItem("show_scrollbar", "no");
} }
} }
function load_scrollbar_setting()
{
if (localStorage.getItem("show_scrollbar") === "no")
{
document.body.classList.add("noscrollbar");
}
else
{
document.body.classList.remove("noscrollbar");
}
}
function get_center_img() function get_center_img()
{ {
let center_x = window.innerWidth / 2; let center_x = window.innerWidth / 2;
@ -288,6 +297,7 @@ def write_directory_index(directory):
document.documentElement.addEventListener("keydown", arrowkey_listener); document.documentElement.addEventListener("keydown", arrowkey_listener);
document.documentElement.addEventListener("mousemove", mousemove_handler); document.documentElement.addEventListener("mousemove", mousemove_handler);
mousemove_handler(); mousemove_handler();
load_scrollbar_setting();
} }
document.addEventListener("DOMContentLoaded", on_pageload); document.addEventListener("DOMContentLoaded", on_pageload);
</script> </script>
@ -330,7 +340,7 @@ def make_thumbnail(photo):
(image_width, image_height) = image.size (image_width, image_height) = image.size
(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=85) image.save(small_name.absolute_path, quality=75)
print(small_name) print(small_name)
return small_name return small_name