From 2b51bb1ce7b7f5f3ec5f3c9cbb2c89e90dc48c8a Mon Sep 17 00:00:00 2001 From: Meekdai Date: Sat, 12 Aug 2023 13:14:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E7=94=A8jinja2=E9=87=8D=E6=9E=84html?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=90=8E=E7=BB=AD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8D=E5=90=8C=E7=9A=84=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gmeek.js | 206 +++++++------------------------------ Gmeek.py | 48 +++++---- icon.js | 2 +- dark.jpg => img/dark.jpg | Bin light.jpg => img/light.jpg | Bin plist_example.html | 88 ---------------- post_example.html | 73 ------------- requirements.txt | 1 + templates/base.html | 42 ++++++++ templates/footer.html | 14 +++ templates/plist.html | 92 +++++++++++++++++ templates/post.html | 55 ++++++++++ 12 files changed, 271 insertions(+), 350 deletions(-) rename dark.jpg => img/dark.jpg (100%) rename light.jpg => img/light.jpg (100%) delete mode 100644 plist_example.html delete mode 100644 post_example.html create mode 100644 templates/base.html create mode 100644 templates/footer.html create mode 100644 templates/plist.html create mode 100644 templates/post.html diff --git a/Gmeek.js b/Gmeek.js index f7c7e16..836f7b6 100644 --- a/Gmeek.js +++ b/Gmeek.js @@ -1,33 +1,4 @@ -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();} @@ -58,144 +29,45 @@ function utterancesTheme(theme){ 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","site:"+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"); - if(postListJson[num]["top"]==0){ - svg.setAttributeNS(null,"style","witdh:16px;height:16px"); - path.setAttributeNS(null, "d", IconList["post"]); - } - else{ - svg.setAttributeNS(null,"style","witdh:16px;height:16px;color:red"); - path.setAttributeNS(null, "d", IconList["upload"]); - } - - 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"; - } - } - } - - - +iconTOP=document.getElementsByClassName("svgTop1"); +iconPost=document.getElementsByClassName("svgTop0"); +for(var i=0;i0){ - 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"); - } - } - } - +for(var i=0;i - - - - - - - - - - -
-

- - -
- - - - - - - - - -
- - -
-

-

- - -
- - - - - diff --git a/post_example.html b/post_example.html deleted file mode 100644 index e7e6b21..0000000 --- a/post_example.html +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - -
-

-
-
- - - - - -
-

-
- - -
- - -
- - - - - diff --git a/requirements.txt b/requirements.txt index 67c1047..5a3f436 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ PyGithub requests xpinyin feedgen +Jinja2 diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..5447186 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,42 @@ + + + + + + + + + {% block title %}{% endblock %} + + +{% block style %}{% endblock %} + + + +
{% block content %}{% endblock %}
+ + + + + +{% block script %}{% endblock %} + + diff --git a/templates/footer.html b/templates/footer.html new file mode 100644 index 0000000..84fdcd9 --- /dev/null +++ b/templates/footer.html @@ -0,0 +1,14 @@ +Copyright © {{ blogBase['title'] }}

{{ blogBase['filingNum'] }} Powered by Gmeek

+ + + diff --git a/templates/plist.html b/templates/plist.html new file mode 100644 index 0000000..cb038b0 --- /dev/null +++ b/templates/plist.html @@ -0,0 +1,92 @@ +{% extends 'base.html' %} + +{% block title%}{{ blogBase['title'] }}{% endblock %} + +{% block style %} + +{% endblock %} + +{% block header %} +

+ + {{ blogBase['displayTitle'] }} +

+
+ + {% for num in postListJson %} + {% if postListJson[num]['label'] in blogBase['singlePage'] %} + + {% endif %} + {% endfor %} + + +
+{% endblock %} + +{% block content %} +
{{ blogBase['subTitle'] }}
+ + +{% endblock %} + +{% block script %} + +{% endblock %} diff --git a/templates/post.html b/templates/post.html new file mode 100644 index 0000000..a577d5e --- /dev/null +++ b/templates/post.html @@ -0,0 +1,55 @@ +{% extends 'base.html' %} + +{% block title%}{{ blogBase['title'] }}{% endblock %} + +{% block style %} + +{% endblock %} + +{% block header %} +

+ {{ blogBase['postTitle'] }} +

+
+ + + + + + + +
+{% endblock %} + +{% block content %} +
+{{ blogBase['postBody'] }} +
+ +
+{% endblock %} + +{% block script %} + +{% endblock %}