docs: fix cross-project link for Card components (#10794)

This commit is contained in:
Shahed Nasser
2025-01-02 12:51:53 +02:00
committed by GitHub
parent 0594f37d59
commit 54e1e70d78
3 changed files with 35 additions and 16 deletions

View File

@@ -90,11 +90,19 @@ function componentChecker({
const attribute = getAttribute(node, attributeName)
if (
!attribute ||
typeof attribute.value === "string" ||
!attribute.value.data?.estree
) {
if (!attribute) {
return
}
if (typeof attribute.value === "string") {
checkLink({
link: attribute.value,
...rest,
})
return
}
if (!attribute.value.data?.estree) {
return
}

View File

@@ -65,11 +65,16 @@ function componentFixer(
const attribute = getAttribute(node, attributeName)
if (
!attribute ||
typeof attribute.value === "string" ||
!attribute.value.data?.estree
) {
if (!attribute) {
return
}
if (typeof attribute.value === "string") {
attribute.value = matchAndFixLinks(attribute.value, options)
return
}
if (!attribute.value.data?.estree) {
return
}

View File

@@ -77,6 +77,7 @@ export function componentLinkFixer(
""
)
const appsPath = basePath || path.join(file.cwd, "app")
const linkFn = checkLinksType === "md" ? matchMdLinks : matchValueLink
visit(tree as UnistTree, "mdxJsxFlowElement", (node: UnistNodeWithData) => {
if (node.name !== componentName) {
return
@@ -84,11 +85,7 @@ export function componentLinkFixer(
const attribute = getAttribute(node, attributeName)
if (
!attribute ||
typeof attribute.value === "string" ||
!attribute.value.data?.estree
) {
if (!attribute) {
return
}
@@ -97,13 +94,22 @@ export function componentLinkFixer(
appsPath,
}
if (typeof attribute.value === "string") {
attribute.value =
linkFn(attribute.value, linkOptions) || attribute.value
return
}
if (!attribute.value.data?.estree) {
return
}
const itemJsVar = estreeToJs(attribute.value.data.estree)
if (!itemJsVar) {
return
}
const linkFn = checkLinksType === "md" ? matchMdLinks : matchValueLink
performActionOnLiteral(itemJsVar, (item) => {
item.original.value = linkFn(item.original.value as string, linkOptions)
item.original.raw = JSON.stringify(item.original.value)