Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
shlu committed Dec 23, 2024
1 parent 56cf12a commit 98d3216
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 147 deletions.
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ commonmark:
#markdown: redcarpet
#redcarpet:
# extensions: ["autolink", "no_intra_emphasis", "tables", "strikethrough"]

lang: zh-CN
permalink: pretty
readme_index:
enabled: true
Expand Down
171 changes: 25 additions & 146 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,154 +27,33 @@ <h1><a href="{{ "/" | absolute_url }}">{{ site.title }}</a></h1>

{{ content }}

<!-- comments config BEGIN -->
<script
data-repo="xpko/xpko.github.io"
data-repo-id="MDEwOlJlcG9zaXRvcnkyNzM0NTQzNjk="
data-category="blog-comments"
data-category-id="DIC_kwDOEEyVIc4CldBL"
data-mapping="pathname"
data-strict="0"
data-reactions-enabled="1"
data-emit-metadata="0"
data-input-position="bottom"
data-theme="preferred_color_scheme"
data-lang="zh-CN"
crossorigin="anonymous"
async
>
(function(){
function h(a){return'[giscus] An error occurred. Error message: "'.concat(a,'".')}
function l(a,g){void 0===g&&(g=!1);g=g?"meta[property='og:".concat(a,"'],"):"";return(a=document.querySelector(g+"meta[name='".concat(a,"']")))?a.content:""}
function p(){delete c.session;var a="".concat(k,"/widget?").concat(new URLSearchParams(c));e.src=a}
var m = null, // 不再依赖 document.currentScript
k = "https://giscus.app", // 手动指定 origin
b = new URL(location.href),
d = b.searchParams.get("giscus") || "",
n = localStorage.getItem("giscus-session");
b.searchParams.delete("giscus");
b.hash = "";
var f = b.toString();
if(d) {
localStorage.setItem("giscus-session", JSON.stringify(d));
history.replaceState(void 0, document.title, f);
}
else if(n) {
try {
d = JSON.parse(n);
} catch(a) {
localStorage.removeItem("giscus-session");
console.warn("".concat(h(null===a||void 0===a?void 0:a.message)," Session has been cleared."));
}
}
b = {
theme: "preferred_color_scheme",
reactionsEnabled: "1",
emitMetadata: "0",
inputPosition: "bottom",
repo: "xpko/xpko.github.io",
repoId: "MDEwOlJlcG9zaXRvcnkyNzM0NTQzNjk=",
category: "blog-comments",
categoryId: "DIC_kwDOEEyVIc4CldBL",
strict: "0",
lang: "zh-CN"
};
var c = {
origin: f,
session: d,
theme: b.theme,
reactionsEnabled: b.reactionsEnabled || "1",
emitMetadata: b.emitMetadata || "0",
inputPosition: b.inputPosition || "bottom",
repo: b.repo,
repoId: b.repoId,
category: b.category || "",
categoryId: b.categoryId,
strict: b.strict || "0",
description: l("description", !0),
backLink: l("giscus:backlink") || f,
mapping: "pathname",
term: 2 > location.pathname.length ? "index" : decodeURIComponent(location.pathname.substring(1).replace(/\.\w+$/, ""))
};
var q = (d = document.querySelector(".giscus")) && d.id;
if(q) {
c.origin = "".concat(f, "#").concat(q);
}
f = b.lang ? "/".concat(b.lang) : "";
f = "".concat(k).concat(f, "/widget?").concat(new URLSearchParams(c));
b = "lazy" === "async" ? "lazy" : void 0;
var e = document.createElement("iframe");
Object.entries({
class: "giscus-frame giscus-frame--loading",
title: "Comments",
scrolling: "no",
allow: "clipboard-write",
src: f,
loading: b
}).forEach(function(a){
var g = a[0];
return (a = a[1]) && e.setAttribute(g, a);
});
e.style.opacity = "0";
e.addEventListener("load", function(){
e.style.removeProperty("opacity");
e.classList.remove("giscus-frame--loading");
});
b = document.getElementById("giscus-css") || document.createElement("link");
b.id = "giscus-css";
b.rel = "stylesheet";
b.href = "".concat(k, "/default.css");
document.head.prepend(b);
if(d){
for(; d.firstChild;) d.firstChild.remove();
d.appendChild(e);
} else {
d = document.createElement("div");
d.setAttribute("class", "giscus");
d.appendChild(e);
// 由于没有 currentScript,手动插入到合适的位置,例如 body 末尾
document.body.insertAdjacentElement("beforeend", d);
}
window.addEventListener("message", function(a){
if(a.origin === k){
a = a.data;
if("object" === typeof a && a.giscus){
if(a.giscus.resizeHeight){
e.style.height = "".concat(a.giscus.resizeHeight, "px");
}
if(a.giscus.signOut){
localStorage.removeItem("giscus-session");
console.log("[giscus] User has logged out. Session has been cleared.");
p();
}
if(a.giscus.error){
a = a.giscus.error;
if(a.includes("Bad credentials") || a.includes("Invalid state value") || a.includes("State has expired")){
if(null !== localStorage.getItem("giscus-session")){
localStorage.removeItem("giscus-session");
console.warn("".concat(h(a), " Session has been cleared."));
p();
} else if(!n){
console.error("".concat(h(a), " No session is stored initially. ").concat("Please consider reporting this error at https://github.com/giscus/giscus/issues/new."));
}
}
else if(a.includes("Discussion not found")){
console.warn("[giscus] ".concat(a, ". A new discussion will be created if a comment/reaction is submitted."));
}
else if(a.includes("API rate limit exceeded")){
console.warn(h(a));
}
else {
console.error("".concat(h(a), " ").concat("Please consider reporting this error at https://github.com/giscus/giscus/issues/new."));
}
}
}
}
});
})();
<!-- comments config BEGIN -->

