添加RSS
This commit is contained in:
parent
03a70359a3
commit
7fc07dc28e
39
Gmeek.py
39
Gmeek.py
@ -9,6 +9,7 @@ import requests
|
|||||||
import argparse
|
import argparse
|
||||||
from github import Github
|
from github import Github
|
||||||
from xpinyin import Pinyin
|
from xpinyin import Pinyin
|
||||||
|
from feedgen.feed import FeedGenerator
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
class GMEEK():
|
class GMEEK():
|
||||||
@ -22,6 +23,7 @@ class GMEEK():
|
|||||||
|
|
||||||
self.plist_example=open('plist_example.html', 'r', encoding='utf-8').read()
|
self.plist_example=open('plist_example.html', 'r', encoding='utf-8').read()
|
||||||
self.post_example=open('post_example.html', 'r', encoding='utf-8').read()
|
self.post_example=open('post_example.html', 'r', encoding='utf-8').read()
|
||||||
|
self.feed = FeedGenerator()
|
||||||
|
|
||||||
user = Github(self.options.github_token)
|
user = Github(self.options.github_token)
|
||||||
self.repo = self.get_repo(user, options.repo_name)
|
self.repo = self.get_repo(user, options.repo_name)
|
||||||
@ -87,7 +89,7 @@ class GMEEK():
|
|||||||
f.close()
|
f.close()
|
||||||
print("create postPage title=%s file=%s " % (issue["postTitle"],gen_Html))
|
print("create postPage title=%s file=%s " % (issue["postTitle"],gen_Html))
|
||||||
|
|
||||||
def creatPlistHtml(self):
|
def createPlistHtml(self):
|
||||||
self.blogBase["postListJson"]=dict(sorted(self.blogBase["postListJson"].items(),key=lambda x:x[1]["createdAt"],reverse=True))#使列表由时间排序
|
self.blogBase["postListJson"]=dict(sorted(self.blogBase["postListJson"].items(),key=lambda x:x[1]["createdAt"],reverse=True))#使列表由时间排序
|
||||||
|
|
||||||
f = open(self.root_dir+"index.html", 'w', encoding='UTF-8')
|
f = open(self.root_dir+"index.html", 'w', encoding='UTF-8')
|
||||||
@ -95,6 +97,30 @@ class GMEEK():
|
|||||||
f.close()
|
f.close()
|
||||||
print("create docs/index.html")
|
print("create docs/index.html")
|
||||||
|
|
||||||
|
def createFeedXml(self):
|
||||||
|
self.blogBase["postListJson"]=dict(sorted(self.blogBase["postListJson"].items(),key=lambda x:x[1]["createdAt"],reverse=False))#使列表由时间排序
|
||||||
|
feed = FeedGenerator()
|
||||||
|
feed.title(self.blogBase["title"])
|
||||||
|
feed.description(self.blogBase["subTitle"])
|
||||||
|
feed.link(href=self.blogBase["homeUrl"])
|
||||||
|
feed.image(url=self.blogBase["avatarUrl"],title="avatar", link=self.blogBase["homeUrl"])
|
||||||
|
feed.pubDate(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()))
|
||||||
|
feed.copyright(self.blogBase["title"])
|
||||||
|
feed.managingEditor(self.blogBase["title"])
|
||||||
|
feed.webMaster(self.blogBase["title"])
|
||||||
|
feed.ttl("60")
|
||||||
|
|
||||||
|
for num in self.blogBase["postListJson"]:
|
||||||
|
item=feed.add_item()
|
||||||
|
item.guid(self.blogBase["homeUrl"]+"/"+self.blogBase["postListJson"][num]["postUrl"],permalink=True)
|
||||||
|
item.title(self.blogBase["postListJson"][num]["postTitle"])
|
||||||
|
item.description(self.blogBase["postListJson"][num]["description"])
|
||||||
|
item.link(href=self.blogBase["homeUrl"]+"/"+self.blogBase["postListJson"][num]["postUrl"])
|
||||||
|
item.pubDate(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(self.blogBase["postListJson"][num]["createdAt"])))
|
||||||
|
|
||||||
|
feed.rss_file(self.root_dir+'rss.xml')
|
||||||
|
|
||||||
|
|
||||||
def addOnePostJson(self,issue):
|
def addOnePostJson(self,issue):
|
||||||
if len(issue.labels)==1:
|
if len(issue.labels)==1:
|
||||||
postNum="P"+str(issue.number)
|
postNum="P"+str(issue.number)
|
||||||
@ -105,6 +131,11 @@ class GMEEK():
|
|||||||
self.blogBase["postListJson"][postNum]["postUrl"]=urllib.parse.quote(self.post_folder+'{}.html'.format(Pinyin().get_pinyin(issue.title)))
|
self.blogBase["postListJson"][postNum]["postUrl"]=urllib.parse.quote(self.post_folder+'{}.html'.format(Pinyin().get_pinyin(issue.title)))
|
||||||
self.blogBase["postListJson"][postNum]["postSourceUrl"]="https://github.com/"+options.repo_name+"/issues/"+str(issue.number)
|
self.blogBase["postListJson"][postNum]["postSourceUrl"]="https://github.com/"+options.repo_name+"/issues/"+str(issue.number)
|
||||||
self.blogBase["postListJson"][postNum]["commentNum"]=issue.get_comments().totalCount
|
self.blogBase["postListJson"][postNum]["commentNum"]=issue.get_comments().totalCount
|
||||||
|
if self.blogBase["i18n"]=="CN":
|
||||||
|
period="。"
|
||||||
|
else:
|
||||||
|
period="."
|
||||||
|
self.blogBase["postListJson"][postNum]["description"]=issue.body.split(period)[0]+period
|
||||||
|
|
||||||
try:
|
try:
|
||||||
modifyTime=json.loads(issue.body.split("\r\n")[-1:][0].split("##")[1])
|
modifyTime=json.loads(issue.body.split("\r\n")[-1:][0].split("##")[1])
|
||||||
@ -130,7 +161,8 @@ class GMEEK():
|
|||||||
for issue in self.blogBase["postListJson"].values():
|
for issue in self.blogBase["postListJson"].values():
|
||||||
self.createPostHtml(issue)
|
self.createPostHtml(issue)
|
||||||
|
|
||||||
self.creatPlistHtml()
|
self.createPlistHtml()
|
||||||
|
self.createFeedXml()
|
||||||
print("====== create static html end ======")
|
print("====== create static html end ======")
|
||||||
|
|
||||||
def runOne(self,number_str):
|
def runOne(self,number_str):
|
||||||
@ -138,7 +170,8 @@ class GMEEK():
|
|||||||
issue=self.repo.get_issue(int(number_str))
|
issue=self.repo.get_issue(int(number_str))
|
||||||
self.addOnePostJson(issue)
|
self.addOnePostJson(issue)
|
||||||
self.createPostHtml(self.blogBase["postListJson"]["P"+number_str])
|
self.createPostHtml(self.blogBase["postListJson"]["P"+number_str])
|
||||||
self.creatPlistHtml()
|
self.createPlistHtml()
|
||||||
|
self.createFeedXml()
|
||||||
print("====== create static html end ======")
|
print("====== create static html end ======")
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|||||||
3
docs/static/icon.js
vendored
3
docs/static/icon.js
vendored
@ -8,5 +8,6 @@ var IconList={
|
|||||||
"moon":"M9.598 1.591a.75.75 0 01.785-.175 7 7 0 11-8.967 8.967.75.75 0 01.961-.96 5.5 5.5 0 007.046-7.046.75.75 0 01.175-.786zm1.616 1.945a7 7 0 01-7.678 7.678 5.5 5.5 0 107.678-7.678z",
|
"moon":"M9.598 1.591a.75.75 0 01.785-.175 7 7 0 11-8.967 8.967.75.75 0 01.961-.96 5.5 5.5 0 007.046-7.046.75.75 0 01.175-.786zm1.616 1.945a7 7 0 01-7.678 7.678 5.5 5.5 0 107.678-7.678z",
|
||||||
"search":"M15.7 13.3l-3.81-3.83A5.93 5.93 0 0 0 13 6c0-3.31-2.69-6-6-6S1 2.69 1 6s2.69 6 6 6c1.3 0 2.48-.41 3.47-1.11l3.83 3.81c.19.2.45.3.7.3.25 0 .52-.09.7-.3a.996.996 0 0 0 0-1.41v.01zM7 10.7c-2.59 0-4.7-2.11-4.7-4.7 0-2.59 2.11-4.7 4.7-4.7 2.59 0 4.7 2.11 4.7 4.7 0 2.59-2.11 4.7-4.7 4.7z",
|
"search":"M15.7 13.3l-3.81-3.83A5.93 5.93 0 0 0 13 6c0-3.31-2.69-6-6-6S1 2.69 1 6s2.69 6 6 6c1.3 0 2.48-.41 3.47-1.11l3.83 3.81c.19.2.45.3.7.3.25 0 .52-.09.7-.3a.996.996 0 0 0 0-1.41v.01zM7 10.7c-2.59 0-4.7-2.11-4.7-4.7 0-2.59 2.11-4.7 4.7-4.7 2.59 0 4.7 2.11 4.7 4.7 0 2.59-2.11 4.7-4.7 4.7z",
|
||||||
"home":"M6.906.664a1.749 1.749 0 0 1 2.187 0l5.25 4.2c.415.332.657.835.657 1.367v7.019A1.75 1.75 0 0 1 13.25 15h-3.5a.75.75 0 0 1-.75-.75V9H7v5.25a.75.75 0 0 1-.75.75h-3.5A1.75 1.75 0 0 1 1 13.25V6.23c0-.531.242-1.034.657-1.366l5.25-4.2Zm1.25 1.171a.25.25 0 0 0-.312 0l-5.25 4.2a.25.25 0 0 0-.094.196v7.019c0 .138.112.25.25.25H5.5V8.25a.75.75 0 0 1 .75-.75h3.5a.75.75 0 0 1 .75.75v5.25h2.75a.25.25 0 0 0 .25-.25V6.23a.25.25 0 0 0-.094-.195Z",
|
"home":"M6.906.664a1.749 1.749 0 0 1 2.187 0l5.25 4.2c.415.332.657.835.657 1.367v7.019A1.75 1.75 0 0 1 13.25 15h-3.5a.75.75 0 0 1-.75-.75V9H7v5.25a.75.75 0 0 1-.75.75h-3.5A1.75 1.75 0 0 1 1 13.25V6.23c0-.531.242-1.034.657-1.366l5.25-4.2Zm1.25 1.171a.25.25 0 0 0-.312 0l-5.25 4.2a.25.25 0 0 0-.094.196v7.019c0 .138.112.25.25.25H5.5V8.25a.75.75 0 0 1 .75-.75h3.5a.75.75 0 0 1 .75.75v5.25h2.75a.25.25 0 0 0 .25-.25V6.23a.25.25 0 0 0-.094-.195Z",
|
||||||
"email":"M1.75 2h12.5c.966 0 1.75.784 1.75 1.75v8.5A1.75 1.75 0 0 1 14.25 14H1.75A1.75 1.75 0 0 1 0 12.25v-8.5C0 2.784.784 2 1.75 2ZM1.5 12.251c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25V5.809L8.38 9.397a.75.75 0 0 1-.76 0L1.5 5.809v6.442Zm13-8.181v-.32a.25.25 0 0 0-.25-.25H1.75a.25.25 0 0 0-.25.25v.32L8 7.88Z"
|
"email":"M1.75 2h12.5c.966 0 1.75.784 1.75 1.75v8.5A1.75 1.75 0 0 1 14.25 14H1.75A1.75 1.75 0 0 1 0 12.25v-8.5C0 2.784.784 2 1.75 2ZM1.5 12.251c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25V5.809L8.38 9.397a.75.75 0 0 1-.76 0L1.5 5.809v6.442Zm13-8.181v-.32a.25.25 0 0 0-.25-.25H1.75a.25.25 0 0 0-.25.25v.32L8 7.88Z",
|
||||||
|
"rss":"M2.002 2.725a.75.75 0 0 1 .797-.699C8.79 2.42 13.58 7.21 13.974 13.201a.75.75 0 0 1-1.497.098 10.502 10.502 0 0 0-9.776-9.776.747.747 0 0 1-.7-.798ZM2.84 7.05h-.002a7.002 7.002 0 0 1 6.113 6.111.75.75 0 0 1-1.49.178 5.503 5.503 0 0 0-4.8-4.8.75.75 0 0 1 .179-1.489ZM2 13a1 1 0 1 1 2 0 1 1 0 0 1-2 0Z"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,6 +58,8 @@ h1 a{margin-left: 4px;margin-top: 16px;}
|
|||||||
|
|
||||||
<button id="buttonAbout" style="display: none;" class="btn btn-invisible circle" onclick="window.location.href='/about.html'"><svg class="octicon" width="16" height="16" ><path fill-rule="evenodd"></path></svg></button>
|
<button id="buttonAbout" style="display: none;" class="btn btn-invisible circle" onclick="window.location.href='/about.html'"><svg class="octicon" width="16" height="16" ><path fill-rule="evenodd"></path></svg></button>
|
||||||
|
|
||||||
|
<button id="buttonRSS" class="btn btn-invisible circle" onclick="window.location.href='/rss.xml'" title="RSS"><svg class="octicon" width="16" height="16" ><path fill-rule="evenodd"></path></svg></button>
|
||||||
|
|
||||||
<div><button id="changeTheme" class="btn btn-invisible circle" onclick="modeSwitch()"><svg class="octicon" width="16" height="16" ><path id="themeSwitch" fill-rule="evenodd"></path></svg></button></div>
|
<div><button id="changeTheme" class="btn btn-invisible circle" onclick="modeSwitch()"><svg class="octicon" width="16" height="16" ><path id="themeSwitch" fill-rule="evenodd"></path></svg></button></div>
|
||||||
|
|
||||||
|
|
||||||
@ -96,6 +98,7 @@ document.getElementById("blogTitle").innerHTML=blogBase["displayTitle"];
|
|||||||
document.getElementById("blogSubTitle").innerHTML=blogBase["subTitle"];
|
document.getElementById("blogSubTitle").innerHTML=blogBase["subTitle"];
|
||||||
document.getElementById("searchSite").setAttribute("value",blogBase["homeUrl"]);
|
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("changeTheme").setAttribute("title",i18n[0]);
|
||||||
document.getElementById("buttonLink").setAttribute("title",i18n[3]);
|
document.getElementById("buttonLink").setAttribute("title",i18n[3]);
|
||||||
document.getElementById("buttonAbout").setAttribute("title",i18n[4]);
|
document.getElementById("buttonAbout").setAttribute("title",i18n[4]);
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
PyGithub
|
PyGithub
|
||||||
requests
|
requests
|
||||||
xpinyin
|
xpinyin
|
||||||
|
feedgen
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user