XeNote/components/MDContent.tsx

79 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

2024-01-07 18:05:04 +00:00
import React from 'react'
import { useRouter } from 'next/router'
2023-12-31 21:17:04 +00:00
export interface LinkType {
2023-12-31 20:29:30 +00:00
slug: string
title: string
shortSummary: string
}
interface BackLinksProps {
2023-12-31 20:29:30 +00:00
linkList: LinkType[]
}
2023-12-31 20:29:30 +00:00
function BackLinks({ linkList }: BackLinksProps) {
return (<div className="">
<h3 className="">Link to this note</h3>
{(linkList != null && linkList.length > 0)
2024-01-07 18:05:04 +00:00
? <>
<div className="">
{linkList.map(aLink =>
<div key={aLink.slug} className="">
2024-01-07 18:05:04 +00:00
{/* <Link href={aLink.slug}> */}
<a href={aLink.slug}>
<p className="">{aLink.title}</p>
<p className="">{aLink.shortSummary} </p>
</a>
2024-01-07 18:05:04 +00:00
{/* </Link> */}
</div>
)}
</div>
</>
: <> <p className=""> No backlinks found</p> </>}
2024-01-07 18:05:04 +00:00
</div>)
}
interface MDContentProps {
2023-12-30 16:42:21 +00:00
content: string
2023-12-31 20:29:30 +00:00
backLinks: LinkType[]
}
2023-12-30 16:42:21 +00:00
function MDContent({ content, backLinks }: MDContentProps) {
2024-01-07 18:05:04 +00:00
useRouter()
return (
<div className="flex-1 p-xl">
<div dangerouslySetInnerHTML={{ __html: content }} />
<BackLinksGroup links={backLinks} />
<hr />
<footer>
<p>Powered by <a href="https://gitlab.com/Tarmstrong95">Triston</a>, © {new Date().getFullYear()}</p>
</footer>
</div>
2024-01-07 18:05:04 +00:00
)
}
2023-12-31 20:29:30 +00:00
interface BackLinksGroupProps {
links: LinkType[]
}
function BackLinksGroup({ links }: BackLinksGroupProps) {
2024-01-07 18:05:04 +00:00
if (links?.length === 0) {
return (
<p className=""> No backlinks found</p>
)
}
return (
<details>
<summary>
BackLinks
</summary>
<BackLinks linkList={links} />
</details>
)
}
2024-01-07 18:05:04 +00:00
export default MDContent