Browse Source

Use markdown metadata to provide GPS

GPS coordinates can be given in Lat,Lon fields
in the Markdown files.
These override the EXIF GPS coordinates, if
both are present.
pull/525/head
Stasinos Konstantopoulos 1 year ago
parent
commit
838ba15049
  1. 1
      AUTHORS
  2. 4
      docs/image_information.rst
  3. 12
      src/sigal/gallery.py
  4. 10
      src/sigal/themes/default/templates/map.html
  5. 9
      src/sigal/utils.py

1
AUTHORS

@ -53,6 +53,7 @@ alphabetical order):
- Sébastien Maccagnoni-Munch
- Sean Grider (@kaibutsux)
- Simon Conseil
- @stasinos
- Stefano Zacchiroli
- @subwarpspeed
- @t-animal

4
docs/image_information.rst

@ -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::

12
src/sigal/gallery.py

@ -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
@ -217,7 +218,7 @@ class Media:
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
@ -286,6 +287,15 @@ class Image(Media):
return meta
@cached_property
def lat(self):
return self.markdown_metadata.get("lat", {})
@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."""

10
src/sigal/themes/default/templates/map.html

@ -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 }},

9
src/sigal/utils.py

@ -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
@ -140,6 +141,14 @@ def read_markdown(filename):
output["title"] = MD.Meta["title"][0]
except KeyError:
pass
try:
output["lat"] = MD.Meta["lat"][0]
except KeyError:
pass
try:
output["lon"] = MD.Meta["lon"][0]
except KeyError:
pass
return output

Loading…
Cancel
Save