Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .tojson() method to Album and other classes #373

Open
defeo opened this issue Aug 22, 2019 · 1 comment
Open

Add .tojson() method to Album and other classes #373

defeo opened this issue Aug 22, 2019 · 1 comment

Comments

@defeo
Copy link

defeo commented Aug 22, 2019

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)

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'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.

@saimn
Copy link
Owner

saimn commented Aug 22, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants