简体   繁体   English

Docusaurus 如何确定侧边栏中标题的顺序?

[英]How does Docusaurus determine the order of headings in the sidebar?

In my Docusaurus project, I have created a new sidebar in sidebars.json and added some files and it shows up nicely, except it is not ordering the way I have ordered it in the json file.在我的 Docusaurus 项目中,我在 sidebars.json 中创建了一个新的侧边栏并添加了一些文件,它显示得很好,只是它的排序方式与我在 json 文件中的排序方式不同。

My new sidebar is a list of dates and the files associated with those dates.我的新侧边栏是日期列表以及与这些日期相关的文件。 So I thought maybe it was due to the categories being numbers.所以我想可能是因为类别是数字。 So I tried renaming them to something with letters like "Current Year", but that didn't work.所以我尝试将它们重命名为诸如“当前年份”之类的字母,但这不起作用。 I also tried rearranging them in the Json file, but that also did not work.我也尝试在 Json 文件中重新排列它们,但这也不起作用。

"WhatsNew": {
    "2019": ["Current Month", "January 2019"], 
    "2018": ["December 2018", "November 2018", "October 2018", "September 
             2018", "August 2018", "July 2018", "June 2018", "May 2018", 
             "April 2018", "March 2018", "February 2018", "January 2018"],
    "2017": ["December 2017"]
  }, 

I would expect the side nav to be ordered as I have it in the json file, but instead it is ordered the opposite to how it is ordered in the json file.我希望侧面导航按照我在 json 文件中的顺序进行排序,但它的排序方式与 json 文件中的排序方式相反。 Instead of starting with 2019, it starts with 2017.它不是从 2019 年开始,而是从 2017 年开始。

I'm afraid there's no good way to fix this now.恐怕现在没有什么好办法可以解决这个问题。 This is because keys in JavaScript have no fixed ordering and this is something Docusaurus has to address in v2.这是因为 JavaScript 中的键没有固定的顺序,这是 Docusaurus 在 v2 中必须解决的问题。

One very ugly hack I can suggest to you is to add a space in front of your keys as such:我可以向您建议的一个非常丑陋的 hack 是在您的键前面添加一个空格,如下所示:

"WhatsNew": {
  " 2019": ["Current Month", "January 2019"], 
  " 2018": ["December 2018", "November 2018", "October 2018", "September 
         2018", "August 2018", "July 2018", "June 2018", "May 2018", 
         "April 2018", "March 2018", "February 2018", "January 2018"],
  " 2017": ["December 2017"]
},

and they will appear in the order you defined it.它们将按照您定义的顺序出现。 Hopefully the space isn't noticeable.希望空间不明显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM