Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Miepee opened this issue Nov 1, 2023 · 8 comments · Fixed by #771
Open

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

Miepee opened this issue Nov 1, 2023 · 8 comments · Fixed by #771

Comments

@Miepee
Copy link

Miepee commented Nov 1, 2023

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
Copy link
Member

xoxys commented Nov 1, 2023

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
Copy link
Author

Miepee commented Nov 2, 2023

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
Copy link
Member

xoxys commented Nov 2, 2023

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
Copy link
Author

Miepee commented Nov 2, 2023

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
Copy link
Member

xoxys commented Nov 2, 2023

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
Copy link
Author

Miepee commented Nov 2, 2023

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
Copy link
Member

xoxys commented Nov 2, 2023

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
Copy link
Author

Miepee commented Nov 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants