pietroppeter / nimib

nimib 🐳 - nim 👑 driven ⛵ publishing ✍
https://pietroppeter.github.io/nimib/
MIT License
175 stars 10 forks source link

New runtime option nbReload to reload the page if open ? #135

Open Kiloneie opened 1 year ago

Kiloneie commented 1 year ago

Currently nbShow opens the file in the browser after c -r, but it does not care if it is already opened, so it always opens up a new instance. Would it be possible to have a nbReload option that would reload the page instead ? Or even open the page if it's not open, and then reload on it's subsequent runs ?

HugoGranstrom commented 1 year ago

I'm not sure how this would be done, nimib would somehow have to know that a browser has the file open and then somehow request the browser to reload the page. I'm not sure if that's possible (in a simple, portable way for all browsers). There are options for you, though:

  1. Only use --nbShow on the first run and then run without it the subsequent times and reload the same page it previously opened manually.
  2. Use an automatically reloading local server (I use Live Server for VSCodium) and open the resulting HTML file using it. When you later rebuild (without --nbShow) the file, the server will notice that the HTML file has been changed and reload the page automatically for you.
  3. If you are using VSCodium/VSCode, there is a plugin nimiBoost which lets you preview the document in a preview window inside the editor. (It opens a new window each time though, but it's easier to deal with there)
Kiloneie commented 1 year ago

Live Server extension works exactly how i wanted it, thank you.

pietroppeter commented 1 year ago

in principle I think there should be a way to this in nimib without relying on an external plugin. We would need to serve the file through localhost, watch for changes and serve again. not sure if a runtime option is the best way* to do that (if it is I might want to call it --nbServe), but I guess we could keep open this issue for further brainstorming.

An automatic reload is indeed something missing in nimib that would help iterating on a document. I do not use that extension (nice to know it exists) and end up having tons of tabs open...

*although I cannot resist thinking how to implement this with a runtime option:

dlesnoff commented 1 year ago

Can we run a small local server with node.js maybe ? Github uses Jekyll (Ruby). I am not sure if we should add them as a dependency. We can simply recommend users to use their favorite one and give some examples in the README.md. It is still more a comfort feature than something mandatory. I am attached to a low count of packages and dependencies.

pietroppeter commented 1 year ago

Defintely not with nodejs ;), but likely with a simple Nim server like nimhttpd + some watch mechanism. I am not sure if this use case warrants for something more than that.