xy2z / PineDocs

A fast and lightweight site for viewing files
GNU General Public License v3.0
141 stars 19 forks source link

Relative path for images #228

Closed Mylloon closed 2 years ago

Mylloon commented 2 years ago

Closes #170.

Certainly not the cleanest way to do it, but it works

xy2z commented 2 years ago

Decent solution.

Just a couple thoughts:

This could even be used for <audio> and <video> in the future. But this could be done in the future.

Maybe this could use cache so it doesn't call ajax again every time you switch pages and back, if the page is already loaded. But I'm not sure when it will be too much for JS memory. If the file is already loaded it can be added to the "loaded" variable and checked like this.

if (self.loaded[href]) {
    window.location.hash = href
    self.render_file(self.loaded[href])
    return
}

Then it will also be cached if the image was already rendered alone. And to further lower traffic, it could keep a list of all images (urls) that didnt exist in pinedocs, so it won't keep doing unnessary ajax calls if the user navigates back to the same page.

But you don't have to do this now, just let me know and I will still merge it, and create issues for the notes.


But I just tested the code and it doesn't work if you are not in a directory, eg. "index.md". Seems like the regex expects a "/".

This fails: /(.*\/)/g.exec("index.md")[0]

Mylloon commented 2 years ago

Ok I'll take a look tomorrow

Mylloon commented 2 years ago

This could even be used for <audio> and <video> in the future. But this could be done in the future.

Done

If the file is already loaded it can be added to the "loaded" variable

Done

And to further lower traffic, it could keep a list of all images (urls) that didnt exist in pinedocs, so it won't keep doing unnessary ajax calls if the user navigates back to the same page.

I added a black_list variable so a stuff that don't exist only make one request

This fails: /(.*\/)/g.exec("index.md")[0]

Fixed

I tried to solve the accessibility problem by putting the file name as an alternative text but the bot disagree 😅

xy2z commented 2 years ago

Thanks!