Skip to main content

Docusaurus docs in reverse order

Referring to https://docusaurus.io/docs/sidebar/autogenerated#customize-the-sidebar-items-generator page, I could've set reversing the order of posts under docs/ directory.


Configuration

It's super simple to configure the order of posts.

So, in your docusaurus.config.js, add below

// ---------------------------------- added ----------------------------------
function reverseSidebarItems(items, name) {
return items.map((item) => {
if (item.type === "category" && item.label === name) {
return { ...item, items: [...item.items].reverse() };
} else if (item.type === "category") {
return { ...item, items: reverseSidebarItems(item.items) };
}
return item;
});
}
// ---------------------------------------------------------------------------
presets: [
[
"classic",
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: {
sidebarPath: "sidebars.js",
path: "docs",
editUrl: "https://github.com/SeiwonPark/mark1/edit/main/",
// --------------------------- added ---------------------------
async sidebarItemsGenerator({
defaultSidebarItemsGenerator,
...args
}) {
const sidebarItems = await defaultSidebarItemsGenerator(args);
return reverseSidebarItems(sidebarItems, "Daily Logs"); // <------- add your docs name
},
// -------------------------------------------------------------
},
// ...

Result

So the result should be as follows:

BeforeAfter
docusaurus-default-orderdocusaurus-reverse-order
Related Links