hugo_jupyter icon indicating copy to clipboard operation
hugo_jupyter copied to clipboard

Multiple adjustments

Open tobiasraabe opened this issue 7 years ago • 0 comments

Hey,

first of all, thanks for making this project as I was desperately in need of such a package. I scripted my own rendering for jupyter notebooks but it missed the elegance of your approach with watchdog by far.

Unfortunately, I had some problems using the latest version which were

  • unable to open the browser for jupyter (windows does not support open ...)
  • infinite building loops
  • resources (images in output fields of the notebook) were not build and not saved to the appropriate folder in hugo (static/...)

Therefore, I went through fabfile.py and made multiple adjustments. Some of them are probably due to the fact that I did not understand your implementation strategy very well. For example, why did you choose to save notebook metadata and paths in class variables of the handler? You surely have a good reason, but for my mental structure of the program, it was easier to delete this necessity.

Also, I do not mean that this PR should be merged. It is probably more appropriate that it serves as a list for some feature enhancements which are fleshed out in separate PRs.

Here is the list of new features:

  • Fix 1 implements a cross-platform solution to open jupyter in the default browser
  • Fix 2 handles events for files which should be ignored replacing the if statements
  • Fix 3 builds the markdown file to content/<post>/<slug> and resources (images), if they exist, to static/<post>/resources/<slug>
  • Fix 4 implements a toc field which yields "true" by default. But this highly depends on your custom toc.html partial
  • Fix 5 rewrites NotebookHandler. The problem with using watchdog is that it does detect when a file is modified by its own function calls which means that if the notebook is altered because metadata is added, a modified file event is raised. Two cases can occur: First, a notebook is created, then we need to update the metadata which will raise a file modified event. Second, if a notebook is modified, then we need to distinguish the cases in which the metadata is present or not. Updating the metadata will results in another call of on_modified, but if the metadata is present, the notebook will be processed. This should eliminate the problem of infinite loops.

But there are also some unfixed problems with my approach:

  • notebooks are forced to be named with the slug as it simplifies the deletion process if the notebook is deleted.
  • when notebooks are deleted or modified, the render-to field is lost or potentially modified. Therefore, program will loop through content/post, content/blog and static/resources/post, static/resources/blog to remove all files identified by the slug.
  • I put a sleep statement in on_modified which is an ugly hack to prevent errors when files are already used by other processes

Again, thanks for your work and I hope this helps you too!

tobiasraabe avatar Feb 03 '18 17:02 tobiasraabe