diff --git a/src/components/comment/Twikoo.astro b/src/components/comment/Twikoo.astro new file mode 100644 index 0000000..65be396 --- /dev/null +++ b/src/components/comment/Twikoo.astro @@ -0,0 +1,19 @@ +--- +import { commentConfig } from '@/config' + +interface Props { + path: string +} + +const config = { + ...commentConfig.twikoo, + el: '#tcomment', + path: Astro.props.path, +} +--- + +
+ + diff --git a/src/components/comment/index.astro b/src/components/comment/index.astro new file mode 100644 index 0000000..3838962 --- /dev/null +++ b/src/components/comment/index.astro @@ -0,0 +1,22 @@ +--- +import type { CollectionEntry } from 'astro:content' +import { commentConfig } from '@/config' +import Twikoo from './Twikoo.astro' +interface Props { + post: CollectionEntry<'posts'> +} + +const { id, data, slug } = Astro.props.post + +const path = `/posts/${slug}` +const url = `${Astro.site?.href}${path}` + +let commentService = '' +if (commentConfig?.twikoo) { + commentService = 'twikoo' +} +--- +
+ {commentService === 'twikoo' && } + {commentService === '' && null} +
diff --git a/src/config.ts b/src/config.ts index 8b1ea77..930a8c3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,6 @@ import type { ExpressiveCodeConfig, + CommentConfig, LicenseConfig, NavBarConfig, ProfileConfig, @@ -99,3 +100,9 @@ export const expressiveCodeConfig: ExpressiveCodeConfig = { // Please select a dark theme, as this blog theme currently only supports dark background color theme: "github-dark", }; + +export const commentConfig: CommentConfig = { + twikoo: { + envId: 'https://twikoo.mckero.com/', + }, +} \ No newline at end of file diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 316bb35..878bc7d 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -13,6 +13,7 @@ import ImageWrapper from "../../components/misc/ImageWrapper.astro"; import PostMetadata from "../../components/PostMeta.astro"; import { profileConfig, siteConfig } from "../../config"; import { formatDateToYYYYMMDD } from "../../utils/date-utils"; +import Comment from "@components/comment/index.astro" export async function getStaticPaths() { const blogEntries = await getSortedPosts(); @@ -108,22 +109,8 @@ const jsonLd = { {licenseConfig.enable && } - + + diff --git a/src/types/config.ts b/src/types/config.ts index f2eb561..94e2f7f 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -91,6 +91,16 @@ export type LIGHT_DARK_MODE = | typeof DARK_MODE | typeof AUTO_MODE; + export type CommentConfig = { + twikoo?: TwikooConfig + } + + type TwikooConfig = { + envId: string + region?: string + lang?: string + } + export type BlogPostData = { body: string; title: string;