tailwind-nextjs-blog/components/comments/index.tsx

72 lines
1.7 KiB
TypeScript
Raw Normal View History

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';
interface Props {
2022-10-17 23:37:01 +08:00
frontMatter: PostFrontMatter;
}
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
);
const CommentoComponent = dynamic(
() => {
2022-10-17 23:37:01 +08:00
return import('@/components/comments/Commento');
},
{ ssr: false }
2022-10-17 23:37:01 +08:00
);
2022-07-17 21:40:41 +08:00
const Comments = ({ frontMatter }: Props) => {
2022-10-17 23:37:01 +08:00
let term;
switch (
siteMetadata.comment.giscusConfig.mapping ||
siteMetadata.comment.utterancesConfig.issueTerm
) {
case 'pathname':
2022-10-17 23:37:01 +08:00
term = frontMatter.slug;
break;
case 'url':
2022-10-17 23:37:01 +08:00
term = window.location.href;
break;
case 'title':
2022-10-17 23:37:01 +08:00
term = frontMatter.title;
break;
}
2022-07-17 21:40:41 +08:00
return (
<div id="comment">
{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} />
)}
{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;