Skip to content
4 changes: 4 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion source/js/third-party/comments/gitalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'));
});