Sort usage directory by type first (#8)

1. Change name of "usage/actions", "usage/packages" to "usage/Actions" and "usage/Packages".
2. Sort usage directory by type first, so type "category" goes before "docs"

Reference from [customize-the-sidebar-items-generator](https://docusaurus.io/docs/sidebar/autogenerated#customize-the-sidebar-items-generator) and [document](https://docusaurus.io/docs/cli#docusaurus-write-translations-sitedir)

![Screen Shot 2023-05-22 at 16.22.33](/attachments/5bbc88c9-9eca-4697-84b4-b8b3c2804eb0)

Reviewed-on: https://gitea.com/gitea/gitea-docusaurus/pulls/8
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: HesterG <hestergong@gmail.com>
Co-committed-by: HesterG <hestergong@gmail.com>
This commit is contained in:
HesterG
2023-05-22 16:31:34 +08:00
committed by Lunny Xiao
parent ddebf0c3b6
commit b27f00bd97
2 changed files with 29 additions and 0 deletions

View File

@@ -4,6 +4,15 @@
const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
// order usage directory by type first
function sortItemsByCategory(items) {
// type with "category" (directory) first
const sortedItems = items.sort(function(a, b) {
return a.type.localeCompare(b.type);
})
return sortedItems;
}
/** @type {import('@docusaurus/types').Config} */
const config = {
title: 'Gitea Documentation',
@@ -39,6 +48,16 @@ const config = {
label: '1.19.3'
}
},
async sidebarItemsGenerator({defaultSidebarItemsGenerator, ...args}) {
const {item} = args;
// Use the provided data to generate a custom sidebar slice
const sidebarItems = await defaultSidebarItemsGenerator(args);
if (item.dirName !== 'usage') {
return sidebarItems;
} else {
return sortItemsByCategory(sidebarItems);
}
},
},
blog: false,
theme: {

View File

@@ -0,0 +1,10 @@
{
"sidebar.defaultSidebar.category.actions": {
"message": "Actions",
"description": "The label for category actions in sidebar defaultSidebar"
},
"sidebar.defaultSidebar.category.packages": {
"message": "Packages",
"description": "The label for category packages in sidebar defaultSidebar"
}
}