From eee38148ee3010290610307d0801821a2f05630e Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Fri, 7 Oct 2022 17:12:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20cusdis=20=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 6 +++-- .gitignore | 3 ++- .vscode/settings.json | 3 +++ components/comments/Cusdis.tsx | 41 +++++++++++++++++++++++++++++++++ components/comments/index.tsx | 11 +++++++++ data/siteMetadata.js | 6 ++++- jsconfig.json | 1 + next.config.js | 6 ++--- package-lock.json | Bin 950752 -> 912189 bytes package.json | 1 + 10 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 components/comments/Cusdis.tsx 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 937cf4bcc2244fa27c91326b0ab8971f11d54295..b56132e62cbf0026703630f6573c589addcd78cb 100644 GIT binary patch delta 1166 zcmd6l`%l|t6vp$u{a*UM-;0G7SYd;P5m+~AOJOS+E(4ZbrBE1cxl9)5m^zq{mbu_A zb|6s~fex}B!w+I+;u41mTVjr6Zf0ucbZ#y))5KpSSwc+4BnE9T!^KV_ZvF-Sa+33T zo}8Q~=S=r+y!5?i@>gmK9g6IGF_OE{mfPZX6gi5a`LVfR~uFI=d(-# zx6TnAp4vtfXsIF^zEQx^$jGrQcx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