How to get the changed file/route on the frontend part?

I am building a personal knowledge base and should release some utilities I’ve written in the process. I edit the files on Neovim or obsidian then Hugo takes care to render. I’ve done some workarounds on the obsidian part to make it possible but I think it will be worth it.

One feature I want to implement is to hook into the live reload and get the changed file, so I can redirect to the page I am editing on Obsidian. It will be opt-in as a button on the side. The problem is how can I get the changed file/route on the HTML part?

I’ve tried to hook into the LiveReload library with success. The problem is that it always reports x.js as the file.

Here is my frontend injected code on the footer of the page (body), the switch is not implemented yet because I was still on the messing around part xD.

<script>
    setTimeout(async function() {
        function Handler() {}
        Handler.prototype.reload = function(path, options) {
            console.log(path)
            console.log(options)
            return true
        }
        Handler.version = '0.1'
        Handler.identifier = "jumper"
        if (globalThis.LiveReload) {
            console.log("live reload!")
            LiveReload.addPlugin(Handler)
        } else {
            console.log("no live reload")
        }
    }, 1000)
</script>

And yeah, knowledge bases have wikilinks and I’ve found a workaroundly way to do this building a obsidian plugin.

TIL hugo do this natively via --navigateToChanged

Awesome

lol

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.