feat: mention markdown component
This commit is contained in:
@@ -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<Profile>()
|
||||
|
||||
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])
|
||||
|
||||
@@ -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 (
|
||||
<CharacterCard siteId={siteId}>
|
||||
<UniLink
|
||||
href={getSiteLink({
|
||||
subdomain: siteId,
|
||||
})}
|
||||
className="inline-block"
|
||||
>
|
||||
@{siteId}
|
||||
</UniLink>
|
||||
</CharacterCard>
|
||||
)
|
||||
}
|
||||
@@ -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) => {
|
||||
|
||||
@@ -11,6 +11,7 @@ const scheme = {
|
||||
"youtube",
|
||||
"toc",
|
||||
"anchor",
|
||||
"mention",
|
||||
],
|
||||
attributes: {
|
||||
...defaultSchema.attributes,
|
||||
|
||||
Reference in New Issue
Block a user