diff --git a/www/apps/book/config/sidebar.tsx b/www/apps/book/config/sidebar.tsx index 392a601721..599f04de64 100644 --- a/www/apps/book/config/sidebar.tsx +++ b/www/apps/book/config/sidebar.tsx @@ -1,26 +1,8 @@ -import { Badge } from "docs-ui" -import type { SidebarConfig, SidebarItem } from "@/types" -import { sidebar } from "../sidebar.mjs" - -const soonBadge = Soon - -const normalizeSidebarItems = (items: SidebarItem[]) => - items.map((item) => { - if (item.type === "separator") { - return item - } - if (item.isSoon) { - item.additionalElms = soonBadge - } - - if (item.children) { - item.children = normalizeSidebarItems(item.children as SidebarItem[]) - } - - return item - }) +import type { SidebarConfig } from "@/types" +import { generatedSidebar } from "../generated/sidebar.mjs" +import { SidebarItem } from "types" export const sidebarConfig: SidebarConfig = { - default: normalizeSidebarItems(sidebar), + default: generatedSidebar as SidebarItem[], mobile: [], } diff --git a/www/apps/book/generated/sidebar.mjs b/www/apps/book/generated/sidebar.mjs new file mode 100644 index 0000000000..ff0ce9c7bf --- /dev/null +++ b/www/apps/book/generated/sidebar.mjs @@ -0,0 +1,983 @@ +export const generatedSidebar = [ + { + "type": "category", + "title": "1. Introduction", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn", + "title": "Introduction", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/installation", + "title": "Installation", + "children": [], + "chapterTitle": "1.1. Installation" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Architecture", + "path": "/learn/introduction/architecture", + "children": [], + "chapterTitle": "1.2. Architecture" + } + ], + "childrenSameLevel": true, + "chapterTitle": "1. Introduction" + } + ], + "loaded": true, + "initialOpen": false + }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "2. Customize", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Build Custom Features", + "path": "/learn/customization/custom-features", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Brand Module", + "path": "/learn/customization/custom-features/module", + "children": [], + "chapterTitle": "2.1.1. Brand Module" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Brand Workflow", + "path": "/learn/customization/custom-features/workflow", + "children": [], + "chapterTitle": "2.1.2. Brand Workflow" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Brand API Route", + "path": "/learn/customization/custom-features/api-route", + "children": [], + "chapterTitle": "2.1.3. Brand API Route" + } + ], + "chapterTitle": "2.1. Build Custom Features" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Extend Features", + "path": "/learn/customization/extend-features", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Link Brands and Products", + "path": "/learn/customization/extend-features/define-link", + "children": [], + "chapterTitle": "2.2.1. Link Brands and Products" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Extend Core Flow", + "path": "/learn/customization/extend-features/extend-create-product", + "children": [], + "chapterTitle": "2.2.2. Extend Core Flow" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Query Linked Records", + "path": "/learn/customization/extend-features/query-linked-records", + "children": [], + "chapterTitle": "2.2.3. Query Linked Records" + } + ], + "chapterTitle": "2.2. Extend Features" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Customize Admin", + "path": "/learn/customization/customize-admin", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Add Widget", + "path": "/learn/customization/customize-admin/widget", + "children": [], + "chapterTitle": "2.3.1. Add Widget" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Add UI Route", + "path": "/learn/customization/customize-admin/route", + "children": [], + "chapterTitle": "2.3.2. Add UI Route" + } + ], + "chapterTitle": "2.3. Customize Admin" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Integrate Systems", + "path": "/learn/customization/integrate-systems", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "CMS Module", + "path": "/learn/customization/integrate-systems/service", + "children": [], + "chapterTitle": "2.4.1. CMS Module" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Sync to CMS", + "path": "/learn/customization/integrate-systems/handle-event", + "children": [], + "chapterTitle": "2.4.2. Sync to CMS" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Schedule Syncing", + "path": "/learn/customization/integrate-systems/schedule-task", + "children": [], + "chapterTitle": "2.4.3. Schedule Syncing" + } + ], + "chapterTitle": "2.4. Integrate Systems" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Next Steps", + "path": "/learn/customization/next-steps", + "children": [], + "chapterTitle": "2.5. Next Steps" + } + ], + "chapterTitle": "2. Customize" + }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "3. Fundamentals", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/medusa-container", + "title": "Medusa Container", + "children": [], + "chapterTitle": "3.1. Medusa Container" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules", + "title": "Modules", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules/modules-directory-structure", + "title": "Modules Directory Structure", + "children": [], + "chapterTitle": "3.2.1. Modules Directory Structure" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules/loaders", + "title": "Loaders", + "children": [], + "chapterTitle": "3.2.2. Loaders" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules/isolation", + "title": "Module Isolation", + "children": [], + "chapterTitle": "3.2.3. Module Isolation" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules/container", + "title": "Module Container", + "children": [], + "chapterTitle": "3.2.4. Module Container" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules/options", + "title": "Module Options", + "children": [], + "chapterTitle": "3.2.5. Module Options" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules/service-factory", + "title": "Service Factory", + "children": [], + "chapterTitle": "3.2.6. Service Factory" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules/service-constraints", + "title": "Service Constraints", + "children": [], + "chapterTitle": "3.2.7. Service Constraints" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules/db-operations", + "title": "Database Operations", + "children": [], + "chapterTitle": "3.2.8. Database Operations" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules/multiple-services", + "title": "Multiple Services", + "children": [], + "chapterTitle": "3.2.9. Multiple Services" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules/commerce-modules", + "title": "Commerce Modules", + "children": [], + "chapterTitle": "3.2.10. Commerce Modules" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/modules/architectural-modules", + "title": "Architectural Modules", + "children": [], + "chapterTitle": "3.2.11. Architectural Modules" + } + ], + "chapterTitle": "3.2. Modules" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/module-links", + "title": "Module Links", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/module-links/directions", + "title": "Module Link Direction", + "children": [], + "chapterTitle": "3.3.1. Module Link Direction" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/module-links/link", + "title": "Link", + "children": [], + "chapterTitle": "3.3.2. Link" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/module-links/query", + "title": "Query", + "children": [], + "chapterTitle": "3.3.3. Query" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/module-links/custom-columns", + "title": "Custom Columns", + "children": [], + "chapterTitle": "3.3.4. Custom Columns" + } + ], + "chapterTitle": "3.3. Module Links" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models", + "title": "Data Models", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models/infer-type", + "title": "Infer Type", + "children": [], + "chapterTitle": "3.4.1. Infer Type" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models/property-types", + "title": "Property Types", + "children": [], + "chapterTitle": "3.4.2. Property Types" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models/primary-key", + "title": "Primary Key", + "children": [], + "chapterTitle": "3.4.3. Primary Key" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models/default-properties", + "title": "Default Properties", + "children": [], + "chapterTitle": "3.4.4. Default Properties" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models/configure-properties", + "title": "Configure Properties", + "children": [], + "chapterTitle": "3.4.5. Configure Properties" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models/relationships", + "title": "Relationships", + "children": [], + "chapterTitle": "3.4.6. Relationships" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models/manage-relationships", + "title": "Manage Relationships", + "children": [], + "chapterTitle": "3.4.7. Manage Relationships" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models/index", + "title": "Define Index", + "children": [], + "chapterTitle": "3.4.8. Define Index" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models/check-constraints", + "title": "Check Constraints", + "children": [], + "chapterTitle": "3.4.9. Check Constraints" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models/searchable-property", + "title": "Searchable Property", + "children": [], + "chapterTitle": "3.4.10. Searchable Property" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/data-models/write-migration", + "title": "Write Migration", + "children": [], + "chapterTitle": "3.4.11. Write Migration" + } + ], + "chapterTitle": "3.4. Data Models" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "API Routes", + "path": "/learn/fundamentals/api-routes", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/api-routes/http-methods", + "title": "HTTP Methods", + "children": [], + "chapterTitle": "3.5.1. HTTP Methods" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/api-routes/parameters", + "title": "Parameters", + "children": [], + "chapterTitle": "3.5.2. Parameters" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/api-routes/responses", + "title": "Response", + "children": [], + "chapterTitle": "3.5.3. Response" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/api-routes/middlewares", + "title": "Middlewares", + "children": [], + "chapterTitle": "3.5.4. Middlewares" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/api-routes/validation", + "title": "Validation", + "children": [], + "chapterTitle": "3.5.5. Validation" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/api-routes/protected-routes", + "title": "Protected Routes", + "children": [], + "chapterTitle": "3.5.6. Protected Routes" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/api-routes/errors", + "title": "Errors", + "children": [], + "chapterTitle": "3.5.7. Errors" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/api-routes/cors", + "title": "Handling CORS", + "children": [], + "chapterTitle": "3.5.8. Handling CORS" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/api-routes/additional-data", + "title": "Additional Data", + "children": [], + "chapterTitle": "3.5.9. Additional Data" + } + ], + "chapterTitle": "3.5. API Routes" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows", + "title": "Workflows", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/variable-manipulation", + "title": "Transform Variables", + "children": [], + "chapterTitle": "3.6.1. Transform Variables" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/conditions", + "title": "When-Then Conditions", + "children": [], + "chapterTitle": "3.6.2. When-Then Conditions" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/constructor-constraints", + "title": "Constructor Constraints", + "children": [], + "chapterTitle": "3.6.3. Constructor Constraints" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/compensation-function", + "title": "Compensation Function", + "children": [], + "chapterTitle": "3.6.4. Compensation Function" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/workflow-hooks", + "title": "Workflow Hooks", + "children": [], + "chapterTitle": "3.6.5. Workflow Hooks" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/add-workflow-hook", + "title": "Expose a Hook", + "children": [], + "chapterTitle": "3.6.6. Expose a Hook" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/access-workflow-errors", + "title": "Access Workflow Errors", + "children": [], + "chapterTitle": "3.6.7. Access Workflow Errors" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/retry-failed-steps", + "title": "Retry Failed Steps", + "children": [], + "chapterTitle": "3.6.8. Retry Failed Steps" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/parallel-steps", + "title": "Run Steps in Parallel", + "children": [], + "chapterTitle": "3.6.9. Run Steps in Parallel" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/workflow-timeout", + "title": "Workflow Timeout", + "children": [], + "chapterTitle": "3.6.10. Workflow Timeout" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/long-running-workflow", + "title": "Long-Running Workflow", + "children": [], + "chapterTitle": "3.6.11. Long-Running Workflow" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/execute-another-workflow", + "title": "Execute Another Workflow", + "children": [], + "chapterTitle": "3.6.12. Execute Another Workflow" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/workflows/multiple-step-usage", + "title": "Multiple Step Usage", + "children": [], + "chapterTitle": "3.6.13. Multiple Step Usage" + } + ], + "chapterTitle": "3.6. Workflows" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/events-and-subscribers", + "title": "Events and Subscribers", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/events-and-subscribers/data-payload", + "title": "Events Data Payload", + "children": [], + "chapterTitle": "3.7.1. Events Data Payload" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/events-and-subscribers/emit-event", + "title": "Emit Event", + "children": [], + "chapterTitle": "3.7.2. Emit Event" + } + ], + "chapterTitle": "3.7. Events and Subscribers" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/scheduled-jobs", + "title": "Scheduled Jobs", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/scheduled-jobs/execution-number", + "title": "Execution Number", + "children": [], + "chapterTitle": "3.8.1. Execution Number" + } + ], + "chapterTitle": "3.8. Scheduled Jobs" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/admin", + "title": "Admin Development", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/admin/widgets", + "title": "Admin Widgets", + "children": [], + "chapterTitle": "3.9.1. Admin Widgets" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/admin/ui-routes", + "title": "Admin UI Routes", + "children": [], + "chapterTitle": "3.9.2. Admin UI Routes" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/admin/constraints", + "title": "Constraints", + "children": [], + "chapterTitle": "3.9.3. Constraints" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/admin/tips", + "title": "Tips", + "children": [], + "chapterTitle": "3.9.4. Tips" + } + ], + "chapterTitle": "3.9. Admin Development" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/custom-cli-scripts", + "title": "Custom CLI Scripts", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/fundamentals/custom-cli-scripts/seed-data", + "title": "Seed Data", + "children": [], + "chapterTitle": "3.10.1. Seed Data" + } + ], + "chapterTitle": "3.10. Custom CLI Scripts" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "title": "Environment Variables", + "path": "/learn/fundamentals/environment-variables", + "children": [], + "chapterTitle": "3.11. Environment Variables" + } + ], + "chapterTitle": "3. Fundamentals" + }, + { + "type": "category", + "title": "4. Storefront", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/storefront-development", + "title": "Storefront Development", + "chapterTitle": "4. Storefront", + "children": [], + "childrenSameLevel": true + } + ], + "loaded": true, + "initialOpen": false + }, + { + "type": "category", + "title": "5. Debugging & Testing", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/debugging-and-testing", + "title": "Debugging and Testing", + "chapterTitle": "5. Debugging & Testing", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/debugging-and-testing/testing-tools", + "title": "Testing Tools", + "children": [], + "chapterTitle": "5.1. Testing Tools" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/debugging-and-testing/testing-tools/integration-tests", + "title": "Integration Tests", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/debugging-and-testing/testing-tools/integration-tests/api-routes", + "title": "Example: API Routes Tests", + "children": [], + "chapterTitle": "5.2.1. Example: API Routes Tests" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/debugging-and-testing/testing-tools/integration-tests/workflows", + "title": "Example: Workflows Tests", + "children": [], + "chapterTitle": "5.2.2. Example: Workflows Tests" + } + ], + "chapterTitle": "5.2. Integration Tests" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/debugging-and-testing/testing-tools/modules-tests", + "title": "Modules Tests", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/debugging-and-testing/testing-tools/modules-tests/module-example", + "title": "Example", + "children": [], + "chapterTitle": "5.3.1. Example" + } + ], + "chapterTitle": "5.3. Modules Tests" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/debugging-and-testing/instrumentation", + "title": "Instrumentation", + "children": [], + "chapterTitle": "5.4. Instrumentation" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/debugging-and-testing/logging", + "title": "Logging", + "children": [], + "chapterTitle": "5.5. Logging" + } + ], + "childrenSameLevel": true + } + ], + "loaded": true, + "initialOpen": false + }, + { + "type": "category", + "title": "6. Production", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/build", + "title": "Build", + "chapterTitle": "6. Production", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/deployment", + "title": "Deployment Overview", + "children": [], + "chapterTitle": "6.1. Deployment Overview" + }, + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/deployment/general", + "title": "General Deployment", + "children": [], + "chapterTitle": "6.2. General Deployment" + } + ], + "childrenSameLevel": true + } + ], + "loaded": true, + "initialOpen": false + }, + { + "type": "category", + "title": "7. More Resources", + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "link", + "path": "/learn/more-resources", + "title": "More Resources", + "children": [], + "childrenSameLevel": true, + "chapterTitle": "7. More Resources" + } + ], + "loaded": true, + "initialOpen": false + } +] \ No newline at end of file diff --git a/www/apps/book/scripts/prepare.mjs b/www/apps/book/scripts/prepare.mjs index 2d46138e23..6abbb9c80e 100644 --- a/www/apps/book/scripts/prepare.mjs +++ b/www/apps/book/scripts/prepare.mjs @@ -1,7 +1,11 @@ -import { generateEditedDates } from "build-scripts" +import { sidebar } from "../sidebar.mjs" +import { generateEditedDates, generateSidebar } from "build-scripts" async function main() { await generateEditedDates() + await generateSidebar(sidebar, { + addNumbering: true, + }) } void main() diff --git a/www/apps/book/sidebar.mjs b/www/apps/book/sidebar.mjs index 82c99b9a03..968a96d77e 100644 --- a/www/apps/book/sidebar.mjs +++ b/www/apps/book/sidebar.mjs @@ -1,564 +1,561 @@ -import numberSidebarItems from "./utils/number-sidebar-items.mjs" import { sidebarAttachHrefCommonOptions } from "./utils/sidebar-attach-common-options.mjs" /** @type {import('@/types').SidebarItem[]} */ -export const sidebar = numberSidebarItems( - sidebarAttachHrefCommonOptions([ - { - type: "link", - path: "/learn", - title: "Introduction", - children: [ - { - type: "link", - path: "/learn/installation", - title: "Installation", - }, - { - type: "link", - title: "Architecture", - path: "/learn/introduction/architecture", - }, - ], - }, - { - type: "category", - title: "Customize", - children: [ - { - type: "link", - title: "Build Custom Features", - path: "/learn/customization/custom-features", - children: [ - { - type: "link", - title: "Brand Module", - path: "/learn/customization/custom-features/module", - }, - { - type: "link", - title: "Brand Workflow", - path: "/learn/customization/custom-features/workflow", - }, - { - type: "link", - title: "Brand API Route", - path: "/learn/customization/custom-features/api-route", - }, - ], - }, - { - type: "link", - title: "Extend Features", - path: "/learn/customization/extend-features", - children: [ - { - type: "link", - title: "Link Brands and Products", - path: "/learn/customization/extend-features/define-link", - }, - { - type: "link", - title: "Extend Core Flow", - path: "/learn/customization/extend-features/extend-create-product", - }, - { - type: "link", - title: "Query Linked Records", - path: "/learn/customization/extend-features/query-linked-records", - }, - ], - }, - { - type: "link", - title: "Customize Admin", - path: "/learn/customization/customize-admin", - children: [ - { - type: "link", - title: "Add Widget", - path: "/learn/customization/customize-admin/widget", - }, - { - type: "link", - title: "Add UI Route", - path: "/learn/customization/customize-admin/route", - }, - ], - }, - { - type: "link", - title: "Integrate Systems", - path: "/learn/customization/integrate-systems", - children: [ - { - type: "link", - title: "CMS Module", - path: "/learn/customization/integrate-systems/service", - }, - { - type: "link", - title: "Sync to CMS", - path: "/learn/customization/integrate-systems/handle-event", - }, - { - type: "link", - title: "Schedule Syncing", - path: "/learn/customization/integrate-systems/schedule-task", - }, - ], - }, - { - type: "link", - title: "Next Steps", - path: "/learn/customization/next-steps", - }, - ], - }, - { - type: "category", - title: "Fundamentals", - children: [ - { - type: "link", - path: "/learn/fundamentals/medusa-container", - title: "Medusa Container", - }, - { - type: "link", - path: "/learn/fundamentals/modules", - title: "Modules", - children: [ - { - type: "link", - path: "/learn/fundamentals/modules/modules-directory-structure", - title: "Modules Directory Structure", - }, - { - type: "link", - path: "/learn/fundamentals/modules/loaders", - title: "Loaders", - }, - { - type: "link", - path: "/learn/fundamentals/modules/isolation", - title: "Module Isolation", - }, - { - type: "link", - path: "/learn/fundamentals/modules/container", - title: "Module Container", - }, - { - type: "link", - path: "/learn/fundamentals/modules/options", - title: "Module Options", - }, - { - type: "link", - path: "/learn/fundamentals/modules/service-factory", - title: "Service Factory", - }, - { - type: "link", - path: "/learn/fundamentals/modules/service-constraints", - title: "Service Constraints", - }, - { - type: "link", - path: "/learn/fundamentals/modules/db-operations", - title: "Database Operations", - }, - { - type: "link", - path: "/learn/fundamentals/modules/multiple-services", - title: "Multiple Services", - }, - { - type: "link", - path: "/learn/fundamentals/modules/commerce-modules", - title: "Commerce Modules", - }, - { - type: "link", - path: "/learn/fundamentals/modules/architectural-modules", - title: "Architectural Modules", - }, - ], - }, - { - type: "link", - path: "/learn/fundamentals/module-links", - title: "Module Links", - children: [ - { - type: "link", - path: "/learn/fundamentals/module-links/directions", - title: "Module Link Direction", - }, - { - type: "link", - path: "/learn/fundamentals/module-links/link", - title: "Link", - }, - { - type: "link", - path: "/learn/fundamentals/module-links/query", - title: "Query", - }, - { - type: "link", - path: "/learn/fundamentals/module-links/custom-columns", - title: "Custom Columns", - }, - ], - }, - { - type: "link", - path: "/learn/fundamentals/data-models", - title: "Data Models", - children: [ - { - type: "link", - path: "/learn/fundamentals/data-models/infer-type", - title: "Infer Type", - }, - { - type: "link", - path: "/learn/fundamentals/data-models/property-types", - title: "Property Types", - }, - { - type: "link", - path: "/learn/fundamentals/data-models/primary-key", - title: "Primary Key", - }, - { - type: "link", - path: "/learn/fundamentals/data-models/default-properties", - title: "Default Properties", - }, - { - type: "link", - path: "/learn/fundamentals/data-models/configure-properties", - title: "Configure Properties", - }, - { - type: "link", - path: "/learn/fundamentals/data-models/relationships", - title: "Relationships", - }, - { - type: "link", - path: "/learn/fundamentals/data-models/manage-relationships", - title: "Manage Relationships", - }, - { - type: "link", - path: "/learn/fundamentals/data-models/index", - title: "Define Index", - }, - { - type: "link", - path: "/learn/fundamentals/data-models/check-constraints", - title: "Check Constraints", - }, - { - type: "link", - path: "/learn/fundamentals/data-models/searchable-property", - title: "Searchable Property", - }, - { - type: "link", - path: "/learn/fundamentals/data-models/write-migration", - title: "Write Migration", - }, - ], - }, - { - type: "link", - title: "API Routes", - path: "/learn/fundamentals/api-routes", - children: [ - { - type: "link", - path: "/learn/fundamentals/api-routes/http-methods", - title: "HTTP Methods", - }, - { - type: "link", - path: "/learn/fundamentals/api-routes/parameters", - title: "Parameters", - }, - { - type: "link", - path: "/learn/fundamentals/api-routes/responses", - title: "Response", - }, - { - type: "link", - path: "/learn/fundamentals/api-routes/middlewares", - title: "Middlewares", - }, - { - type: "link", - path: "/learn/fundamentals/api-routes/validation", - title: "Validation", - }, - { - type: "link", - path: "/learn/fundamentals/api-routes/protected-routes", - title: "Protected Routes", - }, - { - type: "link", - path: "/learn/fundamentals/api-routes/errors", - title: "Errors", - }, - { - type: "link", - path: "/learn/fundamentals/api-routes/cors", - title: "Handling CORS", - }, - { - type: "link", - path: "/learn/fundamentals/api-routes/additional-data", - title: "Additional Data", - }, - ], - }, - { - type: "link", - path: "/learn/fundamentals/workflows", - title: "Workflows", - children: [ - { - type: "link", - path: "/learn/fundamentals/workflows/variable-manipulation", - title: "Transform Variables", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/conditions", - title: "When-Then Conditions", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/constructor-constraints", - title: "Constructor Constraints", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/compensation-function", - title: "Compensation Function", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/workflow-hooks", - title: "Workflow Hooks", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/add-workflow-hook", - title: "Expose a Hook", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/access-workflow-errors", - title: "Access Workflow Errors", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/retry-failed-steps", - title: "Retry Failed Steps", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/parallel-steps", - title: "Run Steps in Parallel", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/workflow-timeout", - title: "Workflow Timeout", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/store-executions", - title: "Store Workflow Executions", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/long-running-workflow", - title: "Long-Running Workflow", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/execute-another-workflow", - title: "Execute Another Workflow", - }, - { - type: "link", - path: "/learn/fundamentals/workflows/multiple-step-usage", - title: "Multiple Step Usage", - }, - ], - }, - { - type: "link", - path: "/learn/fundamentals/events-and-subscribers", - title: "Events and Subscribers", - children: [ - { - type: "link", - path: "/learn/fundamentals/events-and-subscribers/data-payload", - title: "Events Data Payload", - }, - { - type: "link", - path: "/learn/fundamentals/events-and-subscribers/emit-event", - title: "Emit Event", - }, - ], - }, - { - type: "link", - path: "/learn/fundamentals/scheduled-jobs", - title: "Scheduled Jobs", - children: [ - { - type: "link", - path: "/learn/fundamentals/scheduled-jobs/execution-number", - title: "Execution Number", - }, - ], - }, - { - type: "link", - path: "/learn/fundamentals/admin", - title: "Admin Development", - children: [ - { - type: "link", - path: "/learn/fundamentals/admin/widgets", - title: "Admin Widgets", - }, - { - type: "link", - path: "/learn/fundamentals/admin/ui-routes", - title: "Admin UI Routes", - }, - { - type: "link", - path: "/learn/fundamentals/admin/constraints", - title: "Constraints", - }, - { - type: "link", - path: "/learn/fundamentals/admin/tips", - title: "Tips", - }, - ], - }, - { - type: "link", - path: "/learn/fundamentals/custom-cli-scripts", - title: "Custom CLI Scripts", - children: [ - { - type: "link", - path: "/learn/fundamentals/custom-cli-scripts/seed-data", - title: "Seed Data", - }, - ], - }, - { - type: "link", - title: "Environment Variables", - path: "/learn/fundamentals/environment-variables", - }, - ], - }, - { - type: "link", - path: "/learn/storefront-development", - title: "Storefront Development", - chapterTitle: "Storefront", - }, - { - type: "link", - path: "/learn/debugging-and-testing", - title: "Debugging and Testing", - chapterTitle: "Debugging & Testing", - children: [ - { - type: "link", - path: "/learn/debugging-and-testing/testing-tools", - title: "Testing Tools", - }, - { - type: "link", - path: "/learn/debugging-and-testing/testing-tools/integration-tests", - title: "Integration Tests", - children: [ - { - type: "link", - path: "/learn/debugging-and-testing/testing-tools/integration-tests/api-routes", - title: "Example: API Routes Tests", - }, - { - type: "link", - path: "/learn/debugging-and-testing/testing-tools/integration-tests/workflows", - title: "Example: Workflows Tests", - }, - ], - }, - { - type: "link", - path: "/learn/debugging-and-testing/testing-tools/modules-tests", - title: "Modules Tests", - children: [ - { - type: "link", - path: "/learn/debugging-and-testing/testing-tools/modules-tests/module-example", - title: "Example", - }, - ], - }, - { - type: "link", - path: "/learn/debugging-and-testing/instrumentation", - title: "Instrumentation", - }, - { - type: "link", - path: "/learn/debugging-and-testing/logging", - title: "Logging", - }, - ], - }, - { - type: "link", - path: "/learn/build", - title: "Build", - chapterTitle: "Production", - children: [ - { - type: "link", - path: "/learn/deployment", - title: "Deployment Overview", - }, - { - type: "link", - path: "/learn/deployment/general", - title: "General Deployment", - }, - ], - }, - { - type: "link", - path: "/learn/more-resources", - title: "More Resources", - }, - ]) -) +export const sidebar = sidebarAttachHrefCommonOptions([ + { + type: "link", + path: "/learn", + title: "Introduction", + children: [ + { + type: "link", + path: "/learn/installation", + title: "Installation", + }, + { + type: "link", + title: "Architecture", + path: "/learn/introduction/architecture", + }, + ], + }, + { + type: "category", + title: "Customize", + children: [ + { + type: "link", + title: "Build Custom Features", + path: "/learn/customization/custom-features", + children: [ + { + type: "link", + title: "Brand Module", + path: "/learn/customization/custom-features/module", + }, + { + type: "link", + title: "Brand Workflow", + path: "/learn/customization/custom-features/workflow", + }, + { + type: "link", + title: "Brand API Route", + path: "/learn/customization/custom-features/api-route", + }, + ], + }, + { + type: "link", + title: "Extend Features", + path: "/learn/customization/extend-features", + children: [ + { + type: "link", + title: "Link Brands and Products", + path: "/learn/customization/extend-features/define-link", + }, + { + type: "link", + title: "Extend Core Flow", + path: "/learn/customization/extend-features/extend-create-product", + }, + { + type: "link", + title: "Query Linked Records", + path: "/learn/customization/extend-features/query-linked-records", + }, + ], + }, + { + type: "link", + title: "Customize Admin", + path: "/learn/customization/customize-admin", + children: [ + { + type: "link", + title: "Add Widget", + path: "/learn/customization/customize-admin/widget", + }, + { + type: "link", + title: "Add UI Route", + path: "/learn/customization/customize-admin/route", + }, + ], + }, + { + type: "link", + title: "Integrate Systems", + path: "/learn/customization/integrate-systems", + children: [ + { + type: "link", + title: "CMS Module", + path: "/learn/customization/integrate-systems/service", + }, + { + type: "link", + title: "Sync to CMS", + path: "/learn/customization/integrate-systems/handle-event", + }, + { + type: "link", + title: "Schedule Syncing", + path: "/learn/customization/integrate-systems/schedule-task", + }, + ], + }, + { + type: "link", + title: "Next Steps", + path: "/learn/customization/next-steps", + }, + ], + }, + { + type: "category", + title: "Fundamentals", + children: [ + { + type: "link", + path: "/learn/fundamentals/medusa-container", + title: "Medusa Container", + }, + { + type: "link", + path: "/learn/fundamentals/modules", + title: "Modules", + children: [ + { + type: "link", + path: "/learn/fundamentals/modules/modules-directory-structure", + title: "Modules Directory Structure", + }, + { + type: "link", + path: "/learn/fundamentals/modules/loaders", + title: "Loaders", + }, + { + type: "link", + path: "/learn/fundamentals/modules/isolation", + title: "Module Isolation", + }, + { + type: "link", + path: "/learn/fundamentals/modules/container", + title: "Module Container", + }, + { + type: "link", + path: "/learn/fundamentals/modules/options", + title: "Module Options", + }, + { + type: "link", + path: "/learn/fundamentals/modules/service-factory", + title: "Service Factory", + }, + { + type: "link", + path: "/learn/fundamentals/modules/service-constraints", + title: "Service Constraints", + }, + { + type: "link", + path: "/learn/fundamentals/modules/db-operations", + title: "Database Operations", + }, + { + type: "link", + path: "/learn/fundamentals/modules/multiple-services", + title: "Multiple Services", + }, + { + type: "link", + path: "/learn/fundamentals/modules/commerce-modules", + title: "Commerce Modules", + }, + { + type: "link", + path: "/learn/fundamentals/modules/architectural-modules", + title: "Architectural Modules", + }, + ], + }, + { + type: "link", + path: "/learn/fundamentals/module-links", + title: "Module Links", + children: [ + { + type: "link", + path: "/learn/fundamentals/module-links/directions", + title: "Module Link Direction", + }, + { + type: "link", + path: "/learn/fundamentals/module-links/link", + title: "Link", + }, + { + type: "link", + path: "/learn/fundamentals/module-links/query", + title: "Query", + }, + { + type: "link", + path: "/learn/fundamentals/module-links/custom-columns", + title: "Custom Columns", + }, + ], + }, + { + type: "link", + path: "/learn/fundamentals/data-models", + title: "Data Models", + children: [ + { + type: "link", + path: "/learn/fundamentals/data-models/infer-type", + title: "Infer Type", + }, + { + type: "link", + path: "/learn/fundamentals/data-models/property-types", + title: "Property Types", + }, + { + type: "link", + path: "/learn/fundamentals/data-models/primary-key", + title: "Primary Key", + }, + { + type: "link", + path: "/learn/fundamentals/data-models/default-properties", + title: "Default Properties", + }, + { + type: "link", + path: "/learn/fundamentals/data-models/configure-properties", + title: "Configure Properties", + }, + { + type: "link", + path: "/learn/fundamentals/data-models/relationships", + title: "Relationships", + }, + { + type: "link", + path: "/learn/fundamentals/data-models/manage-relationships", + title: "Manage Relationships", + }, + { + type: "link", + path: "/learn/fundamentals/data-models/index", + title: "Define Index", + }, + { + type: "link", + path: "/learn/fundamentals/data-models/check-constraints", + title: "Check Constraints", + }, + { + type: "link", + path: "/learn/fundamentals/data-models/searchable-property", + title: "Searchable Property", + }, + { + type: "link", + path: "/learn/fundamentals/data-models/write-migration", + title: "Write Migration", + }, + ], + }, + { + type: "link", + title: "API Routes", + path: "/learn/fundamentals/api-routes", + children: [ + { + type: "link", + path: "/learn/fundamentals/api-routes/http-methods", + title: "HTTP Methods", + }, + { + type: "link", + path: "/learn/fundamentals/api-routes/parameters", + title: "Parameters", + }, + { + type: "link", + path: "/learn/fundamentals/api-routes/responses", + title: "Response", + }, + { + type: "link", + path: "/learn/fundamentals/api-routes/middlewares", + title: "Middlewares", + }, + { + type: "link", + path: "/learn/fundamentals/api-routes/validation", + title: "Validation", + }, + { + type: "link", + path: "/learn/fundamentals/api-routes/protected-routes", + title: "Protected Routes", + }, + { + type: "link", + path: "/learn/fundamentals/api-routes/errors", + title: "Errors", + }, + { + type: "link", + path: "/learn/fundamentals/api-routes/cors", + title: "Handling CORS", + }, + { + type: "link", + path: "/learn/fundamentals/api-routes/additional-data", + title: "Additional Data", + }, + ], + }, + { + type: "link", + path: "/learn/fundamentals/workflows", + title: "Workflows", + children: [ + { + type: "link", + path: "/learn/fundamentals/workflows/variable-manipulation", + title: "Transform Variables", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/conditions", + title: "When-Then Conditions", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/constructor-constraints", + title: "Constructor Constraints", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/compensation-function", + title: "Compensation Function", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/workflow-hooks", + title: "Workflow Hooks", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/add-workflow-hook", + title: "Expose a Hook", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/access-workflow-errors", + title: "Access Workflow Errors", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/retry-failed-steps", + title: "Retry Failed Steps", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/parallel-steps", + title: "Run Steps in Parallel", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/workflow-timeout", + title: "Workflow Timeout", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/store-executions", + title: "Store Workflow Executions", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/long-running-workflow", + title: "Long-Running Workflow", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/execute-another-workflow", + title: "Execute Another Workflow", + }, + { + type: "link", + path: "/learn/fundamentals/workflows/multiple-step-usage", + title: "Multiple Step Usage", + }, + ], + }, + { + type: "link", + path: "/learn/fundamentals/events-and-subscribers", + title: "Events and Subscribers", + children: [ + { + type: "link", + path: "/learn/fundamentals/events-and-subscribers/data-payload", + title: "Events Data Payload", + }, + { + type: "link", + path: "/learn/fundamentals/events-and-subscribers/emit-event", + title: "Emit Event", + }, + ], + }, + { + type: "link", + path: "/learn/fundamentals/scheduled-jobs", + title: "Scheduled Jobs", + children: [ + { + type: "link", + path: "/learn/fundamentals/scheduled-jobs/execution-number", + title: "Execution Number", + }, + ], + }, + { + type: "link", + path: "/learn/fundamentals/admin", + title: "Admin Development", + children: [ + { + type: "link", + path: "/learn/fundamentals/admin/widgets", + title: "Admin Widgets", + }, + { + type: "link", + path: "/learn/fundamentals/admin/ui-routes", + title: "Admin UI Routes", + }, + { + type: "link", + path: "/learn/fundamentals/admin/constraints", + title: "Constraints", + }, + { + type: "link", + path: "/learn/fundamentals/admin/tips", + title: "Tips", + }, + ], + }, + { + type: "link", + path: "/learn/fundamentals/custom-cli-scripts", + title: "Custom CLI Scripts", + children: [ + { + type: "link", + path: "/learn/fundamentals/custom-cli-scripts/seed-data", + title: "Seed Data", + }, + ], + }, + { + type: "link", + title: "Environment Variables", + path: "/learn/fundamentals/environment-variables", + }, + ], + }, + { + type: "link", + path: "/learn/storefront-development", + title: "Storefront Development", + chapterTitle: "Storefront", + }, + { + type: "link", + path: "/learn/debugging-and-testing", + title: "Debugging and Testing", + chapterTitle: "Debugging & Testing", + children: [ + { + type: "link", + path: "/learn/debugging-and-testing/testing-tools", + title: "Testing Tools", + }, + { + type: "link", + path: "/learn/debugging-and-testing/testing-tools/integration-tests", + title: "Integration Tests", + children: [ + { + type: "link", + path: "/learn/debugging-and-testing/testing-tools/integration-tests/api-routes", + title: "Example: API Routes Tests", + }, + { + type: "link", + path: "/learn/debugging-and-testing/testing-tools/integration-tests/workflows", + title: "Example: Workflows Tests", + }, + ], + }, + { + type: "link", + path: "/learn/debugging-and-testing/testing-tools/modules-tests", + title: "Modules Tests", + children: [ + { + type: "link", + path: "/learn/debugging-and-testing/testing-tools/modules-tests/module-example", + title: "Example", + }, + ], + }, + { + type: "link", + path: "/learn/debugging-and-testing/instrumentation", + title: "Instrumentation", + }, + { + type: "link", + path: "/learn/debugging-and-testing/logging", + title: "Logging", + }, + ], + }, + { + type: "link", + path: "/learn/build", + title: "Build", + chapterTitle: "Production", + children: [ + { + type: "link", + path: "/learn/deployment", + title: "Deployment Overview", + }, + { + type: "link", + path: "/learn/deployment/general", + title: "General Deployment", + }, + ], + }, + { + type: "link", + path: "/learn/more-resources", + title: "More Resources", + }, +]) diff --git a/www/packages/build-scripts/src/generate-sidebar.ts b/www/packages/build-scripts/src/generate-sidebar.ts index a7bd54137a..411ff02bf3 100644 --- a/www/packages/build-scripts/src/generate-sidebar.ts +++ b/www/packages/build-scripts/src/generate-sidebar.ts @@ -4,11 +4,16 @@ import path from "path" import { getSidebarItemLink, sidebarAttachHrefCommonOptions } from "./index.js" import getCoreFlowsRefSidebarChildren from "./utils/get-core-flows-ref-sidebar-children.js" import { parseTags } from "./utils/parse-tags.js" +import numberSidebarItems from "./utils/number-sidebar-items.js" export type ItemsToAdd = SidebarItem & { sidebar_position?: number } +type GenerateSidebarOptions = { + addNumbering?: boolean +} + const customGenerators: Record Promise> = { "core-flows": getCoreFlowsRefSidebarChildren, } @@ -158,8 +163,11 @@ async function checkItem(item: RawSidebarItem): Promise { return item } -async function checkItems(items: RawSidebarItem[]): Promise { - return ( +async function checkItems( + items: RawSidebarItem[], + options?: GenerateSidebarOptions +): Promise { + const updatedItems = ( await Promise.all(items.map(async (item) => await checkItem(item))) ).filter((item) => { if (item.type !== "category" && item.type !== "sub-category") { @@ -168,13 +176,22 @@ async function checkItems(items: RawSidebarItem[]): Promise { return (item.children?.length || 0) > 0 }) + + if (options?.addNumbering) { + return numberSidebarItems(updatedItems) + } + + return updatedItems } -export async function generateSidebar(sidebar: RawSidebarItem[]) { +export async function generateSidebar( + sidebar: RawSidebarItem[], + options?: GenerateSidebarOptions +): Promise { const path = await import("path") const { writeFileSync } = await import("fs") - const normalizedSidebar = await checkItems(sidebar) + const normalizedSidebar = await checkItems(sidebar, options) const generatedDirPath = path.resolve("generated") diff --git a/www/apps/book/utils/number-sidebar-items.mjs b/www/packages/build-scripts/src/utils/number-sidebar-items.ts similarity index 58% rename from www/apps/book/utils/number-sidebar-items.mjs rename to www/packages/build-scripts/src/utils/number-sidebar-items.ts index d6e5b4aab1..d6539d1ccc 100644 --- a/www/apps/book/utils/number-sidebar-items.mjs +++ b/www/packages/build-scripts/src/utils/number-sidebar-items.ts @@ -1,27 +1,23 @@ -/** - * - * @param {import("@/types").SidebarItem[]} sidebarItems - The items to add numbers to their titles - * @param {number[]} numbering - The current numbering level - * @returns {import("@/types").SidebarItem[]} The modified sidebar items - */ -export default function numberSidebarItems(sidebarItems, numbering = [1]) { +import { InteractiveSidebarItem, SidebarItem, SidebarItemCategory } from "types" + +export default function numberSidebarItems( + sidebarItems: SidebarItem[], + numbering = [1] +): SidebarItem[] { if (!numbering.length) { numbering.push(1) } const isTopItems = numbering.length === 1 - /** @type {import("@/types").SidebarItem[]} */ - const numberedItems = [] - /** @type {import("@/types").SidebarItem | undefined} */ - let parentItem - sidebarItems.forEach((item, index) => { + const numberedItems: SidebarItem[] = [] + let parentItem: InteractiveSidebarItem | undefined + sidebarItems.forEach((item) => { if (item.type === "separator") { ;(parentItem?.children || numberedItems).push(item) return } // append current number to the item's title - item.number = `${numbering.join(".")}.` - item.chapterTitle = `${item.number} ${ + item.chapterTitle = `${numbering.join(".")}. ${ item.chapterTitle?.trim() || item.title?.trim() }` item.title = item.title.trim() @@ -30,7 +26,10 @@ export default function numberSidebarItems(sidebarItems, numbering = [1]) { // Add chapter category numberedItems.push( item.type === "category" - ? item + ? { + ...item, + title: item.chapterTitle, + } : { type: "category", title: item.chapterTitle, @@ -40,7 +39,9 @@ export default function numberSidebarItems(sidebarItems, numbering = [1]) { } ) - parentItem = numberedItems[numberedItems.length - 1] + parentItem = numberedItems[ + numberedItems.length - 1 + ] as SidebarItemCategory } if (item.children) {