Replies: 1 comment
-
One way to do this would be to let people provide a function to a toc entry that used glob, where the function would help you sort the entries. For example similar to python lambda sorting https://stackoverflow.com/a/3766636 Another option would be to just allow for special cases like a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey all! I really hate hand-managing my table-of-contents, so I usually start omitting a
toc
and settingfolders: true
, and structure my documents the way I want my website to be structured. But sometimes the filename-to-slug transformation gets me in a bind.For example, I want to have a bunch of pages representing events, and I want those pages to be listed chronologically from newest at the top to oldest at the bottom, and I want the slugs to look like
{YYYYMM}-{location}
. E.g.202508-berkeley
.If I name my files with that pattern e.g.
202508-berkeley.md
, the slug looks correct but they will be sorted in the opposite direction I desire. If I prefix them with a number, e.g.99-202508-berkeley.md
, then I can get the order I want by decrementing the prefix with each new event, but all the numbers at the beginning get stripped off and my slug becomesberkeley
. If I have multiple Berkeley events, a future slug will beberkeley-1
.I was thinking that a valid solution for me would be to be able to override the autogenerated slug in frontmatter, e.g. in a file name
99-202508-berkeley.md
:Or perhaps altering the filename transformation algorithm to only strip consecutive digits from the filename, so
99-202508-berkeley.md
->202508-berkeley
.Or, maybe we should work towards enabling auto-generated TOCs to be more customizable and understandable (I find the autogenerated TOC behavior to require remembering a lot of little facts). I'm not sure how much of the legacy Sphinx toc directive support is still around and how it interacts with autogenerated tocs based on file hierarchy, but I keep finding myself wanting the ability to exert more control on the toc generation. Being able to specify in a directive that "this directory's contents are included in the toc by glob, and are sorted by the
date
field in the frontmatter", for example. Relevant: #1933Are there other solutions to this problem I might not be aware of? Other ideas about how to enable the behavior I'm looking for?
I'd love to hear others' thoughts!
Beta Was this translation helpful? Give feedback.
All reactions