From 84369b1c552611083c79530c81fa486e78392675 Mon Sep 17 00:00:00 2001 From: Zane Starr Date: Tue, 9 Jun 2026 21:23:30 -0700 Subject: [PATCH] fix: reorder sidebar position in sidebar.ts This change reorders the sidebar positions to respect full semver path. --- docs-releases/sidebars.ts | 15 ++++++++++++++- scripts/sync-release-note.js | 10 +--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs-releases/sidebars.ts b/docs-releases/sidebars.ts index d1b9a1c77..e969be14f 100644 --- a/docs-releases/sidebars.ts +++ b/docs-releases/sidebars.ts @@ -1,7 +1,20 @@ import type {SidebarsConfig} from '@docusaurus/plugin-content-docs'; +import {readdirSync} from 'node:fs'; +import {fileURLToPath} from 'node:url'; +import semver from 'semver'; + +// Order release docs by descending semver precedence (newest on top). Built +// explicitly here rather than via sidebar_position frontmatter so arbitrary +// prereleases sort correctly and new release files are picked up automatically. +const dir = fileURLToPath(new URL('.', import.meta.url)); +const releaseDocs = readdirSync(dir) + .filter((f) => f.endsWith('.md') && f !== 'index.md') + .map((f) => f.replace(/\.md$/, '')) + .filter((id) => semver.valid(id.replace(/^v/, ''))) + .sort((a, b) => semver.rcompare(a, b)); const sidebars: SidebarsConfig = { - releasesSidebar: [{type: 'autogenerated', dirName: '.'}], + releasesSidebar: ['index', ...releaseDocs], }; export default sidebars; diff --git a/scripts/sync-release-note.js b/scripts/sync-release-note.js index 74d70cb84..8e8ec55b8 100644 --- a/scripts/sync-release-note.js +++ b/scripts/sync-release-note.js @@ -8,6 +8,7 @@ import { import { join } from "node:path"; import { argv, env, exit } from "node:process"; + const flags = {}; for (let i = 2; i < argv.length; i++) { const a = argv[i]; @@ -20,14 +21,6 @@ function slugify(s) { return String(s).replace(/[^A-Za-z0-9.+-]/g, "-"); } -// this puts the newest releases first -function sidebarPos(t) { - const m = String(t).match(/^v?(\d+)\.(\d+)\.(\d+)/); - if (!m) return 0; - const [, maj, min, pat] = m.map(Number); - return -(maj * 1_000_000 + min * 1_000 + pat); -} - function escapeFrontmatter(s) { return String(s).replace(/"/g, '\\"'); } @@ -102,7 +95,6 @@ function buildMarkdown(r) { "---", `title: "${escapeFrontmatter(r.title)}"`, `sidebar_label: "${escapeFrontmatter(r.tag)}"`, - `sidebar_position: ${sidebarPos(r.tag)}`, `slug: /${slugify(r.tag)}`, r.publishedAt ? `date: ${r.publishedAt}` : null, "---",