til-schneider / slim-wiki

A slim wiki based on PHP and markdown
MIT License
13 stars 7 forks source link

For missing /subdir/index.md fall back to /subdir.md if it exists? #16

Open DivineDominion opened 2 years ago

DivineDominion commented 2 years ago

When a less tech-savvy friend for whom I set up Slim Wiki encountered how subfolders work, he was confused by the fact that old pages were forgotten. Here's a procedure description so you see what I mean:

The file tree at that point is:

├── index.md
├── subdir
│   └── detail.md
├── subdir.md

So when you browse /subdir, Slim Wiki says the file is missing because it's looking for /subdir/index.md in the file system.

In that case, I would suggest to either fall-back to the overshadowed /subdir.md, or recognize this special case and offer to move /subdir.md to /subdir/index.md with the click of a button. The latter is not as magical, but probably more robust because the editor doesn't need to change file lookup routines.

To the end user, it appears that the content at /subdir is lost. But you have to change the file into a directory index file and then everything's alright. At the moment, though, this is rather panic inducing for organically growing wiki users :)


@til-schneider What do you think about this?

til-schneider commented 2 years ago

I think, moving /subdir.md to /subdir/index.md would be best. This way, the file system doesn't end up in several directories which handle this differently, just because they happend to be created the one or the other way.

DivineDominion commented 2 years ago

@til-schneider Do you fancy any particular way to implement this? I'd suggest showing a different placeholder text than "this page doesn't exist":

Found a file with a similar name at `/subdir.md` that is overshadowed by this directory.
You can move that file into this directory as `/subdir/index.md`.

[Import file as directory index]

And when you click the button, well, it'll move the file :)

til-schneider commented 2 years ago

I would rather just move the file and hide this technical detail to the user. So the user just sees the moved page.

til-schneider commented 2 years ago

Oh, wait! Doesn't this break all the relative links?

If yes, we should probably keep the /subdir.md file and detect this case when looking up the page.

DivineDominion commented 2 years ago

Right -- It would break any link where the optional file suffix .md is used! I didn't realize that this even works to disambiguate the paths. Neat, so the file is still accessible.

So: if /subdir/index.mdis not found, look for /subdir.md and display that instead?

til-schneider commented 2 years ago

Yes: If /subdir/index.md is not found, look for /subdir.md and display that instead.

til-schneider commented 2 years ago

I'm still not quite sure whether relative links are an issue or not... In the end both /subdir/index.md and /subdir.md will get the same URL /subdir, right? So relative links should work just the same? I think this needs some testing first.

DivineDominion commented 2 years ago

Relative links are resolved as absolute paths before the file is read when the GET request is being made, so at that point we should be able to have a canonical way to make this decision.

I played around with the code a bite (see PR's :)) and will be taking a jab at implementing this next week or so.