Skip to content

Commit

Permalink
docs: fix cross-project link for Card components (#10794)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser authored Jan 2, 2025
1 parent 0594f37 commit 54e1e70
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
18 changes: 13 additions & 5 deletions www/packages/remark-rehype-plugins/src/broken-link-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 10 additions & 5 deletions www/packages/remark-rehype-plugins/src/cross-project-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,15 @@ 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
}

const attribute = getAttribute(node, attributeName)

if (
!attribute ||
typeof attribute.value === "string" ||
!attribute.value.data?.estree
) {
if (!attribute) {
return
}

Expand All @@ -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)
Expand Down

0 comments on commit 54e1e70

Please sign in to comment.