docs: support generating sidebar items with tags (#10672)

* docs: support generating sidebar items with tags

* small fix

* fix dependencies

* test

* test fix

* test fix

* test fix

* test fix

* another fix

* revert change

* fix for resources
This commit is contained in:
Shahed Nasser
2024-12-19 18:24:36 +02:00
committed by GitHub
parent 1118e35924
commit 65007c49f6
19 changed files with 119 additions and 54 deletions

View File

@@ -1,4 +1,4 @@
import { getFrontMatter, findPageTitle } from "../../../docs-utils/dist/index.js"
import { getFrontMatter, findPageTitle } from "docs-utils"
import { ItemsToAdd, sidebarAttachHrefCommonOptions } from "../index.js"
import { InteractiveSidebarItem } from "types"

View File

@@ -0,0 +1,44 @@
import { getTagItems } from "tags"
import { Tag } from "types"
export const parseTags = (tagNames: string): Tag => {
const parsedTags: Tag = []
tagNames.split(",").forEach((tagName) => {
const intersectingTags = getIntersectionTags(tagName)
if (!intersectingTags.length) {
return
}
parsedTags.push(...intersectingTags)
})
return parsedTags
}
const getIntersectionTags = (tags: string): Tag => {
const tagsToIntersect: Tag[] = tags
.split("+")
.map((tagName) => getTagItems(tagName))
.filter((tag) => tag !== undefined) as Tag[]
if (!tagsToIntersect.length) {
return []
}
if (tagsToIntersect.length === 1) {
return tagsToIntersect[0]
}
return tagsToIntersect[0].filter((tagItem) => {
return tagsToIntersect
.slice(1)
.every((otherTag) =>
otherTag.some(
(otherTagItem) =>
otherTagItem.title === tagItem.title &&
otherTagItem.path === tagItem.path
)
)
})
}