Skip to content

Commit 1593f57

Browse files
authored
Merge pull request #32 from open-rpc/fix/sidebarpos
fix: reorder sidebar position in sidebar.ts
2 parents be3a914 + cc281e4 commit 1593f57

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

docs-releases/sidebars.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
import type {SidebarsConfig} from '@docusaurus/plugin-content-docs';
2+
import {readdirSync} from 'node:fs';
3+
import {fileURLToPath} from 'node:url';
4+
import semver from 'semver';
5+
6+
// Order release docs by descending semver precedence (newest on top). Built
7+
// explicitly here rather than via sidebar_position frontmatter so arbitrary
8+
// prereleases sort correctly and new release files are picked up automatically.
9+
const dir = fileURLToPath(new URL('.', import.meta.url));
10+
const releaseDocs = readdirSync(dir)
11+
.filter((f) => f.endsWith('.md') && f !== 'index.md')
12+
.map((f) => f.replace(/\.md$/, ''))
13+
.filter((id) => semver.valid(id.replace(/^v/, '')))
14+
.sort((a, b) => semver.rcompare(a, b));
215

316
const sidebars: SidebarsConfig = {
4-
releasesSidebar: [{type: 'autogenerated', dirName: '.'}],
17+
releasesSidebar: ['index', ...releaseDocs],
518
};
619

720
export default sidebars;

scripts/sync-release-note.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { join } from "node:path";
99
import { argv, env, exit } from "node:process";
1010

11+
1112
const flags = {};
1213
for (let i = 2; i < argv.length; i++) {
1314
const a = argv[i];
@@ -20,14 +21,6 @@ function slugify(s) {
2021
return String(s).replace(/[^A-Za-z0-9.+-]/g, "-");
2122
}
2223

23-
// this puts the newest releases first
24-
function sidebarPos(t) {
25-
const m = String(t).match(/^v?(\d+)\.(\d+)\.(\d+)/);
26-
if (!m) return 0;
27-
const [, maj, min, pat] = m.map(Number);
28-
return -(maj * 1_000_000 + min * 1_000 + pat);
29-
}
30-
3124
function escapeFrontmatter(s) {
3225
return String(s).replace(/"/g, '\\"');
3326
}
@@ -102,7 +95,6 @@ function buildMarkdown(r) {
10295
"---",
10396
`title: "${escapeFrontmatter(r.title)}"`,
10497
`sidebar_label: "${escapeFrontmatter(r.tag)}"`,
105-
`sidebar_position: ${sidebarPos(r.tag)}`,
10698
`slug: /${slugify(r.tag)}`,
10799
r.publishedAt ? `date: ${r.publishedAt}` : null,
108100
"---",

0 commit comments

Comments
 (0)