Docc Plugin Hot Reload

Hello, is there any way to enable hot reload while previewing a documentation using the docc plugin? Although the changes are monitored, the browser does not automatically reload.

2 Likes

You're correct that the browser does not automatically reload in sync with the updated compilation that occurs in preview mode as the content is updated. I can definitely see the benefit in making something like this work in the future though.

2 Likes

I'm currently working with two screens, where on one I edit the documentation and on the other I have the preview running in a browser. So I have to keep changing the focus between screens to reload the browser and see the changes and I often end up reloading the editing screen by accident.

If you use Safari, you might find the following script useful. Maybe you can have your build process run it automatically, or bind it to a key in your editor, or run it automatically using entr. Change targetUrl to something appropriate for you.

The script tells Safari to reload and activate the first tab it finds whose url starts with targetUrl, or (if no such tab exists) to create and activate a tab showing targetUrl.

#!/usr/bin/osascript -lJavaScript

(() => {
    const targetUrl = 'http://localhost/your/url/here/';
    const safari = Application('Safari');
    safari.activate();

    for (const w of safari.windows()) {
        // Inspectors don't have tabs.
        if (w.currentTab() === null) {
            continue;
        }

        for (const t of w.tabs()) {
            if (t.url().startsWith(targetUrl)) {
                safari.doJavaScript('location.reload()', { in: t });

                // Activate the tab.
                w.currentTab = t;

                // Raise the window.
                w.index = 1;

                return;
            }
        }
    }

    if (safari.windows.length < 1) {
        let w = safari.Window();
        safari.windows.push(w);
    }

    let w = safari.windows[0];
    let t = safari.Tab({ url: targetUrl });
    w.tabs.push(t);
    w.currentTab = t;
    w.index = 1;
})();
1 Like