[browse function] Display folders first

is there a way to display folders first in the browse function?

Not currently… what is the use case for this?

well for navigation with the browsing this might make it easier for some (including me) especially considering that many file explorers do the same.

You could do this naively by simply writing your own template that puts dirs first - would fail on pagination though, but fine for small directory listings (for some value of small)

1 Like

Order by size. Folder size is artificially set below 0, so they will be listed on top.

3 Likes

well yeah but then the files are ordered by size.
I would like it by name and folders first, like for example in windows explorer

1 Like

I would agree that ordering by Folder Name then by File Name would be standard everywhere except in shell systems. Github and most other web based representations of file systems would do this. See https://github.com/mholt/caddy to see folders first at top.

@my1 You could raise it as an issue in github and if we can come to a concensus it might get implemented.

1 Like

Any polls conducted using Github will be flawed: Not everyone relevant will be asked, and the issue is only seen by maintainers and those made aware of it. Maintainer’s stance will be neutral (experienced maintainers are more likely less inclined to entertain changes), and the participants’ will be mostly pro-change. Those are the usual dynamics. :slight_smile:

I for one have never understood why something like “glibc_2.25.deb” should be listed after a folder “glibc6_2.24”. (The proposed new order.) Not only indicates a similar name something comparable, folder or not, so any other dimension should be secondary (most filesystems don’t allow duplicate names, so said dimension will become irrelevant), I’d like to have semantically similar items close to each other.

The informatician in me argues that the old order allows to spot a file in O(log n), the new one in worse O(k·log n). For aesthetic reasons, which can be achieved by a custom template.

The developer in me says: We will be adding complexity.

The engineer in me argues that cost–benefits will be negative. (Mind opportunity costs and cost of interruptions.)

why not make it an option, that way ppl can choose…

also, how is a template, which as far as I have seen templates, only have style and placeholders, but no programmatical impact on the script running it and the script working on the template essentially just fills in the placeholders, supposed to change the order of what comes in?

Adds even more complexity and duplication.

An engineers goal is not to add, but to remove. :wink:

{{- range .Items}}
{{- if .IsDir }}
{{- end }}
{{- end}}

{{- range .Items}}
{{- if not .IsDir }}
{{- end }}
{{- end}}

See also:

I see I no longer own browse — but I hope the above examples help you getting started.

okay. this is intresting, usually as far as I have experienced templates essentially have just HTML and placeholders to get filled and that’s it.
but the problem that @thechriswalker said, the pagination, may persist, although I have no Idea how many items it needs to trigger the paging.

@wmark I dont think I was suggesting poll based on github, I was simply using the link to show that github lists folders first then files. I was saying really was that almost all UI representations of Folders and Files show folders first and then files. The exception to this is shell / command line systems which on both windows and linux show all files and folders in alphabetical order.

I do agree however that there should not be an option to do this in the Caddyfile (maybe possible as a template option) as it would add unneeded complexity.

My personal vote would be to change the default sort order to Folders then files all in alphabetical order, mainly because that is the way I expect to see it.

1 Like

Sorry, I cannot find anything about pagination in the source code. It’d go after any sorting, but there’s only limiting the number of elements returned.

okay, I just considered what @thechriswalker said.

where the limit is queried from URL

https://github.com/mholt/caddy/blob/36d2027493a65e76463d7075d37cd0a139dcb7f7/caddyhttp/browse/browse.go#L336

where the limit is applied to listing

https://github.com/mholt/caddy/blob/36d2027493a65e76463d7075d37cd0a139dcb7f7/caddyhttp/browse/browse.go#L401

default value is “no limit”

I’ve been one of the contributors who refactored browse. :wink:

Pagination ≠ limiting how many entries get displayed. Above still applies.

I hope the examples I’ve provided above help you getting started.

1 Like

OK I give you that, but if you do limit then you don’t necessarily get all the directory’s in the limited list, so displaying directories first in a 2-pass template (as I suggested) would still get you misleading results.

That’s all I was trying to get at.

1 Like

https://github.com/mholt/caddy/pull/1527

1 Like

@tobya oh nice, thanks for making that.

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