on master help sign in
lib: sort sidebars by weight in pagetree
33b159eMatilde Park
lib/lib.js+16−4
@@ -190,10 +190,22 @@ export function buildPageTree(path, ordering = "", content = false) {
190 })
190 })
191 .sort((a, b) => a.weight - b.weight),
191 .sort((a, b) => a.weight - b.weight),
192 children: Object.fromEntries(
192 children: Object.fromEntries(
193+ subdirs
194+ .sort((a, b) => {
195+ const aMetadata = matter(
196+ fs.readFileSync(join(path, a.name, "_index.md")),
197+ options
198+ );
199+ const bMetadata = matter(
200+ fs.readFileSync(join(path, b.name, "_index.md")),
201+ options
202+ );
203+ return aMetadata?.data?.weight - bMetadata?.data?.weight || 0;
204+ })
193− subdirs.map((subdir) => [
205+ .map((subdir) => [
194− subdir.name,
206+ subdir.name,
195− buildPageTree(join(path, subdir.name), ordering, content),
207+ buildPageTree(join(path, subdir.name), ordering, content),
196− ])
208+ ])
197 ),
209 ),
198 };
210 };
199}
211}