QuantEcon / sphinxcontrib-jupyter

A Sphinx Extension for Generating Jupyter Notebooks
BSD 3-Clause "New" or "Revised" License
77 stars 23 forks source link

URL Prefixes for static content #116

Closed arnavs closed 6 years ago

arnavs commented 6 years ago

One of the things @jlperla and I are working on in preparation for teaching is to remove dependence on local files in rst_files/_static/. Ideally we could just swap out the prefix in _static (that is, self.confdir + _static) with something like https://raw.githubusercontent.com/QuantEcon/lecture-source-jl/master/rst_files/, and then add a Jupinx setting.

For example, if we use commands like .. figure:: https://raw.githubusercontent.com/QuantEcon/lecture-source-jl/master/rst_files/_static/figures/arellano_bond_prices.png and swallow the exceptions thrown by Jupinx, then we get the desired behavior.

cc: @mmcky

jlperla commented 6 years ago

Yes. And, just to be clear, with a URL prefix you don't need to copy the files at all so I suspect that whole copy_asset could be skipped.

mmcky commented 6 years ago

Does anyone know if github has any rate limits for accessing raw files?

I know there is a limit of 5000 requests per hour on the general api. https://developer.github.com/v3/#rate-limiting

if the site pulls from raw.githubusercontent.com each time the site is loaded we may hit some github limits which could prevent images from loading. Just want to rule this out before implementing this.

mmcky commented 6 years ago

I think it would probably be better to embed the files in the notebook as attachments. https://nbformat.readthedocs.io/en/latest/format_description.html#cell-attachments

Can you remind me if there is a reason not to go this way?

I think it is better to be self contained then to link to images on an external service.

jlperla commented 6 years ago

Yes, if they are links, it should be to the hosted mages for the HTML site as opposed to github directly. But with a sphinx setting the prefix url could be swapped out in different builds.

I don't know jupyter well enough to know if cell attachments are a good idea, but I do know that:

mmcky commented 6 years ago

Yes, if they are links, it should be to the hosted mages for the HTML site as opposed to github directly. But with a sphinx setting the prefix url could be swapped out in different builds.

OK I see - so we will need to copy the static assets to the s3 hosting bucket anyway but we could add links in the notebooks as html calls rather than relative links.

jlperla commented 6 years ago

Yeah, that was my thinking... maybe there is a better way. Regardless, I don't think offline use of the notebooks is worth the trouble of embedding the static assets.

mmcky commented 6 years ago

PR submitted to allow this. @jlperla I have left the copy assets in place as it is useful having the _static folder to copy to the server.