apas / athena

Minimalist static blog generator written in Python
https://apas.github.io/athena/
341 stars 23 forks source link

Is there any way to add Vega-Lite graphs to the posts? #15

Closed cuchoi closed 4 years ago

cuchoi commented 5 years ago

I know this is a stretch, but was wondering if there was an easy way to add support for Vega-Lite in athena. I have seen some projects like Visdown (https://visdown.com/) that give support for Markdown to have Vega-Lite graphs, but I don't really know how much work it would be to integrate this with athena.

apas commented 5 years ago

This is interesting. Since Visdown embeds a YAML code block within a Markdown file and athena uses Pandoc to convert markdown to HTML I think the best approach would be to write a Pandoc filter. What's not clear to me about Visdown is when and how the conversion happens; from what I understand (?) it's on page load via Javascript and DOM manipulation.

Issues with this approach: when athena loads a page it's already in HTML. Ergo, whatever conversion happens needs to occur prior to page load. A "look for vis code blocks, convert to HTML, embed the generated HTML in Markdown, and then convert Markdown to HTML again" approach is at minimum problematic. Hence, the need I think for a Pandoc filter. (If I understand Visdown's mechanics correctly.)

I contacted the author and he mentioned something about a Python package; let's see.

If Visdown can be expressed as a Pandoc filter I'm open to enable it as a flag in athena. Otherwise, I don't see how I can support this.

cuchoi commented 5 years ago

That's amazing, thank you.

Also thank you for writing athena, it is a really cool static blog generator :).

cuchoi commented 5 years ago

I am reading about pandoc filters, they look promising! I am still not sure how they work. Is there a way to do something like this?

Write the following markdown: [altair](dir/to/json/graph.json) Then is could be embedded in vega-embed: https://vega.github.io/vega-lite/usage/embed.html. This seems like the one least likely to cause problems since the user only need to provide the json and athena would only need to render that. But I don't know how easy is to add the javascript dependencies and the javascript code to the final output.

Another alternative is that the Markdown could be Altair code (https://altair-viz.github.io/index.html) and then the code is passed through eval(), exported as html and then iframed.