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