hikerpig / gatsby-project-kb

Developing gatsby-theme-kb, a Gatsby theme for publishing Knowledge Base.
https://gatsby-project-kb.vercel.app/
MIT License
61 stars 15 forks source link

Added sort by default to nodes #58

Closed jessems closed 1 year ago

jessems commented 1 year ago

By default the nodes are sorted by id, not by title or relativePath. This is a bit counter intuitive when you have a bunch of markdown files and folders with alphabetic sorting (e.g. "01 this is the first file" and "02 this is the second file") and they don't appear in the same sequence in the sidebar menu.

This little sort fixes that.

image
hikerpig commented 1 year ago

It occurred to me that sorting by relativePath will also cause some confusions because sidebar displays article title rather than file path. So it sometimes will look strange if file path and title are not the same. I think it'd be better if the sorting can be configured, but this PR itself is good enough to be merged (with the problem in my CR comment fixed of course. It's a good default behavior this way. And I will make it configurable later.

image image
jessems commented 1 year ago

Updated the pull request to sort on validNodes. And I agree with you, having the option to sort on title would be even better. I ran into a case where I needed it already.