<!-- src="https://giscus.app/client.js" 自定义client.js-->
<script
data-repo="xpko/xpko.github.io"
data-repo-id="MDEwOlJlcG9zaXRvcnkyNzM0NTQzNjk="
data-category="blog-comments"
data-category-id="DIC_kwDOEEyVIc4CldBL"
data-mapping="pathname"
data-strict="0"
data-reactions-enabled="1"
data-emit-metadata="0"
data-input-position="bottom"
data-theme="preferred_color_scheme"
data-lang="zh-CN"
crossorigin="anonymous"
async>
(function(){function h(a){return'[giscus] An error occurred. Error message: "'.concat(a,'".')}function l(a,g){void 0===g&&(g=!1);g=g?"meta[property='og:".concat(a,"'],"):"";return(a=document.querySelector(g+"meta[name='".concat(a,"']")))?a.content:""}function p(){delete c.session;var a="".concat(k,"/widget?").concat(new URLSearchParams(c));e.src=a}var m=document.currentScript,k="https://giscus.app",b=new URL(location.href),d=b.searchParams.get("giscus")||"",n=localStorage.getItem("giscus-session");
b.searchParams.delete("giscus");b.hash="";var f=b.toString();if(d)localStorage.setItem("giscus-session",JSON.stringify(d)),history.replaceState(void 0,document.title,f);else if(n)try{d=JSON.parse(n)}catch(a){localStorage.removeItem("giscus-session"),console.warn("".concat(h(null===a||void 0===a?void 0:a.message)," Session has been cleared."))}b=m.dataset;var c={};c.origin=f;c.session=d;c.theme=b.theme;c.reactionsEnabled=b.reactionsEnabled||"1";c.emitMetadata=b.emitMetadata||"0";c.inputPosition=b.inputPosition||
"bottom";c.repo=b.repo;c.repoId=b.repoId;c.category=b.category||"";c.categoryId=b.categoryId;c.strict=b.strict||"0";c.description="";c.backLink=`[web link](${l("giscus:backlink")||f})`;switch(b.mapping){case "url":c.term=f;break;case "title":c.term=document.title;break;case "og:title":c.term=l("title",!0);break;case "specific":c.term=b.term;break;case "number":c.number=b.term;break;default:c.term=2>location.pathname.length?"index":decodeURIComponent(location.pathname.substring(1).replace(/\.\w+$/,""))}var q=(d=document.querySelector(".giscus"))&&
d.id;q&&(c.origin="".concat(f,"#").concat(q));f=b.lang?"/".concat(b.lang):"";f="".concat(k).concat(f,"/widget?").concat(new URLSearchParams(c));b="lazy"===b.loading?"lazy":void 0;var e=document.createElement("iframe");Object.entries({class:"giscus-frame giscus-frame--loading",title:"Comments",scrolling:"no",allow:"clipboard-write",src:f,loading:b}).forEach(function(a){var g=a[0];return(a=a[1])&&e.setAttribute(g,a)});e.style.opacity="0";e.addEventListener("load",function(){e.style.removeProperty("opacity");
e.classList.remove("giscus-frame--loading")});b=document.getElementById("giscus-css")||document.createElement("link");b.id="giscus-css";b.rel="stylesheet";b.href="".concat(k,"/default.css");document.head.prepend(b);if(d){for(;d.firstChild;)d.firstChild.remove();d.appendChild(e)}else d=document.createElement("div"),d.setAttribute("class","giscus"),d.appendChild(e),m.insertAdjacentElement("afterend",d);window.addEventListener("message",function(a){a.origin===k&&(a=a.data,"object"===typeof a&&a.giscus&&
(a.giscus.resizeHeight&&(e.style.height="".concat(a.giscus.resizeHeight,"px")),a.giscus.signOut?(localStorage.removeItem("giscus-session"),console.log("[giscus] User has logged out. Session has been cleared."),p()):a.giscus.error&&(a=a.giscus.error,a.includes("Bad credentials")||a.includes("Invalid state value")||a.includes("State has expired")?null!==localStorage.getItem("giscus-session")?(localStorage.removeItem("giscus-session"),console.warn("".concat(h(a)," Session has been cleared.")),p()):n||
console.error("".concat(h(a)," No session is stored initially. ").concat("Please consider reporting this error at https://github.com/giscus/giscus/issues/new.")):a.includes("Discussion not found")?console.warn("[giscus] ".concat(a,". A new discussion will be created if a comment/reaction is submitted.")):a.includes("API rate limit exceeded")?console.warn(h(a)):console.error("".concat(h(a)," ").concat("Please consider reporting this error at https://github.com/giscus/giscus/issues/new.")))))})})();
</script>
<!-- comments config END -->

