mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-17 18:22:33 +00:00
Add body option to gitalk configuration to support custom issue content (#877)
Co-authored-by: Mimi <1119186082@qq.com>
This commit is contained in:
parent
2a6af757f2
commit
fd72e89ba7
@ -733,6 +733,10 @@ gitalk:
|
|||||||
# If you want everyone visiting your site to see a uniform language, you can set a force language value
|
# 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
|
# Available values: en | es-ES | fr | ru | zh-CN | zh-TW
|
||||||
language:
|
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
|
# Utterances
|
||||||
# For more information: https://utteranc.es
|
# For more information: https://utteranc.es
|
||||||
|
|||||||
17
source/js/third-party/comments/gitalk.js
vendored
17
source/js/third-party/comments/gitalk.js
vendored
@ -3,6 +3,20 @@
|
|||||||
document.addEventListener('page:loaded', async () => {
|
document.addEventListener('page:loaded', async () => {
|
||||||
if (!CONFIG.page.comments) return;
|
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.loadComments('.gitalk-container');
|
||||||
await NexT.utils.getScript(CONFIG.gitalk.js, {
|
await NexT.utils.getScript(CONFIG.gitalk.js, {
|
||||||
condition: window.Gitalk
|
condition: window.Gitalk
|
||||||
@ -16,7 +30,8 @@ document.addEventListener('page:loaded', async () => {
|
|||||||
id : CONFIG.gitalk.path_md5,
|
id : CONFIG.gitalk.path_md5,
|
||||||
proxy : CONFIG.gitalk.proxy,
|
proxy : CONFIG.gitalk.proxy,
|
||||||
language : CONFIG.gitalk.language || window.navigator.language,
|
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'));
|
gitalk.render(document.querySelector('.gitalk-container'));
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user