diff --git a/.env.example b/.env.example index ecf12d0..97ce54d 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,8 @@ NEXT_PUBLIC_GISCUS_CATEGORY= NEXT_PUBLIC_GISCUS_CATEGORY_ID= NEXT_PUBLIC_UTTERANCES_REPO= NEXT_PUBLIC_DISQUS_SHORTNAME= +NEXT_PUBLIC_CUSDIS_APPID= +NEXT_PUBLIC_CUSDIS_HOST= MAILCHIMP_API_KEY= @@ -15,8 +17,8 @@ BUTTONDOWN_API_KEY= CONVERTKIT_API_URL=https://api.convertkit.com/v3/ CONVERTKIT_API_KEY= -// curl https://api.convertkit.com/v3/forms?api_key= to get your form ID -CONVERTKIT_FORM_ID= +// curl https://api.convertkit.com/v3/forms?api_key= to get your form ID +CONVERTKIT_FORM_ID= KLAVIYO_API_KEY= KLAVIYO_LIST_ID= diff --git a/.gitignore b/.gitignore index 76bad3b..79018e0 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ yarn-error.log* .env.test.local .env.production.local -secrets.txt \ No newline at end of file +secrets.txt +.env diff --git a/.vscode/settings.json b/.vscode/settings.json index 662a3ed..bb6031b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,8 +2,11 @@ "cSpell.words": [ "alpn", "blackhole", + "Cusdis", + "Disqus", "dokodemo", "fullchain", + "Giscus", "lastmod", "outbounds", "rprx", diff --git a/components/comments/Cusdis.tsx b/components/comments/Cusdis.tsx new file mode 100644 index 0000000..0d68207 --- /dev/null +++ b/components/comments/Cusdis.tsx @@ -0,0 +1,41 @@ +import React, { useMemo, useState } from 'react' + +import siteMetadata from '@/data/siteMetadata' +import { PostFrontMatter } from 'types/PostFrontMatter' +import { ReactCusdis } from 'react-cusdis' +import { useTheme } from 'next-themes' + +interface Props { + frontMatter: PostFrontMatter +} + +const Cusdis = ({ frontMatter }: Props) => { + const { resolvedTheme } = useTheme() + const commentsTheme = useMemo(() => { + switch (resolvedTheme) { + case 'light': + case 'dark': + return resolvedTheme + default: + return 'auto' + } + }, [resolvedTheme]) + return ( +
+ +
+ ) +} + +export default Cusdis diff --git a/components/comments/index.tsx b/components/comments/index.tsx index 89188ff..9e30231 100644 --- a/components/comments/index.tsx +++ b/components/comments/index.tsx @@ -1,3 +1,5 @@ +import React from 'react' + import siteMetadata from '@/data/siteMetadata' import dynamic from 'next/dynamic' import { PostFrontMatter } from 'types/PostFrontMatter' @@ -24,6 +26,12 @@ const DisqusComponent = dynamic( }, { ssr: false } ) +const CusdisComponent = dynamic( + () => { + return import('@/components/comments/Cusdis') + }, + { ssr: false } +) const Comments = ({ frontMatter }: Props) => { let term @@ -52,6 +60,9 @@ const Comments = ({ frontMatter }: Props) => { {siteMetadata.comment && siteMetadata.comment.provider === 'disqus' && ( )} + {siteMetadata.comment && siteMetadata.comment.provider === 'cusdis' && ( + + )} ) } diff --git a/data/siteMetadata.js b/data/siteMetadata.js index 5b8566b..6a7eb5e 100644 --- a/data/siteMetadata.js +++ b/data/siteMetadata.js @@ -40,7 +40,7 @@ const siteMetadata = { // content security policy in the `next.config.js` file. // Select a provider and use the environment variables associated to it // https://vercel.com/docs/environment-variables - provider: '', // supported providers: giscus, utterances, disqus + provider: 'cusdis', // supported providers: giscus, utterances, disqus giscusConfig: { // Visit the link below, and follow the steps in the 'configuration' section // https://giscus.app/ @@ -78,6 +78,10 @@ const siteMetadata = { // https://help.disqus.com/en/articles/1717111-what-s-a-shortname shortname: process.env.NEXT_PUBLIC_DISQUS_SHORTNAME, }, + cusdisConfig: { + appId: process.env.NEXT_PUBLIC_CUSDIS_APPID, + host: process.env.NEXT_PUBLIC_CUSDIS_HOST, + }, }, } diff --git a/jsconfig.json b/jsconfig.json index a01d7de..5d0cbf8 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "jsx": "react", "baseUrl": ".", "paths": { "@/components/*": ["components/*"], diff --git a/next.config.js b/next.config.js index 2dc87ed..225c42a 100644 --- a/next.config.js +++ b/next.config.js @@ -5,13 +5,13 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({ // You might need to insert additional domains in script-src if you are using external services const ContentSecurityPolicy = ` default-src 'self'; - script-src 'self' 'unsafe-eval' 'unsafe-inline' giscus.app; - style-src 'self' 'unsafe-inline'; + script-src 'self' 'unsafe-eval' 'unsafe-inline' giscus.app comment.ivanli.cc; + style-src 'self' 'unsafe-inline' comment.ivanli.cc; img-src * blob: data:; media-src 'none'; connect-src *; font-src 'self'; - frame-src giscus.app + frame-src giscus.app comment.ivanli.cc ` const securityHeaders = [ diff --git a/package-lock.json b/package-lock.json index 937cf4b..b56132e 100644 Binary files a/package-lock.json and b/package-lock.json differ diff --git a/package.json b/package.json index daa77e1..dabc5c0 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "postcss": "^8.4.17", "preact": "^10.11.1", "react": "18.2.0", + "react-cusdis": "^2.1.3", "react-dom": "18.2.0", "reading-time": "1.5.0", "rehype-autolink-headings": "^6.1.1",