<!-- comments config END -->

{% if site.github.private != true and site.github.license %}
<div class="footer border-top border-gray-light mt-5 pt-3 text-right text-gray">
Expand Down
26 changes: 26 additions & 0 deletions github/为Jekyll添加评论系统.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 为Jekyll添加评论系统

目前使用的是:https://giscus.app

直接按官方文档提示操作即可

## 自定义client.js

原始js:https://giscus.app/client.js

```js
(function(){function h(a){return'[giscus] An error occurred. Error message: "'.concat(a,'".')}function l(a,g){void 0===g&&(g=!1);g=g?"meta[property='og:".concat(a,"'],"):"";return(a=document.querySelector(g+"meta[name='".concat(a,"']")))?a.content:""}function p(){delete c.session;var a="".concat(k,"/widget?").concat(new URLSearchParams(c));e.src=a}var m=document.currentScript,k=(new URL(m.src)).origin,b=new URL(location.href),d=b.searchParams.get("giscus")||"",n=localStorage.getItem("giscus-session");
b.searchParams.delete("giscus");b.hash="";var f=b.toString();if(d)localStorage.setItem("giscus-session",JSON.stringify(d)),history.replaceState(void 0,document.title,f);else if(n)try{d=JSON.parse(n)}catch(a){localStorage.removeItem("giscus-session"),console.warn("".concat(h(null===a||void 0===a?void 0:a.message)," Session has been cleared."))}b=m.dataset;var c={};c.origin=f;c.session=d;c.theme=b.theme;c.reactionsEnabled=b.reactionsEnabled||"1";c.emitMetadata=b.emitMetadata||"0";c.inputPosition=b.inputPosition||
"bottom";c.repo=b.repo;c.repoId=b.repoId;c.category=b.category||"";c.categoryId=b.categoryId;c.strict=b.strict||"0";c.description=l("description",!0);c.backLink=l("giscus:backlink")||f;switch(b.mapping){case "url":c.term=f;break;case "title":c.term=document.title;break;case "og:title":c.term=l("title",!0);break;case "specific":c.term=b.term;break;case "number":c.number=b.term;break;default:c.term=2>location.pathname.length?"index":location.pathname.substring(1).replace(/\.\w+$/,"")}var q=(d=document.querySelector(".giscus"))&&
d.id;q&&(c.origin="".concat(f,"#").concat(q));f=b.lang?"/".concat(b.lang):"";f="".concat(k).concat(f,"/widget?").concat(new URLSearchParams(c));b="lazy"===b.loading?"lazy":void 0;var e=document.createElement("iframe");Object.entries({class:"giscus-frame giscus-frame--loading",title:"Comments",scrolling:"no",allow:"clipboard-write",src:f,loading:b}).forEach(function(a){var g=a[0];return(a=a[1])&&e.setAttribute(g,a)});e.style.opacity="0";e.addEventListener("load",function(){e.style.removeProperty("opacity");
e.classList.remove("giscus-frame--loading")});b=document.getElementById("giscus-css")||document.createElement("link");b.id="giscus-css";b.rel="stylesheet";b.href="".concat(k,"/default.css");document.head.prepend(b);if(d){for(;d.firstChild;)d.firstChild.remove();d.appendChild(e)}else d=document.createElement("div"),d.setAttribute("class","giscus"),d.appendChild(e),m.insertAdjacentElement("afterend",d);window.addEventListener("message",function(a){a.origin===k&&(a=a.data,"object"===typeof a&&a.giscus&&
(a.giscus.resizeHeight&&(e.style.height="".concat(a.giscus.resizeHeight,"px")),a.giscus.signOut?(localStorage.removeItem("giscus-session"),console.log("[giscus] User has logged out. Session has been cleared."),p()):a.giscus.error&&(a=a.giscus.error,a.includes("Bad credentials")||a.includes("Invalid state value")||a.includes("State has expired")?null!==localStorage.getItem("giscus-session")?(localStorage.removeItem("giscus-session"),console.warn("".concat(h(a)," Session has been cleared.")),p()):n||
console.error("".concat(h(a)," No session is stored initially. ").concat("Please consider reporting this error at https://github.com/giscus/giscus/issues/new.")):a.includes("Discussion not found")?console.warn("[giscus] ".concat(a,". A new discussion will be created if a comment/reaction is submitted.")):a.includes("API rate limit exceeded")?console.warn(h(a)):console.error("".concat(h(a)," ").concat("Please consider reporting this error at https://github.com/giscus/giscus/issues/new.")))))})})();
```

补丁位置:支持url解码,否则评论里标题不显示中文

![image-20241223151219375](./为Jekyll添加评论系统/image-20241223151219375.png)

![image-20241223151447138](./为Jekyll添加评论系统/image-20241223151447138.png)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 98d3216

Please sign in to comment.