Skip to content

Commit

Permalink
Merge pull request #61 from syfxlin/develop
Browse files Browse the repository at this point in the history
fix: artalk comment not working
  • Loading branch information
syfxlin authored Dec 24, 2023
2 parents cc0fb76 + f50d212 commit 4ddd281
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@syfxlin/reve": "^1.0.5",
"@tippyjs/react": "^4.2.6",
"@vanilla-extract/css": "^1.14.0",
"artalk": "^2.7.2",
"artalk": "^2.6.4",
"fs-extra": "^11.2.0",
"fuse.js": "^7.0.0",
"gh-lang-colors": "^0.1.3",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/templates/template/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Main } from "../../layouts/main";
import { Title } from "../../layouts/title";
import { Toc } from "../../widgets/toc";
import { CursorPagination } from "../../ui/pagination";
import { Artalk } from "../../widgets/artalk/dynamic";
import { Artalk } from "../../widgets/artalk";
import { Footer } from "../../layouts/footer";
import { TocData } from "../../../contents/types";

Expand Down
4 changes: 0 additions & 4 deletions src/components/widgets/artalk/dynamic.tsx

This file was deleted.

21 changes: 12 additions & 9 deletions src/components/widgets/artalk/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"use client";
import "artalk/dist/Artalk.css";
import * as styles from "./styles.css";
import React, { useEffect } from "react";
import ArtalkComment from "artalk";
import React, { useEffect, useRef } from "react";
import { COLINE_ARTALK_SERVER_URL, COLINE_ARTALK_SITE_NAME } from "../../../env/public";
import { useTheme } from "next-themes";

Expand All @@ -12,20 +11,24 @@ type Props = {
};

export const Artalk: React.FC<Props> = ({ name, link }) => {
const artalk = useRef<any>();
const { resolvedTheme } = useTheme();
useEffect(() => {
try {
ArtalkComment.init({
el: `#comment`,
import("artalk").then((mod) => {
artalk.current = new mod.default({
el: `#artalk`,
pageTitle: name,
pageKey: link,
darkMode: resolvedTheme === "dark",
server: COLINE_ARTALK_SERVER_URL,
site: COLINE_ARTALK_SITE_NAME,
});
} catch (e) {
// ignore
}
});
return () => {
if (artalk.current) {
artalk.current.destroy();
}
};
}, [name, link, resolvedTheme]);
return <section id="comment" aria-label="评论系统" className={styles.container} />;
return <section id="artalk" aria-label="评论系统" className={styles.container} />;
};

0 comments on commit 4ddd281

Please sign in to comment.