docs: add sidebar sorting logic (#11751)
* docs: add sidebar sorting logic * generate sidebar
This commit is contained in:
1 parent
ecc3deb362
commit
3616003145
28 files changed
+1959
-1656
No files matched your search
@@ -5,6 +5,7 @@ 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"
|
||||
import { sortSidebarItems } from "./utils/sidebar-sorting.js"
|
||||
|
||||
export type ItemsToAdd = SidebarItem & {
|
||||
sidebar_position?: number
|
||||
@@ -160,6 +161,11 @@ async function checkItem(item: RawSidebarItem): Promise<RawSidebarItem> {
|
||||
item.children = await checkItems(item.children)
|
||||
}
|
||||
|
||||
item.children = sortSidebarItems({
|
||||
items: item.children as RawSidebarItem[],
|
||||
type: item.sort_sidebar,
|
||||
})
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { InteractiveSidebarItem, RawSidebarItem, SidebarSortType } from "types"
|
||||
|
||||
type Options = {
|
||||
items: RawSidebarItem[]
|
||||
type?: SidebarSortType
|
||||
}
|
||||
|
||||
export const sortSidebarItems = ({
|
||||
items,
|
||||
type = "none",
|
||||
}: Options): RawSidebarItem[] => {
|
||||
switch (type) {
|
||||
case "alphabetize":
|
||||
return alphabetizeSidebarItems(items)
|
||||
default:
|
||||
return items
|
||||
}
|
||||
}
|
||||
|
||||
const alphabetizeSidebarItems = (items: RawSidebarItem[]): RawSidebarItem[] => {
|
||||
const segments: RawSidebarItem[][] = []
|
||||
let currentSegment: RawSidebarItem[] = []
|
||||
|
||||
items.forEach((item) => {
|
||||
if (item.type === "separator") {
|
||||
if (currentSegment.length > 0) {
|
||||
segments.push(currentSegment)
|
||||
currentSegment = []
|
||||
}
|
||||
segments.push([item])
|
||||
} else {
|
||||
currentSegment.push(item)
|
||||
}
|
||||
})
|
||||
|
||||
if (currentSegment.length > 0) {
|
||||
segments.push(currentSegment)
|
||||
}
|
||||
|
||||
return segments
|
||||
.map((segment) => {
|
||||
return segment[0].type === "separator"
|
||||
? segment
|
||||
: (segment as InteractiveSidebarItem[]).sort((a, b) =>
|
||||
a.title.localeCompare(b.title)
|
||||
)
|
||||
})
|
||||
.flat()
|
||||
}
|
||||
@@ -1,40 +1,40 @@
|
||||
export * from "./user-guide.js"
|
||||
export * from "./order.js"
|
||||
export * from "./fulfillment.js"
|
||||
export * from "./payment.js"
|
||||
export * from "./pricing.js"
|
||||
export * from "./product.js"
|
||||
export * from "./promotion.js"
|
||||
export * from "./user.js"
|
||||
export * from "./auth.js"
|
||||
export * from "./product.js"
|
||||
export * from "./api-key.js"
|
||||
export * from "./stock-location.js"
|
||||
export * from "./workflow.js"
|
||||
export * from "./region.js"
|
||||
export * from "./stock-location.js"
|
||||
export * from "./sales-channel.js"
|
||||
export * from "./currency.js"
|
||||
export * from "./tax.js"
|
||||
export * from "./region.js"
|
||||
export * from "./store.js"
|
||||
export * from "./currency.js"
|
||||
export * from "./concept.js"
|
||||
export * from "./tax.js"
|
||||
export * from "./query.js"
|
||||
export * from "./order.js"
|
||||
export * from "./inventory.js"
|
||||
export * from "./cart.js"
|
||||
export * from "./customer.js"
|
||||
export * from "./fulfillment.js"
|
||||
export * from "./product-category.js"
|
||||
export * from "./stripe.js"
|
||||
export * from "./customer.js"
|
||||
export * from "./checkout.js"
|
||||
export * from "./server.js"
|
||||
export * from "./publishable-api-key.js"
|
||||
export * from "./product-collection.js"
|
||||
export * from "./js-sdk.js"
|
||||
export * from "./logger.js"
|
||||
export * from "./step.js"
|
||||
export * from "./remote-query.js"
|
||||
export * from "./example.js"
|
||||
export * from "./product-collection.js"
|
||||
export * from "./publishable-api-key.js"
|
||||
export * from "./link.js"
|
||||
export * from "./step.js"
|
||||
export * from "./product-category.js"
|
||||
export * from "./locking.js"
|
||||
export * from "./event-bus.js"
|
||||
export * from "./remote-query.js"
|
||||
export * from "./logger.js"
|
||||
export * from "./js-sdk.js"
|
||||
export * from "./file.js"
|
||||
export * from "./admin.js"
|
||||
export * from "./notification.js"
|
||||
export * from "./event-bus.js"
|
||||
export * from "./file.js"
|
||||
export * from "./link.js"
|
||||
export * from "./cart.js"
|
||||
export * from "./storefront.js"
|
||||
export * from "./locking.js"
|
||||
export * from "./server.js"
|
||||
@@ -1,8 +1,4 @@
|
||||
export const jsSdk = [
|
||||
{
|
||||
"title": "Implement Express Checkout with Medusa",
|
||||
"path": "https://docs.medusajs.com/resources/storefront-development/guides/express-checkout"
|
||||
},
|
||||
{
|
||||
"title": "apiKey",
|
||||
"path": "https://docs.medusajs.com/resources/references/js-sdk/admin/apiKey"
|
||||
|
||||
@@ -67,10 +67,13 @@ export type SidebarSectionItems = {
|
||||
parentItem?: InteractiveSidebarItem
|
||||
}
|
||||
|
||||
export type SidebarSortType = "none" | "alphabetize"
|
||||
|
||||
export type RawSidebarItem = SidebarItem & {
|
||||
autogenerate_path?: string
|
||||
autogenerate_tags?: string
|
||||
autogenerate_as_ref?: boolean
|
||||
sort_sidebar?: SidebarSortType
|
||||
custom_autogenerate?: string
|
||||
number?: string
|
||||
} & (
|
||||
|
||||
Reference in new issue
Block a user