feat: split artalk to local-provided standalone component

This commit is contained in:
草师傅 2025-07-21 15:33:15 +08:00
parent 7af0886d9c
commit 05a0f3461d
Signed by: gb
GPG key ID: 43330A030E2D6478
4 changed files with 45 additions and 20 deletions

View file

@ -2,9 +2,10 @@
import {siteConfig} from "../config";
import FediverseComments from "./helper/comments/Fediverse.astro";
import HatsuComments from "./helper/comments/Hatsu.astro";
import Artalk from "./helper/comments/Artalk.astro";
const method = siteConfig.comments.type
const ArtalkConfig = siteConfig.comments.artalk
const giscusConfig = siteConfig.comments.giscus
const FediverseConfig = siteConfig.comments.fediverse
interface Props {
@ -13,25 +14,7 @@ interface Props {
let { path='/' } = Astro.props;
---
{method === 'artalk' &&
<div>
<!-- CSS -->
<link href={`https://${ArtalkConfig.instanceDomain}/dist/Artalk.css`} rel="stylesheet">
<!-- JS -->
<script src={`https://${ArtalkConfig.instanceDomain}/dist/Artalk.js`}></script>
<!-- Artalk -->
<div id="Comments"></div>
<script define:vars={{ instanceDomain: ArtalkConfig.instanceDomain, pagePath: path }}>
Artalk.init({
el: '#Comments',
pageKey: pagePath, // Using the passed variable
server: `https://${instanceDomain}`, // Using the passed variable
})
</script>
</div>
}
{method === 'artalk' && <Artalk path={path} />}
{method === 'giscus' && (
<script
src="https://giscus.app/client.js"

View file

@ -0,0 +1,22 @@
---
import {siteConfig} from "../../../config";
import 'artalk/Artalk.css';
const ArtalkInstanceDomain = siteConfig.comments.artalk.instanceDomain
const { path } = Astro.props;
---
<div>
<!-- Artalk -->
<div id="comments" data-path={path} data-server={ArtalkInstanceDomain}></div>
<script>
import Artalk from "artalk";
const atkElement = document.querySelector('#comments');
Artalk.init({
el: '#comments',
pageKey: atkElement?.getAttribute('data-path') || window.location.pathname,
server: `https://${atkElement?.getAttribute('data-server')}`,
darkMode: "auto",
versionCheck: false
});
</script>
</div>