diff --git a/src/components/common/CharacterCard.tsx b/src/components/common/CharacterCard.tsx index 8c8aeadd..a4cebc3e 100644 --- a/src/components/common/CharacterCard.tsx +++ b/src/components/common/CharacterCard.tsx @@ -45,12 +45,12 @@ export const CharacterCard: React.FC<{ ]) const [buttonLoading, setButtonLoading] = useState(false) - const [firstOpen, setFirstOpen] = useState(false) + const [firstOpen, setFirstOpen] = useState("") const [site, setSite] = useState() useEffect(() => { - if (!firstOpen && open && siteId && !site) { - setFirstOpen(true) + if (open && siteId && (firstOpen !== siteId || !site)) { + setFirstOpen(siteId) siteModel.getSite(siteId).then((site) => setSite(site)) } }, [open, firstOpen, siteId, site]) diff --git a/src/components/ui/Mention.tsx b/src/components/ui/Mention.tsx new file mode 100644 index 00000000..9f4fe746 --- /dev/null +++ b/src/components/ui/Mention.tsx @@ -0,0 +1,23 @@ +import React from "react" +import { CharacterCard } from "../common/CharacterCard" +import { UniLink } from "./UniLink" +import { getSiteLink } from "~/lib/helpers" + +export const Mention: React.FC<{ + id: string +}> = ({ id }) => { + const siteId = id?.replace(/^user-content-/, "") + console.log(siteId) + return ( + + + @{siteId} + + + ) +} diff --git a/src/markdown/index.ts b/src/markdown/index.ts index 9626032b..7bf8bbfc 100644 --- a/src/markdown/index.ts +++ b/src/markdown/index.ts @@ -27,6 +27,7 @@ import rehypeAutolinkHeadings from "rehype-autolink-headings" import { toc, Result as TocResult } from "mdast-util-toc" import { Element } from "react-scroll" import type { Root } from "hast" +import { Mention } from "~/components/ui/Mention" export type MarkdownEnv = { excerpt: string @@ -136,6 +137,7 @@ export const renderPageContent = ( components: { img: Image, anchor: Element, + mention: Mention, } as any, }) .use(() => (tree) => { diff --git a/src/markdown/sanitize-schema.ts b/src/markdown/sanitize-schema.ts index a44252e8..2e34eae0 100644 --- a/src/markdown/sanitize-schema.ts +++ b/src/markdown/sanitize-schema.ts @@ -11,6 +11,7 @@ const scheme = { "youtube", "toc", "anchor", + "mention", ], attributes: { ...defaultSchema.attributes,