feat: 添加 cusdis 评论。
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Ivan Li 2022-10-07 17:12:50 +08:00
parent 31a4cb3bd1
commit eee38148ee
10 changed files with 71 additions and 7 deletions

View File

@ -4,6 +4,8 @@ NEXT_PUBLIC_GISCUS_CATEGORY=
NEXT_PUBLIC_GISCUS_CATEGORY_ID= NEXT_PUBLIC_GISCUS_CATEGORY_ID=
NEXT_PUBLIC_UTTERANCES_REPO= NEXT_PUBLIC_UTTERANCES_REPO=
NEXT_PUBLIC_DISQUS_SHORTNAME= NEXT_PUBLIC_DISQUS_SHORTNAME=
NEXT_PUBLIC_CUSDIS_APPID=
NEXT_PUBLIC_CUSDIS_HOST=
MAILCHIMP_API_KEY= MAILCHIMP_API_KEY=
@ -15,8 +17,8 @@ BUTTONDOWN_API_KEY=
CONVERTKIT_API_URL=https://api.convertkit.com/v3/ CONVERTKIT_API_URL=https://api.convertkit.com/v3/
CONVERTKIT_API_KEY= CONVERTKIT_API_KEY=
// curl https://api.convertkit.com/v3/forms?api_key=<your_public_api_key> to get your form ID // curl https://api.convertkit.com/v3/forms?api_key=<your_public_api_key> to get your form ID
CONVERTKIT_FORM_ID= CONVERTKIT_FORM_ID=
KLAVIYO_API_KEY= KLAVIYO_API_KEY=
KLAVIYO_LIST_ID= KLAVIYO_LIST_ID=

3
.gitignore vendored
View File

@ -35,4 +35,5 @@ yarn-error.log*
.env.test.local .env.test.local
.env.production.local .env.production.local
secrets.txt secrets.txt
.env

View File

@ -2,8 +2,11 @@
"cSpell.words": [ "cSpell.words": [
"alpn", "alpn",
"blackhole", "blackhole",
"Cusdis",
"Disqus",
"dokodemo", "dokodemo",
"fullchain", "fullchain",
"Giscus",
"lastmod", "lastmod",
"outbounds", "outbounds",
"rprx", "rprx",

View File

@ -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 (
<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>
)
}
export default Cusdis

View File

@ -1,3 +1,5 @@
import React from 'react'
import siteMetadata from '@/data/siteMetadata' import siteMetadata from '@/data/siteMetadata'
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
import { PostFrontMatter } from 'types/PostFrontMatter' import { PostFrontMatter } from 'types/PostFrontMatter'
@ -24,6 +26,12 @@ const DisqusComponent = dynamic(
}, },
{ ssr: false } { ssr: false }
) )
const CusdisComponent = dynamic(
() => {
return import('@/components/comments/Cusdis')
},
{ ssr: false }
)
const Comments = ({ frontMatter }: Props) => { const Comments = ({ frontMatter }: Props) => {
let term let term
@ -52,6 +60,9 @@ const Comments = ({ frontMatter }: Props) => {
{siteMetadata.comment && siteMetadata.comment.provider === 'disqus' && ( {siteMetadata.comment && siteMetadata.comment.provider === 'disqus' && (
<DisqusComponent frontMatter={frontMatter} /> <DisqusComponent frontMatter={frontMatter} />
)} )}
{siteMetadata.comment && siteMetadata.comment.provider === 'cusdis' && (
<CusdisComponent frontMatter={frontMatter} />
)}
</div> </div>
) )
} }

View File

@ -40,7 +40,7 @@ const siteMetadata = {
// content security policy in the `next.config.js` file. // content security policy in the `next.config.js` file.
// Select a provider and use the environment variables associated to it // Select a provider and use the environment variables associated to it
// https://vercel.com/docs/environment-variables // https://vercel.com/docs/environment-variables
provider: '', // supported providers: giscus, utterances, disqus provider: 'cusdis', // supported providers: giscus, utterances, disqus
giscusConfig: { giscusConfig: {
// Visit the link below, and follow the steps in the 'configuration' section // Visit the link below, and follow the steps in the 'configuration' section
// https://giscus.app/ // https://giscus.app/
@ -78,6 +78,10 @@ const siteMetadata = {
// https://help.disqus.com/en/articles/1717111-what-s-a-shortname // https://help.disqus.com/en/articles/1717111-what-s-a-shortname
shortname: process.env.NEXT_PUBLIC_DISQUS_SHORTNAME, shortname: process.env.NEXT_PUBLIC_DISQUS_SHORTNAME,
}, },
cusdisConfig: {
appId: process.env.NEXT_PUBLIC_CUSDIS_APPID,
host: process.env.NEXT_PUBLIC_CUSDIS_HOST,
},
}, },
} }

View File

@ -1,5 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"jsx": "react",
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"@/components/*": ["components/*"], "@/components/*": ["components/*"],

View File

@ -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 // You might need to insert additional domains in script-src if you are using external services
const ContentSecurityPolicy = ` const ContentSecurityPolicy = `
default-src 'self'; default-src 'self';
script-src 'self' 'unsafe-eval' 'unsafe-inline' giscus.app; script-src 'self' 'unsafe-eval' 'unsafe-inline' giscus.app comment.ivanli.cc;
style-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline' comment.ivanli.cc;
img-src * blob: data:; img-src * blob: data:;
media-src 'none'; media-src 'none';
connect-src *; connect-src *;
font-src 'self'; font-src 'self';
frame-src giscus.app frame-src giscus.app comment.ivanli.cc
` `
const securityHeaders = [ const securityHeaders = [

BIN
package-lock.json generated

Binary file not shown.

View File

@ -27,6 +27,7 @@
"postcss": "^8.4.17", "postcss": "^8.4.17",
"preact": "^10.11.1", "preact": "^10.11.1",
"react": "18.2.0", "react": "18.2.0",
"react-cusdis": "^2.1.3",
"react-dom": "18.2.0", "react-dom": "18.2.0",
"reading-time": "1.5.0", "reading-time": "1.5.0",
"rehype-autolink-headings": "^6.1.1", "rehype-autolink-headings": "^6.1.1",