From 05b43ecdb55dd05713483754a57d4154dbd07fb4 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Mon, 28 Apr 2025 10:50:02 +0300 Subject: [PATCH] docs-util: add sidebar link validation in prep script (#12306) --- .../build-scripts/src/generate-sidebar.ts | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/www/packages/build-scripts/src/generate-sidebar.ts b/www/packages/build-scripts/src/generate-sidebar.ts index 8fffce672d..584abda5c7 100644 --- a/www/packages/build-scripts/src/generate-sidebar.ts +++ b/www/packages/build-scripts/src/generate-sidebar.ts @@ -144,9 +144,7 @@ async function getAutogeneratedTagSidebarItems( return items } -async function checkItem( - item: Sidebar.RawSidebarItem -): Promise { +function validateItem(item: Sidebar.RawSidebarItem): void { if (!item.type) { throw new Error( `ERROR: The following item doesn't have a type: ${JSON.stringify( @@ -156,9 +154,6 @@ async function checkItem( )}` ) } - if (item.type === "separator") { - return item - } if (item.type === "sidebar" && !item.sidebar_id) { throw new Error( `ERROR: The following sidebar item doesn't have a sidebar_id: ${JSON.stringify( @@ -168,6 +163,25 @@ async function checkItem( )}` ) } + if (item.type === "link" && !item.path) { + throw new Error( + `ERROR: The following link item doesn't have a path: ${JSON.stringify( + item, + undefined, + 2 + )}` + ) + } +} + +async function checkItem( + item: Sidebar.RawSidebarItem +): Promise { + if (item.type === "separator") { + return item + } + + validateItem(item) if (item.children) { item.children = await checkItems(item.children)