Add body option to gitalk configuration to support custom issue content (#877)

Co-authored-by: Mimi <1119186082@qq.com>
This commit is contained in:
TootsCharlie 2025-11-03 20:55:40 +08:00 committed by GitHub
parent 2a6af757f2
commit fd72e89ba7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View File

@ -733,6 +733,10 @@ gitalk:
# If you want everyone visiting your site to see a uniform language, you can set a force language value
# Available values: en | es-ES | fr | ru | zh-CN | zh-TW
language:
# If you want to customize the content of the initialized Issue, please edit the body parameter.
# For example:
# body: Comments for post ${title}, see ${url}
body:
# Utterances
# For more information: https://utteranc.es

View File

@ -3,6 +3,20 @@
document.addEventListener('page:loaded', async () => {
if (!CONFIG.page.comments) return;
// Parse and replace body expressions
const allowed = {
title: document.title,
url : location.href,
path : location.pathname,
lang : navigator.language
};
const parsedBody = CONFIG.gitalk.body?.replace(/\$\{([^}]+)}/g, (_, keyRaw) => {
const key = keyRaw.trim();
if (!/^[A-Za-z0-9_]+$/.test(key)) return '';
return String(allowed[key] ?? '');
});
await NexT.utils.loadComments('.gitalk-container');
await NexT.utils.getScript(CONFIG.gitalk.js, {
condition: window.Gitalk
@ -16,7 +30,8 @@ document.addEventListener('page:loaded', async () => {
id : CONFIG.gitalk.path_md5,
proxy : CONFIG.gitalk.proxy,
language : CONFIG.gitalk.language || window.navigator.language,
distractionFreeMode: CONFIG.gitalk.distraction_free_mode
distractionFreeMode: CONFIG.gitalk.distraction_free_mode,
body : parsedBody
});
gitalk.render(document.querySelector('.gitalk-container'));
});