rehype-component.ts — ui Source File
Architecture documentation for rehype-component.ts, a typescript file in the ui codebase. 7 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR a572535f_b25f_7501_dc60_c7a2d320a739["rehype-component.ts"] 3958e4bc_926d_5880_3584_6100e196e980["index.tsx"] a572535f_b25f_7501_dc60_c7a2d320a739 --> 3958e4bc_926d_5880_3584_6100e196e980 80482477_f158_7e0b_0d31_34ba4bbaeae6["registry-styles.ts"] a572535f_b25f_7501_dc60_c7a2d320a739 --> 80482477_f158_7e0b_0d31_34ba4bbaeae6 eac8f98f_e40a_7fe8_f505_372c83d20c7a["fs"] a572535f_b25f_7501_dc60_c7a2d320a739 --> eac8f98f_e40a_7fe8_f505_372c83d20c7a d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5["path"] a572535f_b25f_7501_dc60_c7a2d320a739 --> d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5 0730df87_79db_5696_d5e4_371255b3036a["unist"] a572535f_b25f_7501_dc60_c7a2d320a739 --> 0730df87_79db_5696_d5e4_371255b3036a 937f5d4b_c2a7_bcb9_05d8_41dc51498899["unist-builder"] a572535f_b25f_7501_dc60_c7a2d320a739 --> 937f5d4b_c2a7_bcb9_05d8_41dc51498899 fcbb6195_57aa_1339_fa5f_694d53020f20["unist-util-visit"] a572535f_b25f_7501_dc60_c7a2d320a739 --> fcbb6195_57aa_1339_fa5f_694d53020f20 3ab0029b_bc98_e23e_7c0d_e96099aed850["contentlayer.config.js"] 3ab0029b_bc98_e23e_7c0d_e96099aed850 --> a572535f_b25f_7501_dc60_c7a2d320a739 style a572535f_b25f_7501_dc60_c7a2d320a739 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import fs from "fs"
import path from "path"
import { UnistNode, UnistTree } from "types/unist"
import { u } from "unist-builder"
import { visit } from "unist-util-visit"
import { Index } from "../__registry__"
import { styles } from "../registry/registry-styles"
export function rehypeComponent() {
return async (tree: UnistTree) => {
visit(tree, (node: UnistNode) => {
// src prop overrides both name and fileName.
const { value: srcPath } =
(getNodeAttributeByName(node, "src") as {
name: string
value?: string
type?: string
}) || {}
if (node.name === "ComponentSource") {
const name = getNodeAttributeByName(node, "name")?.value as string
const fileName = getNodeAttributeByName(node, "fileName")?.value as
| string
| undefined
if (!name && !srcPath) {
return null
}
try {
for (const style of styles) {
let src: string
if (srcPath) {
src = path.join(process.cwd(), srcPath)
} else {
const component = Index[style.name][name]
src = fileName
? component.files.find((file: unknown) => {
if (typeof file === "string") {
return (
file.endsWith(`${fileName}.tsx`) ||
file.endsWith(`${fileName}.ts`)
)
}
return false
}) || component.files[0]?.path
: component.files[0]?.path
}
// Read the source file.
const filePath = src
let source = fs.readFileSync(filePath, "utf8")
// Replace imports.
// TODO: Use @swc/core and a visitor to replace this.
// For now a simple regex should do.
source = source.replaceAll(
`@/registry/${style.name}/`,
// ... (223 more lines)
Domain
Subdomains
Dependencies
- fs
- index.tsx
- path
- registry-styles.ts
- unist
- unist-builder
- unist-util-visit
Imported By
Source
Frequently Asked Questions
What does rehype-component.ts do?
rehype-component.ts is a source file in the ui codebase, written in typescript. It belongs to the ComponentRegistry domain, Styles subdomain.
What functions are defined in rehype-component.ts?
rehype-component.ts defines 3 function(s): getComponentSourceFileContent, getNodeAttributeByName, rehypeComponent.
What does rehype-component.ts depend on?
rehype-component.ts imports 7 module(s): fs, index.tsx, path, registry-styles.ts, unist, unist-builder, unist-util-visit.
What files import rehype-component.ts?
rehype-component.ts is imported by 1 file(s): contentlayer.config.js.
Where is rehype-component.ts in the architecture?
rehype-component.ts is located at deprecated/www/lib/rehype-component.ts (domain: ComponentRegistry, subdomain: Styles, directory: deprecated/www/lib).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free