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:
@@ -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"
|
||||
|
||||
|
||||
44
www/packages/build-scripts/src/utils/parse-tags.ts
Normal file
44
www/packages/build-scripts/src/utils/parse-tags.ts
Normal 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
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user