@@ -190,10 +190,22 @@ export function buildPageTree(path, ordering = "", content = false) {
190190 })
191191 .sort((a, b) => a.weight - b.weight),
192192 children: Object.fromEntries(
193− subdirs.map((subdir) => [
194− subdir.name,
195− buildPageTree(join(path, subdir.name), ordering, content),
196− ])
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+ })
205+ .map((subdir) => [
206+ subdir.name,
207+ buildPageTree(join(path, subdir.name), ordering, content),
208+ ])
197209 ),
198210 };
199211}