feat: mention markdown component

This commit is contained in:
DIYgod
2022-11-01 19:23:52 +00:00
parent 98c83756b8
commit d0b079886c
4 changed files with 29 additions and 3 deletions
+3 -3
View File
@@ -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])
+23
View File
@@ -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>
)
}
+2
View File
@@ -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) => {
+1
View File
@@ -11,6 +11,7 @@ const scheme = {
"youtube",
"toc",
"anchor",
"mention",
],
attributes: {
...defaultSchema.attributes,