feat: add 'site' & 'title' to Artalk init options

This commit is contained in:
草师傅 2025-08-21 17:47:56 +08:00
parent 0b383a2fd3
commit b91b03adec
Signed by: gb
GPG key ID: 43330A030E2D6478
4 changed files with 11 additions and 4 deletions

View file

@ -13,11 +13,12 @@ const FediverseConfig = siteConfig.comments.fediverse
interface Props { interface Props {
mastodonLink?: string; mastodonLink?: string;
bskyLink?: string; bskyLink?: string;
pageTitle?: string;
} }
const { mastodonLink, bskyLink } = Astro.props; const { mastodonLink, bskyLink, pageTitle } = Astro.props;
--- ---
{method === 'artalk' && <Artalk />} {method === 'artalk' && <Artalk title={pageTitle} />}
{method === 'giscus' && <Giscus />} {method === 'giscus' && <Giscus />}
<!-- if prerender === true is set then render from client --> <!-- if prerender === true is set then render from client -->
{(method === 'fediverse' && !FediverseConfig.renderOnServer ) && <FediverseComments /> } {(method === 'fediverse' && !FediverseConfig.renderOnServer ) && <FediverseComments /> }

View file

@ -2,10 +2,13 @@
import {siteConfig} from "../../../config"; import {siteConfig} from "../../../config";
import 'artalk/Artalk.css'; import 'artalk/Artalk.css';
const ArtalkInstanceDomain = siteConfig.comments.artalk.instanceDomain const ArtalkInstanceDomain = siteConfig.comments.artalk.instanceDomain
const ArtalkInstanceSite = siteConfig.comments.artalk.site
const { title = '' } = Astro.props;
--- ---
<div> <div>
<!-- Artalk --> <!-- Artalk -->
<div id="comments" data-path={Astro.url.pathname} data-server={ArtalkInstanceDomain}></div> <div id="comments" data-path={Astro.url.pathname} data-title={title} data-server={ArtalkInstanceDomain} data-site={ArtalkInstanceSite}></div>
<script> <script>
import Artalk from "artalk"; import Artalk from "artalk";
@ -16,7 +19,9 @@ const ArtalkInstanceDomain = siteConfig.comments.artalk.instanceDomain
Artalk.init({ Artalk.init({
el: '#comments', el: '#comments',
pageKey: atkElement?.getAttribute('data-path') || window.location.pathname, pageKey: atkElement?.getAttribute('data-path') || window.location.pathname,
pageTitle: atkElement?.getAttribute('data-title') || document.title,
server: `https://${atkElement?.getAttribute('data-server')}`, server: `https://${atkElement?.getAttribute('data-server')}`,
site: atkElement?.getAttribute('data-site') || 'default',
darkMode: "auto", darkMode: "auto",
versionCheck: false versionCheck: false
}); });

View file

@ -54,6 +54,7 @@ export const siteConfig = {
type: 'artalk', // 'artalk','giscus','fediverse','email','hatsu','oom','twikoo','waline' type: 'artalk', // 'artalk','giscus','fediverse','email','hatsu','oom','twikoo','waline'
artalk: { artalk: {
instanceDomain: '', // the domain of your artalk instance instanceDomain: '', // the domain of your artalk instance
site: '', // the site name of the current site in artalk dashboard, default is "default"
}, },
giscus: { giscus: {
// get these params from giscus.app // get these params from giscus.app

View file

@ -83,7 +83,7 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
<ReplyViaEmail title={entry.data.title} email={authorInfo[0].email} /> <ReplyViaEmail title={entry.data.title} email={authorInfo[0].email} />
<br> <br>
<a href="/blog">&larr; {t('article.back_to_posts')}</a> <a href="/blog">&larr; {t('article.back_to_posts')}</a>
{!noscript && <h2>{t('article.comments')}</h2> <Comments />} {!noscript && <h2>{t('article.comments')}</h2> <Comments pageTitle={entry.data.title} />}
{!noscript && {!noscript &&
<script> <script>
import "katex/dist/contrib/copy-tex.js" import "katex/dist/contrib/copy-tex.js"