2022-10-07 17:12:50 +08:00
|
|
|
import React from 'react'
|
|
|
|
|
2022-07-17 21:40:41 +08:00
|
|
|
import siteMetadata from '@/data/siteMetadata'
|
|
|
|
import dynamic from 'next/dynamic'
|
2022-10-07 13:55:39 +08:00
|
|
|
import { PostFrontMatter } from 'types/PostFrontMatter'
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
frontMatter: PostFrontMatter
|
|
|
|
}
|
2022-07-17 21:40:41 +08:00
|
|
|
|
|
|
|
const UtterancesComponent = dynamic(
|
|
|
|
() => {
|
|
|
|
return import('@/components/comments/Utterances')
|
|
|
|
},
|
|
|
|
{ ssr: false }
|
|
|
|
)
|
|
|
|
const GiscusComponent = dynamic(
|
|
|
|
() => {
|
|
|
|
return import('@/components/comments/Giscus')
|
|
|
|
},
|
|
|
|
{ ssr: false }
|
|
|
|
)
|
|
|
|
const DisqusComponent = dynamic(
|
|
|
|
() => {
|
|
|
|
return import('@/components/comments/Disqus')
|
|
|
|
},
|
|
|
|
{ ssr: false }
|
|
|
|
)
|
2022-10-07 17:12:50 +08:00
|
|
|
const CusdisComponent = dynamic(
|
|
|
|
() => {
|
|
|
|
return import('@/components/comments/Cusdis')
|
|
|
|
},
|
|
|
|
{ ssr: false }
|
|
|
|
)
|
2022-10-07 22:04:38 +08:00
|
|
|
const CommentoComponent = dynamic(
|
|
|
|
() => {
|
|
|
|
return import('@/components/comments/Commento')
|
|
|
|
},
|
|
|
|
{ ssr: false }
|
|
|
|
)
|
2022-07-17 21:40:41 +08:00
|
|
|
|
2022-10-07 13:55:39 +08:00
|
|
|
const Comments = ({ frontMatter }: Props) => {
|
|
|
|
let term
|
|
|
|
switch (
|
|
|
|
siteMetadata.comment.giscusConfig.mapping ||
|
|
|
|
siteMetadata.comment.utterancesConfig.issueTerm
|
|
|
|
) {
|
|
|
|
case 'pathname':
|
|
|
|
term = frontMatter.slug
|
|
|
|
break
|
|
|
|
case 'url':
|
|
|
|
term = window.location.href
|
|
|
|
break
|
|
|
|
case 'title':
|
|
|
|
term = frontMatter.title
|
|
|
|
break
|
|
|
|
}
|
2022-07-17 21:40:41 +08:00
|
|
|
return (
|
|
|
|
<div id="comment">
|
2022-10-07 13:55:39 +08:00
|
|
|
{siteMetadata.comment && siteMetadata.comment.provider === 'giscus' && (
|
|
|
|
<GiscusComponent mapping={term} />
|
|
|
|
)}
|
2022-07-17 21:40:41 +08:00
|
|
|
{siteMetadata.comment && siteMetadata.comment.provider === 'utterances' && (
|
2022-10-07 13:55:39 +08:00
|
|
|
<UtterancesComponent issueTerm={term} />
|
2022-07-17 21:40:41 +08:00
|
|
|
)}
|
|
|
|
{siteMetadata.comment && siteMetadata.comment.provider === 'disqus' && (
|
|
|
|
<DisqusComponent frontMatter={frontMatter} />
|
|
|
|
)}
|
2022-10-07 17:12:50 +08:00
|
|
|
{siteMetadata.comment && siteMetadata.comment.provider === 'cusdis' && (
|
|
|
|
<CusdisComponent frontMatter={frontMatter} />
|
|
|
|
)}
|
2022-10-07 22:04:38 +08:00
|
|
|
{siteMetadata.comment && siteMetadata.comment.provider === 'commento' && (
|
|
|
|
<CommentoComponent frontMatter={frontMatter} />
|
|
|
|
)}
|
2022-07-17 21:40:41 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Comments
|