2022-10-17 23:37:01 +08:00
|
|
|
import React, { useMemo, useState } from 'react';
|
2022-10-07 17:12:50 +08:00
|
|
|
|
2022-10-17 23:37:01 +08:00
|
|
|
import siteMetadata from '@/data/siteMetadata';
|
|
|
|
import { PostFrontMatter } from 'types/PostFrontMatter';
|
|
|
|
import { ReactCusdis } from 'react-cusdis';
|
|
|
|
import { useTheme } from 'next-themes';
|
2022-10-07 17:12:50 +08:00
|
|
|
|
|
|
|
interface Props {
|
2022-10-17 23:37:01 +08:00
|
|
|
frontMatter: PostFrontMatter;
|
2022-10-07 17:12:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Cusdis = ({ frontMatter }: Props) => {
|
2022-10-17 23:37:01 +08:00
|
|
|
const { resolvedTheme } = useTheme();
|
2022-10-07 17:12:50 +08:00
|
|
|
const commentsTheme = useMemo(() => {
|
|
|
|
switch (resolvedTheme) {
|
|
|
|
case 'light':
|
|
|
|
case 'dark':
|
2022-10-17 23:37:01 +08:00
|
|
|
return resolvedTheme;
|
2022-10-07 17:12:50 +08:00
|
|
|
default:
|
2022-10-17 23:37:01 +08:00
|
|
|
return 'auto';
|
2022-10-07 17:12:50 +08:00
|
|
|
}
|
2022-10-17 23:37:01 +08:00
|
|
|
}, [resolvedTheme]);
|
2022-10-07 17:12:50 +08:00
|
|
|
return (
|
|
|
|
<div className="my-2">
|
|
|
|
<ReactCusdis
|
|
|
|
key={commentsTheme}
|
|
|
|
lang={siteMetadata.language?.toLocaleLowerCase()}
|
|
|
|
attrs={{
|
|
|
|
appId: siteMetadata.comment.cusdisConfig.appId,
|
|
|
|
host: siteMetadata.comment.cusdisConfig.host,
|
|
|
|
pageId: frontMatter.slug,
|
|
|
|
pageUrl: window.location.href,
|
|
|
|
pageTitle: frontMatter.title,
|
|
|
|
theme: commentsTheme,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-10-17 23:37:01 +08:00
|
|
|
);
|
|
|
|
};
|
2022-10-07 17:12:50 +08:00
|
|
|
|
2022-10-17 23:37:01 +08:00
|
|
|
export default Cusdis;
|