For writing themes based on purely frontend technologies (e.g., VueJS), it would be useful if the Gallery, Album, etc. classes could be easily serialized to JSON.
Jinja supports a tojson filter, which is based on Python's default json module, however most of the data passed to templates in the album dict is not JSON-serializable, thus leading to writing ugly code such as (never mind the early draft, plz)
It is not easy to hook into the way the json module serializes objects: having Jinja's tojson work with the Album class would require changes to Jinja's code. Thus I believe the simplest solution would be to add a tojson() method to these classes in Sigal.
If we can agree on a course of actions, I am willing to write a pull request.
Hi,
Interesting, I need to think a bit more about it but it seems a good idea. The galleria theme already use some json serialization so we could maybe use this as well.
For writing themes based on purely frontend technologies (e.g., VueJS), it would be useful if the
Gallery
,Album
, etc. classes could be easily serialized to JSON.Jinja supports a
tojson
filter, which is based on Python's defaultjson
module, however most of the data passed to templates in thealbum
dict is not JSON-serializable, thus leading to writing ugly code such as (never mind the early draft, plz)https://github.com/defeo/sigal-theme/blob/68e3dae1e7a1b94578626d9d587aca3cded1a3cc/templates/album.html#L16-L49
It is not easy to hook into the way the
json
module serializes objects: having Jinja'stojson
work with theAlbum
class would require changes to Jinja's code. Thus I believe the simplest solution would be to add atojson()
method to these classes in Sigal.If we can agree on a course of actions, I am willing to write a pull request.