munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.87k stars 1.04k forks source link

[Web] Improve UX of current location #1072

Open grouma opened 2 years ago

grouma commented 2 years ago

The web version of the book has support for deep links through a # URL scheme, e.g. https://craftinginterpreters.com/scanning.html#the-interpreter-framework. However, the web page does not update the URL as you scroll through the book and therefore can become out of sync (see image below).

It would also be great if the sidebar nav links also changed state depending on the current location. They already support a hover styling which likely would be sufficient.

The points mentioned above are highlighted in red for clarity: Screenshot 2022-07-24 10 48 52 PM

grouma commented 2 years ago

I was curious how I'd implement this support and found this JSFiddle that is likely helpful. Probably need to use window.history.pushstate as well. Probably easy to stuff here.