独立JS文件,使用jsdelivr CDN

This commit is contained in:
呆瓜云 2023-08-01 14:57:28 +08:00
parent b61a183ca3
commit 281c0b09ef
5 changed files with 216 additions and 234 deletions

192
Gmeek.js Normal file
View File

@ -0,0 +1,192 @@
if(typeof(blogBase["subTitle"])=='undefined'){htmlType="post";}
else{htmlType="plist";}
var i18nEN=["switch theme","Run "," days","links","about me","Search","Home","Comments","Loading"];
var i18nCN=["切换主题", "网站运行","天","友情链接","关于", "搜索", "首页", "评论", "加载中"];
if(blogBase["i18n"]=="CN"){var i18n=i18nCN;}
else{var i18n=i18nEN;}
if(blogBase["startSite"]!=""){
var now=new Date();
var startSite=new Date(blogBase["startSite"]);
var diff=now.getTime()-startSite.getTime();
var diffDay=Math.floor(diff/(1000*60*60*24));
document.getElementById("year").innerHTML=now.getFullYear();
document.getElementById("runday").innerHTML=i18n[1]+diffDay+i18n[2]+" • ";
}
if(blogBase["filingNum"]!=""){document.getElementById("filingNum").innerHTML=blogBase["filingNum"]+" • ";}
document.getElementById("footerblogTitle").innerHTML=blogBase["title"];
document.getElementById("footerblogTitle").href=blogBase["homeUrl"];
if(blogBase["faviconUrl"]!=""){
link=document.createElement("link");
link.setAttribute("rel","icon");
link.setAttribute("href",blogBase["faviconUrl"]);
document.head.appendChild(link);
}
document.getElementById("changeTheme").setAttribute("title",i18n[0]);
document.getElementById("themeSwitch").setAttribute("d",value=IconList["sun"]);
if(localStorage.getItem("meek_theme")==null){localStorage.setItem("meek_theme","light")}
else if(localStorage.getItem("meek_theme")=="dark"){changeDark();}
else if(localStorage.getItem("meek_theme")=="light"){changeLight();}
var utterancesLoad=0
if(localStorage.getItem("meek_theme")==null){localStorage.setItem("meek_theme","light")}
else if(localStorage.getItem("meek_theme")=="dark"){changeDark();}
else if(localStorage.getItem("meek_theme")=="light"){changeLight();}
function changeDark(){
document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="dark";
document.getElementById("themeSwitch").attributes.getNamedItem("d").value=IconList["moon"];
if(utterancesLoad==1){utterancesTheme("dark-blue");}
}
function changeLight(){
document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="light";
document.getElementById("themeSwitch").attributes.getNamedItem("d").value=IconList["sun"];
if(utterancesLoad==1){utterancesTheme("github-light");}
}
function modeSwitch(){
if(document.getElementsByTagName("html")[0].attributes[0].value=="light"){changeDark();localStorage.setItem("meek_theme","dark");}
else{changeLight();localStorage.setItem("meek_theme","light");}
}
function utterancesTheme(theme){
const message = {type: 'set-theme',theme: theme};
const iframe = document.getElementsByClassName('utterances-frame')[0];
iframe.contentWindow.postMessage(message, 'https://utteranc.es');
}
console.log("\n %c Gmeek "+blogBase["GMEEK_VERSION"]+" %c https://github.com/Meekdai/Gmeek \n\n", "color: #fff; background-image: linear-gradient(90deg, rgb(47, 172, 178) 0%, rgb(45, 190, 96) 100%); padding:5px 1px;", "background-image: linear-gradient(90deg, rgb(45, 190, 96) 0%, rgb(255, 255, 255) 100%); padding:5px 0;");
if(htmlType=="plist"){
var postListJson=blogBase["postListJson"];
document.title=blogBase["title"];
document.getElementById("avatarImg").src=blogBase["avatarUrl"];
document.getElementById("blogTitle").innerHTML=blogBase["displayTitle"];
document.getElementById("blogSubTitle").innerHTML=blogBase["subTitle"];
document.getElementById("searchSite").setAttribute("value",blogBase["homeUrl"]);
document.getElementById("buttonRSS").childNodes[0].childNodes[0].setAttribute("d",value=IconList["rss"]);
document.getElementById("buttonLink").setAttribute("title",i18n[3]);
document.getElementById("buttonAbout").setAttribute("title",i18n[4]);
document.getElementById("buttonSearch").innerHTML=i18n[5];
document.getElementById("searchSVG").setAttribute("d",value=IconList["search"]);
var navList=document.getElementById("navList");
for(var num in postListJson){
if(blogBase["singlePage"].indexOf(postListJson[num]["label"])==-1){
SideNavItem=document.createElement("a");
SideNavItem.setAttribute("class", "SideNav-item d-flex flex-items-center flex-justify-between");
SideNavItem.setAttribute("href", postListJson[num]["postUrl"]);
div=document.createElement("div");
svg=document.createElementNS('http://www.w3.org/2000/svg','svg');
path=document.createElementNS("http://www.w3.org/2000/svg","path");
span=document.createElement("span");
div.setAttribute("class","d-flex flex-items-center");
svg.setAttributeNS(null,"class","SideNav-icon octicon");
svg.setAttributeNS(null,"style","witdh:16px;height:16px");
path.setAttributeNS(null, "d", IconList["post"]);
span.innerHTML=postListJson[num]["postTitle"];
svg.appendChild(path);
div.appendChild(svg);
div.appendChild(span);
SideNavItem.appendChild(div);
div=document.createElement("div");
div.setAttribute("class","listLabels");
if(postListJson[num]["commentNum"]>0){
span=document.createElement("span");
span.setAttribute("class","Label");
span.setAttribute("style","background-color:"+blogBase["commentLabelColor"]);
span.innerHTML=postListJson[num]["commentNum"];
div.appendChild(span);
}
span=document.createElement("span");
span.setAttribute("class","Label");
span.setAttribute("style","background-color:"+postListJson[num]["labelColor"]);
span.innerHTML=postListJson[num]["label"];
div.appendChild(span);
span=document.createElement("span");
span.setAttribute("class","Label");
span.setAttribute("style","background-color:"+postListJson[num]["dateLabelColor"]);
date=new Date(postListJson[num]["createdAt"] * 1000);
span.innerHTML=date.getFullYear()+"-"+(date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1)+"-"+(date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
div.appendChild(span);
SideNavItem.appendChild(div);
navList.appendChild(SideNavItem);
}
else{
if(postListJson[num]["label"]=="link"){
document.getElementById("buttonLink").childNodes[0].childNodes[0].setAttribute("d",value=IconList["link"]);
document.getElementById("buttonLink").style="display:block";
}
else if(postListJson[num]["label"]=="about"){
document.getElementById("buttonAbout").childNodes[0].childNodes[0].setAttribute("d",value=IconList["person"]);
document.getElementById("buttonAbout").style="display:block";
}
}
}
}
else{
document.title=blogBase["postTitle"];
document.getElementById("postTitle").innerHTML=blogBase["postTitle"];
document.getElementById("postBody").innerHTML=blogBase["postBody"];
document.getElementById("buttonHome").setAttribute("title",i18n[6]);
document.getElementById("cmButton").innerHTML=i18n[7];
function gotoSource(){window.open(blogBase["postSourceUrl"]);}
document.getElementById("pathHome").setAttribute("d",value=IconList["home"]);
document.getElementById("pathIssue").setAttribute("d",value=IconList["github"]);
if(blogBase["commentNum"]>0){
cmButton=document.getElementById("cmButton");
span=document.createElement("span");
span.setAttribute("class","Counter");
span.innerHTML=blogBase["commentNum"];
cmButton.appendChild(span);
}
function openComments(){
cm=document.getElementById("comments");
cmButton=document.getElementById("cmButton");
cmButton.innerHTML=i18n[8];
span=document.createElement("span");
span.setAttribute("class","AnimatedEllipsis");
cmButton.appendChild(span);
script=document.createElement("script");
script.setAttribute("src","https://utteranc.es/client.js");
script.setAttribute("repo",blogBase["repoName"]);
script.setAttribute("issue-term","title");
if(localStorage.getItem("meek_theme")=="dark"){script.setAttribute("theme","dark-blue");}
else{script.setAttribute("theme","github-light");}
script.setAttribute("crossorigin","anonymous");
script.setAttribute("async","");
cm.appendChild(script);
int=self.setInterval("iFrameLoading()",200);
}
function iFrameLoading(){
var utterances=document.getElementsByClassName('utterances');
if(utterances.length==1){
if(utterances[0].style.height!=""){
utterancesLoad=1;
int=window.clearInterval(int);
document.getElementById("cmButton").style.display="none";
console.log("utterances Load OK");
}
}
}
}

View File

@ -42,10 +42,11 @@ class GMEEK():
if os.path.exists("backup/"):
shutil.rmtree("backup/")
if os.path.exists(self.post_dir):
shutil.rmtree(self.post_dir)
if os.path.exists(self.root_dir):
shutil.rmtree(self.root_dir)
os.mkdir("backup/")
os.mkdir(self.root_dir)
os.mkdir(self.post_dir)

View File

@ -42,7 +42,7 @@ h1 a{margin-left: 4px;margin-top: 16px;}
.SideNav-item .Label{color: #fff;margin-left:8px;}
.footer {margin: 40px auto; text-align: center;font-size: small;}
</style>
<script>var blogBase=%s</script>
<body>
<div class="markdown-body">
<h1>
@ -72,131 +72,17 @@ h1 a{margin-left: 4px;margin-top: 16px;}
</div>
</body>
<script src="./static/icon.js"></script>
<script>
var blogBase=%s
var i18nEN=["switch theme","Run "," days","links","about me","Search"];
var i18nCN=["切换主题","网站运行","天","友情链接","关于","搜索"];
if(blogBase["i18n"]=="CN"){var i18n=i18nCN;}
else{var i18n=i18nEN;}
if(blogBase["startSite"]!=""){
var now=new Date();
var startSite=new Date(blogBase["startSite"]);
var diff=now.getTime()-startSite.getTime();
var diffDay=Math.floor(diff/(1000*60*60*24));
document.getElementById("year").innerHTML=now.getFullYear();
document.getElementById("runday").innerHTML=i18n[1]+diffDay+i18n[2]+" • ";
}
var postListJson=blogBase["postListJson"]
document.title=blogBase["title"];
document.getElementById("avatarImg").src=blogBase["avatarUrl"];
document.getElementById("blogTitle").innerHTML=blogBase["displayTitle"];
document.getElementById("blogSubTitle").innerHTML=blogBase["subTitle"];
document.getElementById("searchSite").setAttribute("value",blogBase["homeUrl"]);
document.getElementById("buttonRSS").childNodes[0].childNodes[0].setAttribute("d",value=IconList["rss"]);
document.getElementById("changeTheme").setAttribute("title",i18n[0]);
document.getElementById("buttonLink").setAttribute("title",i18n[3]);
document.getElementById("buttonAbout").setAttribute("title",i18n[4]);
document.getElementById("buttonSearch").innerHTML=i18n[5];
if(blogBase["filingNum"]!=""){document.getElementById("filingNum").innerHTML=blogBase["filingNum"]+" • ";}
document.getElementById("footerblogTitle").innerHTML=blogBase["title"];
document.getElementById("footerblogTitle").href=blogBase["homeUrl"];
var navList=document.getElementById("navList");
if(blogBase["faviconUrl"]!=""){
link=document.createElement("link");
link.setAttribute("rel","icon");
link.setAttribute("href",blogBase["faviconUrl"]);
document.head.appendChild(link);
}
for(var num in postListJson){
if(blogBase["singlePage"].indexOf(postListJson[num]["label"])==-1){
SideNavItem=document.createElement("a");
SideNavItem.setAttribute("class", "SideNav-item d-flex flex-items-center flex-justify-between");
SideNavItem.setAttribute("href", postListJson[num]["postUrl"]);
div=document.createElement("div");
svg=document.createElementNS('http://www.w3.org/2000/svg','svg');
path=document.createElementNS("http://www.w3.org/2000/svg","path");
span=document.createElement("span");
div.setAttribute("class","d-flex flex-items-center");
svg.setAttributeNS(null,"class","SideNav-icon octicon");
svg.setAttributeNS(null,"style","witdh:16px;height:16px");
path.setAttributeNS(null, "d", IconList["post"]);
span.innerHTML=postListJson[num]["postTitle"];
svg.appendChild(path);
div.appendChild(svg);
div.appendChild(span);
SideNavItem.appendChild(div);
div=document.createElement("div");
div.setAttribute("class","listLabels");
if(postListJson[num]["commentNum"]>0){
span=document.createElement("span");
span.setAttribute("class","Label");
span.setAttribute("style","background-color:"+blogBase["commentLabelColor"]);
span.innerHTML=postListJson[num]["commentNum"];
div.appendChild(span);
}
span=document.createElement("span");
span.setAttribute("class","Label");
span.setAttribute("style","background-color:"+postListJson[num]["labelColor"]);
span.innerHTML=postListJson[num]["label"];
div.appendChild(span);
span=document.createElement("span");
span.setAttribute("class","Label");
span.setAttribute("style","background-color:"+postListJson[num]["dateLabelColor"]);
date=new Date(postListJson[num]["createdAt"] * 1000);
span.innerHTML=date.getFullYear()+"-"+(date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1)+"-"+(date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
div.appendChild(span);
SideNavItem.appendChild(div);
navList.appendChild(SideNavItem);
function addScript(url){
var script = document.createElement('script');
script.setAttribute('type','text/javascript');
script.setAttribute('src',url);
document.body.appendChild(script);
}
else{
if(postListJson[num]["label"]=="link"){
document.getElementById("buttonLink").childNodes[0].childNodes[0].setAttribute("d",value=IconList["link"]);
document.getElementById("buttonLink").style="display:block";
}
else if(postListJson[num]["label"]=="about"){
document.getElementById("buttonAbout").childNodes[0].childNodes[0].setAttribute("d",value=IconList["person"]);
document.getElementById("buttonAbout").style="display:block";
}
window.onload=function(){
addScript("https://cdn.jsdelivr.net/gh/Meekdai/Gmeek@"+blogBase["GMEEK_VERSION"]+"/icon.js" );
addScript("https://cdn.jsdelivr.net/gh/Meekdai/Gmeek@"+blogBase["GMEEK_VERSION"]+"/Gmeek.js" );
}
}
document.getElementById("searchSVG").setAttribute("d",value=IconList["search"]);
document.getElementById("themeSwitch").setAttribute("d",value=IconList["sun"]);
if(localStorage.getItem("meek_theme")==null){localStorage.setItem("meek_theme","light")}
else if(localStorage.getItem("meek_theme")=="dark"){changeDark();}
else if(localStorage.getItem("meek_theme")=="light"){changeLight();}
function changeDark(){
document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="dark";
document.getElementById("themeSwitch").attributes.getNamedItem("d").value=IconList["moon"];
}
function changeLight(){
document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="light";
document.getElementById("themeSwitch").attributes.getNamedItem("d").value=IconList["sun"];
}
function modeSwitch(){
if(document.getElementsByTagName("html")[0].attributes[0].value=="light"){changeDark();localStorage.setItem("meek_theme","dark");}
else{changeLight();localStorage.setItem("meek_theme","light");}
}
console.log("\n %%c Gmeek "+blogBase["GMEEK_VERSION"]+" %%c https://github.com/Meekdai/Gmeek \n\n", "color: #fff; background-image: linear-gradient(90deg, rgb(47, 172, 178) 0%%, rgb(45, 190, 96) 100%%); padding:5px 1px;", "background-image: linear-gradient(90deg, rgb(45, 190, 96) 0%%, rgb(255, 255, 255) 100%%); padding:5px 0;");
</script>
</script>
</html>

View File

@ -33,7 +33,7 @@ h1 {display:flex;}
.footer {margin: 40px auto; text-align: center;font-size: small;}
#cmButton{height:48px;margin-top:48px;}
</style>
<script>var blogBase=%s</script>
<body>
<div class="markdown-body">
<h1>
@ -55,114 +55,17 @@ h1 {display:flex;}
</div>
</body>
<script src="../static/icon.js"></script>
<script>
var blogBase=%s
var i18nEN=["switch theme","Run "," days","Home","Comments","Loading"];
var i18nCN=["切换主题","网站运行","天","首页","评论","加载中"];
if(blogBase["i18n"]=="CN"){var i18n=i18nCN;}
else{var i18n=i18nEN;}
if(blogBase["startSite"]!=""){
var now=new Date();
var startSite=new Date(blogBase["startSite"]);
var diff=now.getTime()-startSite.getTime();
var diffDay=Math.floor(diff/(1000*60*60*24));
document.getElementById("year").innerHTML=now.getFullYear();
document.getElementById("runday").innerHTML=i18n[1]+diffDay+i18n[2]+" • ";
function addScript(url){
var script = document.createElement('script');
script.setAttribute('type','text/javascript');
script.setAttribute('src',url);
document.body.appendChild(script);
}
document.title=blogBase["postTitle"];
document.getElementById("postTitle").innerHTML=blogBase["postTitle"];
document.getElementById("postBody").innerHTML=blogBase["postBody"];
document.getElementById("changeTheme").setAttribute("title",i18n[0]);
document.getElementById("buttonHome").setAttribute("title",i18n[3]);
document.getElementById("cmButton").innerHTML=i18n[4];
if(blogBase["faviconUrl"]!=""){
link=document.createElement("link");
link.setAttribute("rel","icon");
link.setAttribute("href",blogBase["faviconUrl"]);
document.head.appendChild(link);
window.onload=function(){
addScript("https://cdn.jsdelivr.net/gh/Meekdai/Gmeek@"+blogBase["GMEEK_VERSION"]+"/icon.js" );
addScript("https://cdn.jsdelivr.net/gh/Meekdai/Gmeek@"+blogBase["GMEEK_VERSION"]+"/Gmeek.js" );
}
if(blogBase["filingNum"]!=""){document.getElementById("filingNum").innerHTML=blogBase["filingNum"]+" • ";}
document.getElementById("footerblogTitle").innerHTML=blogBase["title"];
document.getElementById("footerblogTitle").href=blogBase["homeUrl"];
function gotoSource(){window.open(blogBase["postSourceUrl"]);}
var utterancesLoad=0
document.getElementById("pathHome").setAttribute("d",value=IconList["home"]);
document.getElementById("pathIssue").setAttribute("d",value=IconList["github"]);
document.getElementById("themeSwitch").setAttribute("d",value=IconList["sun"]);
if(localStorage.getItem("meek_theme")==null){localStorage.setItem("meek_theme","light")}
else if(localStorage.getItem("meek_theme")=="dark"){changeDark();}
else if(localStorage.getItem("meek_theme")=="light"){changeLight();}
function changeDark(){
document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="dark";
document.getElementById("themeSwitch").attributes.getNamedItem("d").value=IconList["moon"];
if(utterancesLoad==1){utterancesTheme("dark-blue");}
}
function changeLight(){
document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="light";
document.getElementById("themeSwitch").attributes.getNamedItem("d").value=IconList["sun"];
if(utterancesLoad==1){utterancesTheme("github-light");}
}
function modeSwitch(){
if(document.getElementsByTagName("html")[0].attributes[0].value=="light"){changeDark();localStorage.setItem("meek_theme","dark");}
else{changeLight();localStorage.setItem("meek_theme","light");}
}
function utterancesTheme(theme){
const message = {type: 'set-theme',theme: theme};
const iframe = document.getElementsByClassName('utterances-frame')[0];
iframe.contentWindow.postMessage(message, 'https://utteranc.es');
}
if(blogBase["commentNum"]>0){
cmButton=document.getElementById("cmButton");
span=document.createElement("span");
span.setAttribute("class","Counter");
span.innerHTML=blogBase["commentNum"];
cmButton.appendChild(span);
}
function openComments(){
cm=document.getElementById("comments");
cmButton=document.getElementById("cmButton");
cmButton.innerHTML=i18n[5];
span=document.createElement("span");
span.setAttribute("class","AnimatedEllipsis");
cmButton.appendChild(span);
script=document.createElement("script");
script.setAttribute("src","https://utteranc.es/client.js");
script.setAttribute("repo",blogBase["repoName"]);
script.setAttribute("issue-term","title");
if(localStorage.getItem("meek_theme")=="dark"){script.setAttribute("theme","dark-blue");}
else{script.setAttribute("theme","github-light");}
script.setAttribute("crossorigin","anonymous");
script.setAttribute("async","");
cm.appendChild(script);
int=self.setInterval("iFrameLoading()",200);
}
function iFrameLoading(){
var utterances=document.getElementsByClassName('utterances');
if(utterances.length==1){
if(utterances[0].style.height!=""){
utterancesLoad=1;
int=window.clearInterval(int);
document.getElementById("cmButton").style.display="none";
console.log("utterances Load OK");
}
}
}
console.log("\n %%c Gmeek "+blogBase["GMEEK_VERSION"]+" %%c https://github.com/Meekdai/Gmeek \n\n", "color: #fff; background-image: linear-gradient(90deg, rgb(47, 172, 178) 0%%, rgb(45, 190, 96) 100%%); padding:5px 1px;", "background-image: linear-gradient(90deg, rgb(45, 190, 96) 0%%, rgb(255, 255, 255) 100%%); padding:5px 0;");
</script>
</html>