icyphox / legit

web frontend for git
https://git.icyphox.sh
MIT License
376 stars 25 forks source link

Traversing subdirectories #16

Open daenney opened 1 year ago

daenney commented 1 year ago

First off, thanks for legit, it's rather neat!

I was looking at how to make it support traversing subdirectories and so far I have the necessary infrastructure in place that would let me do this, including being able to limit the recursion depth.

The problem I'm running into is flow and its URL path handling:

mux.HandleFunc("/:name", d.Multiplex, "GET", "POST")

Unsurprisingly, /:name only captures a single segment. But when you have subdirectories you need either /:parent/:name or /:name. If I can assume there's only max 1 parent this can be solved without much trouble. But if there's a desire to allow for an arbitrary path depth it becomes problematic as the wildcard ... can only be used once and only at the end of a path. I'm not sure how to consume multiple path segments.

I'm wondering if you've given any thought around how to solve this?

icyphox commented 1 year ago

Thanks!

I have indeed been thinking about this (or rather, something adjacent to this) for a bit. I was looking to implement "directories as categories", similar to cgit's section-from-path configuration option. Essentially, if you've got a tree that looks like:

repos/
├── category1/
│   ├── foo
│   └── bar
└── category2/
    ├── baz
    └── ...

they'd then show up under those respective subheadings in the repo index. A visual example for what I'm describing can be seen in this cgit instance: https://git.peppe.rs (notice "cli", "config", ...).

With that preface out of the way,

If I can assume there's only max 1 parent this can be solved without much trouble.

this is a fair assumption. Having one level of traversal was also what I had in mind for the above feature.

lillian-b commented 5 months ago

I have a basic implementation of "directories as categories", but it doesn't work well with also having top-level repositories. Right now my implementation (here, links are broken except from index) uses _ in url to denote a repo in the root folder - but that's not a very clean solution.

cgit does support this mode of displaying repositories, but from what I can tell, it does not actually traverse subdirectories and rather is just a per-repo configuration in cgitrc.

If anyone has an idea of how to implement this (I did try simply having both /{pre}/{name} and /{name} endpoints registered, but they conflicted), I'm happy to do the implementation work.

icyphox commented 5 months ago

Hi, so there's an existing PR that implements category support but in its current state it breaks clones. I haven't quite figured out how to make it work but perhaps it might serve as a starting point?

lillian-b commented 5 months ago

I'll take a look at that, thanks!