jmbuhr / quarto-molstar

Shortcode to embed proteins and trajectories with Mol*
https://jmbuhr.de/quarto-molstar/
MIT License
42 stars 4 forks source link

Local files aren't moved with website building. #7

Open BradyAJohnston opened 2 years ago

BradyAJohnston commented 2 years ago

An issue I was running into while trying to get the snapshots working in #6 , was that when trialling it on a quarto blog, while the molstar.molj file was in the correct location with the original index.qmd document, upon actual rendering of the website with quarto render or quarto preview everything was copied to the docs folder, but the molstar.molj was left behind and thus broke the URL.

Is there a way to mark specific files inside of the Lua / Pandoc to be treated as assets by Quarto? I assume that would fix the problem. Similar to what is done with images and other assets already inside of Quarto.

kjelljorner commented 2 years ago

I think the resources option under the project key would be one way to do this: https://quarto.org/docs/reference/projects/core.html

BradyAJohnston commented 2 years ago

Ah yes that fixes it! Having

resources: molstar.molj

in the header YAML fixes it. Can be on a single document basis as well.

I think we'll need to put this into the docs as well, as currently local .pdb or .xtc files break as well for blog posts.

jmbuhr commented 2 years ago

Ideally, we would do this automatically in the shortcode. Shortcodes do get the yaml metadata e.g. https://github.com/jmbuhr/quarto-molstar/blob/7192d5d1725bf84ec807dd13e1280d87854e7982/_extensions/molstar/molstar.lua#L214 but I think they can't modify it.

Regular filters on the other hand could operate on the metadata, but this would require additional parsing for the shortcodes and their content, which feels a bit convoluted and I am not sure about the order of resource discovery and filters. I will ask the quarto devs if they have a more elegant solution.

jmbuhr commented 2 years ago

When we add automatic addition of resources it will only work for those explicitly mentioned in the shortcode. For snapshots such as molstar.molj we will have to ask the user to add the resources manually, unless we want to parse the snapshot files.

Oh, wait, actually, this won't we too hard. If .molj is really just plain text json, we can use https://quarto.org/docs/extensions/lua.html#json-encoding!

BradyAJohnston commented 2 years ago

Would this run before or after the files are moved / rendered into another directory?

local molj = quarto.json.decode(readFile(url))

If after we still run into the same problem as before

jmbuhr commented 2 years ago

For self-included filters one can specify if they should run before or after the quarto filter: https://quarto.org/docs/extensions/filters.html#activating-filters, but I am not sure if this is possible to specify for shortcodes and within an extension. And as it turns out my first instinct that resources would be handled by one of the quarto builtin lua filters is wrong anyways. It is handled by their typescript code: https://github.com/quarto-dev/quarto-cli/blob/aa8d33fa2b873e5f8e73ecfdc1582ee3c94236d0/src/command/render/render.ts via https://github.com/quarto-dev/quarto-cli/blob/aa8d33fa2b873e5f8e73ecfdc1582ee3c94236d0/src/command/render/resources.ts

I think the resources processing happens after pandoc's render, so after the filters.

jmbuhr commented 2 years ago

The coresponding question to the quarto devs is at: https://github.com/quarto-dev/quarto-cli/discussions/1938

jmbuhr commented 2 years ago

Looks like quarto.doc.addHtmlDependency should work to add resources at runtime as well :)