thegeeklab / hugo-geekdoc

Hugo theme made for documentation
https://geekdocs.de
MIT License
516 stars 315 forks source link

TOC-Tree sorts alphabettically instead of how the site sorts it #736

Open Miepee opened 1 year ago

Miepee commented 1 year ago

If I have a category like this:

root:
  - c
  - b
  - a

then using toc-tree will display that alphabettically instead:

root:
  - a
  - b
  - c
xoxys commented 1 year ago

The Toc-Tree shortcode is not intended to be used together with the sidebar menu. It is using the Hugo section object and creates a Toc in an alphabetic order. Therefor, any manual menu order created with the bundle menu cant be reflected by this shortcode. But maybe I misunderstand your issue.

Miepee commented 1 year ago

Oh I see. Basically the usecase I wanted to have was to have the sidebar like this:

Configuration:
  - Default settings
  - Cli Options
  - Environment variables

And then on the _index.md for the Configuration, have something like

---
title: Configuration
---
Some preamble about configuration stuff, blabla
Table of Contents:
{{<toc-tree>}}

where the table of contents would then be ordered the same way as the sidebar.

I'm honestly still a hugo noob, and also haven't looked into the codebase here at all. So I'm not sure whether it'd be worth the effort to provide a parameter to the shortcode to provide different sortings. If you feel like that's out of scope, feel free to just close this as WONTFIX, and I'll see whether i can get some personal workaround.

xoxys commented 1 year ago

If you feel like that's out of scope, feel free to just close this as WONTFIX, and I'll see whether i can get some personal workaround.

The problem is, I don't see a way how to solve it. The bundle menu is a fully customizable menu with a manual order. This manual order can't be reflected by the toc-tree shortcode.

to provide a parameter to the shortcode to provide different sortings.

How should such a parameter look like if the ordering is fully controlled by the user?

Miepee commented 1 year ago

This manual order can't be reflected by the toc-tree shortcode.

Is it not possible for the shortcode to retrieve/read the tree at data/main.yaml?

How should such a parameter look like if the ordering is fully controlled by the user?

I was thinking that, if the shortcode is unable to gather the manual order, that one might want to specify another parameter, other than the title, to order things for. For example the weight parameter, or the pages' linkTitle param. But it'd mean that the developer has to specify the main.yaml and any other extra parameters just for a table of contents to look nice.

Using weight to sort instead of the title it could maybe help for File-tree menus though.

xoxys commented 1 year ago

Is it not possible for the shortcode to retrieve/read the tree at data/main.yaml?

Sure it is but, we would have to read and loop over this YAML file every time when the toc-tree shortcode is used. Doing it once to build the main menu is one thing, but doing it quiet often for a shortcode doesn't really scale and IMO too complex for this use-case.

Using weight to sort instead of the title it could maybe help for File-tree menus though.

Definitely! Stumbled over it yesterday as well, we have this feature already for the filetree menu, and at least this logic should be added to the filetree menu as well.

Miepee commented 1 year ago

Alternative ramblings: is it possible for something very early in the building-site process to read the main.yaml, then loop over all its pages, and manually give it a weight parameter?

xoxys commented 1 year ago

manually give it a weight parameter?

Where does this value come from? However, AFAIK there is no way to manipulate Hugos Page objects to dynamically add page parameters.

Miepee commented 1 year ago

Where does this value come from?

I'd just use a running counter from 0 to however many pages there are

AFAIK there is no way to manipulate Hugos Page objects to dynamically add page parameters.

Would this not work? https://gohugo.io/variables/page/#the-param-method