From 838ba15049fa983b51da65c05ddde088995de0a9 Mon Sep 17 00:00:00 2001 From: Stasinos Konstantopoulos Date: Tue, 22 Oct 2024 11:45:11 +0300 Subject: [PATCH] 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. --- AUTHORS | 1 + docs/image_information.rst | 4 ++++ src/sigal/gallery.py | 12 +++++++++++- src/sigal/themes/default/templates/map.html | 10 +++++++++- src/sigal/utils.py | 9 +++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 9be0cc4..27a2d4f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -53,6 +53,7 @@ alphabetical order): - Sébastien Maccagnoni-Munch - Sean Grider (@kaibutsux) - Simon Conseil +- @stasinos - Stefano Zacchiroli - @subwarpspeed - @t-animal diff --git a/docs/image_information.rst b/docs/image_information.rst index 671ed2d..8f11b02 100644 --- a/docs/image_information.rst +++ b/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:: diff --git a/src/sigal/gallery.py b/src/sigal/gallery.py index 51cb5d7..d6ed30d 100644 --- a/src/sigal/gallery.py +++ b/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.""" diff --git a/src/sigal/themes/default/templates/map.html b/src/sigal/themes/default/templates/map.html index 7d7f9e2..6b019e1 100644 --- a/src/sigal/themes/default/templates/map.html +++ b/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 }}, diff --git a/src/sigal/utils.py b/src/sigal/utils.py index 57da452..80ee3c9 100644 --- a/src/sigal/utils.py +++ b/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