Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ alphabetical order):
- Sébastien Maccagnoni-Munch
- Sean Grider (@kaibutsux)
- Simon Conseil
- @stasinos
- Stefano Zacchiroli
- @subwarpspeed
- @t-animal
Expand Down
4 changes: 4 additions & 0 deletions docs/image_information.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ keys are used by Sigal to get the useful informations on the gallery:
- *Title*: the image title.
- *Date*: the file date, useful when it cannot be read from the EXIF metadata,
e.g. for videos and some image formats.
- *Lat* and *Lon*: geo-location for positioning the image on map galleries.
Note that this overrides EXIF coordinates, so except for localizing when
EXIF cooredinates are missing it can also be used to localize the image
based on what is depicted instead of where the camera was standing.

Any additional meta-data is available in the templates. For instance::

Expand Down
12 changes: 11 additions & 1 deletion src/sigal/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Copyright (c) 2017 - Mate Lakat
# Copyright (c) 2018 - Edwin Steele
# Copyright (c) 2021 - Tim AtLee
# Copyright (c) 2024 - Stasinos Konstantopoulos

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -217,7 +218,7 @@ def markdown_metadata_filepath(self):

def _get_markdown_metadata(self):
"""Get metadata from filename.md."""
meta = {"title": "", "description": "", "meta": {}}
meta = {"title": "", "description": "", "lat": "", "lon": "", "meta": {}}
if isfile(self.markdown_metadata_filepath):
meta.update(read_markdown(self.markdown_metadata_filepath))
return meta
Expand Down Expand Up @@ -286,6 +287,15 @@ def _get_markdown_metadata(self):

return meta

@cached_property
def lat(self):
return self.markdown_metadata.get("lat", {})
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the properties to return media.exif.gps.lat/lon if not available in meta ? this would avoid the if/else in the template.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that would make it impossible to write a template that prefers the EXIF coordinates.
You might not want this, IMHO.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

people can still use directly media.exif.gps. But for media.lat I think it makes sense to avoid the manual coordinates or the exif ones.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate to insist, but I feel I have to. I perceive the Python code as a considerably "deeper" layer than the templates. I expect that many users will be happy to work at the template layer but will want to avoid the Python layer. Thus, I expect that a simple, easily predictable behaviour for media.lat/lon and media.exif.gps makes it easy to write templates.

Now, if you really want to have a template without ifs, I suggest keeping meta.lat/lon as they are and adding a new set of variables that implement the fallback and a configuration option that defines preference to GPS or .md if both are present.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And, BTW, come to think of it, one of the ifs will still be needed as it might be the case that there are no coordinates at either EXIF or .md. So we will still need an if, except without the else branch.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had another idea: How about a config option that sets the order of preference between md, EXIF?
Then both ways are accessible at the template. If the option also includes a "default location" (say, 0,0 or someplace in the middle of the Pacific) then all photos are guaranteed to have a location and the template can be completely without checks. This has the advantage that photos without a location do not silently disappear but are placed at a location that the users know to mean that they have forgotten to add a location.


@cached_property
def lon(self):
"""Other metadata extracted from the Markdown index.md file."""
return self.markdown_metadata.get("lon", {})

@cached_property
def raw_exif(self):
"""If not `None`, contains the raw EXIF tags."""
Expand Down
10 changes: 9 additions & 1 deletion src/sigal/themes/default/templates/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@

var photos = [];
{% for media in album.medias %}
{% if media.exif and media.exif.gps %}
{% if media.lat and media.lon %}
photos.push({
lat: {{ media.lat }},
lng: {{ media.lon }},
url: "{{ media.thumbnail }}",
caption: "{{ media.title }}",
thumbnail: "{{ media.thumbnail }}",
});
{% elif media.exif and media.exif.gps %}
photos.push({
lat: {{ media.exif.gps.lat }},
lng: {{ media.exif.gps.lon }},
Expand Down
11 changes: 7 additions & 4 deletions src/sigal/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2011-2023 - Simon Conseil
# Copyright (c) 2024 - Stasinos Konstantopoulos

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -136,10 +137,12 @@ def read_markdown(filename):
pass
else:
output["meta"] = meta
try:
output["title"] = MD.Meta["title"][0]
except KeyError:
pass
l = MD.Meta.get("title", [])
if l: output["title"] = l[0]
l = MD.Meta.get("lat", [])
if l: output["lat"] = l[0]
l = MD.Meta.get("lon", [])
if l: output["lon"] = l[0]

return output

Expand Down