diff --git a/CONIFG.md b/CONIFG.md
index 8049407..35cff14 100644
--- a/CONIFG.md
+++ b/CONIFG.md
@@ -15,6 +15,7 @@
"email":"meekdai@163.com",
"startSite":"02/16/2015",
"filingNum":"浙ICP备20023628号",
+ "onePageListNum":15,
"singlePage":["link","about"],
"commentLabelColor":"#006b75",
"yearColorList":["#bc4c00", "#0969da", "#1f883d", "#A333D0"],
@@ -74,7 +75,7 @@ jobs:
run: |
cp -r ./* /opt/Gmeek/
cd /opt/Gmeek/
- python Gmeek.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} $(jq -r ".GMEEK_VERSION" config.json) --issue_number '${{ github.event.issue.number }}'
+ python Gmeek.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} --issue_number '${{ github.event.issue.number }}'
cp -a /opt/Gmeek/docs ${{ github.workspace }}
cp -a /opt/Gmeek/backup ${{ github.workspace }}
cp /opt/Gmeek/blogBase.json ${{ github.workspace }}
diff --git a/Gmeek.py b/Gmeek.py
index b7f04a6..479d211 100644
--- a/Gmeek.py
+++ b/Gmeek.py
@@ -12,9 +12,9 @@ from xpinyin import Pinyin
from feedgen.feed import FeedGenerator
from jinja2 import Environment, FileSystemLoader
######################################################################################
-i18n={"Search":"Search","switchTheme":"switch theme","link":"link","home":"home","comments":"comments","run":"run ","days":" days"}
-i18nCN={"Search":"搜索","switchTheme":"切换主题","link":"友情链接","home":"首页","comments":"评论","run":"网站运行","days":"天"}
-IconPlist={
+i18n={"Search":"Search","switchTheme":"switch theme","link":"link","home":"home","comments":"comments","run":"run ","days":" days","Previous":"Previous","Next":"Next"}
+i18nCN={"Search":"搜索","switchTheme":"切换主题","link":"友情链接","home":"首页","comments":"评论","run":"网站运行","days":"天","Previous":"上一页","Next":"下一页"}
+IconList={
"post":"M0 3.75C0 2.784.784 2 1.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.25Zm1.75-.25a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25v-8.5a.25.25 0 0 0-.25-.25ZM3.5 6.25a.75.75 0 0 1 .75-.75h7a.75.75 0 0 1 0 1.5h-7a.75.75 0 0 1-.75-.75Zm.75 2.25h4a.75.75 0 0 1 0 1.5h-4a.75.75 0 0 1 0-1.5Z",
"link":"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z",
"about":"M10.561 8.073a6.005 6.005 0 0 1 3.432 5.142.75.75 0 1 1-1.498.07 4.5 4.5 0 0 0-8.99 0 .75.75 0 0 1-1.498-.07 6.004 6.004 0 0 1 3.431-5.142 3.999 3.999 0 1 1 5.123 0ZM10.5 5a2.5 2.5 0 1 0-5 0 2.5 2.5 0 0 0 5 0Z",
@@ -22,12 +22,8 @@ IconPlist={
"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",
"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",
- "upload":"M2.75 14A1.75 1.75 0 0 1 1 12.25v-2.5a.75.75 0 0 1 1.5 0v2.5c0 .138.112.25.25.25h10.5a.25.25 0 0 0 .25-.25v-2.5a.75.75 0 0 1 1.5 0v2.5A1.75 1.75 0 0 1 13.25 14Z M11.78 4.72a.749.749 0 1 1-1.06 1.06L8.75 3.811V9.5a.75.75 0 0 1-1.5 0V3.811L5.28 5.78a.749.749 0 1 1-1.06-1.06l3.25-3.25a.749.749 0 0 1 1.06 0l3.25 3.25Z"
-}
-IconPost={
+ "upload":"M2.75 14A1.75 1.75 0 0 1 1 12.25v-2.5a.75.75 0 0 1 1.5 0v2.5c0 .138.112.25.25.25h10.5a.25.25 0 0 0 .25-.25v-2.5a.75.75 0 0 1 1.5 0v2.5A1.75 1.75 0 0 1 13.25 14Z M11.78 4.72a.749.749 0 1 1-1.06 1.06L8.75 3.811V9.5a.75.75 0 0 1-1.5 0V3.811L5.28 5.78a.749.749 0 1 1-1.06-1.06l3.25-3.25a.749.749 0 0 1 1.06 0l3.25 3.25Z",
"github":"M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z",
- "sun":"M8 10.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zM8 12a4 4 0 100-8 4 4 0 000 8zM8 0a.75.75 0 01.75.75v1.5a.75.75 0 01-1.5 0V.75A.75.75 0 018 0zm0 13a.75.75 0 01.75.75v1.5a.75.75 0 01-1.5 0v-1.5A.75.75 0 018 13zM2.343 2.343a.75.75 0 011.061 0l1.06 1.061a.75.75 0 01-1.06 1.06l-1.06-1.06a.75.75 0 010-1.06zm9.193 9.193a.75.75 0 011.06 0l1.061 1.06a.75.75 0 01-1.06 1.061l-1.061-1.06a.75.75 0 010-1.061zM16 8a.75.75 0 01-.75.75h-1.5a.75.75 0 010-1.5h1.5A.75.75 0 0116 8zM3 8a.75.75 0 01-.75.75H.75a.75.75 0 010-1.5h1.5A.75.75 0 013 8zm10.657-5.657a.75.75 0 010 1.061l-1.061 1.06a.75.75 0 11-1.06-1.06l1.06-1.06a.75.75 0 011.06 0zm-9.193 9.193a.75.75 0 010 1.06l-1.06 1.061a.75.75 0 11-1.061-1.06l1.06-1.061a.75.75 0 011.061 0z",
- "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",
"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"
}
######################################################################################
@@ -52,9 +48,9 @@ class GMEEK():
config=json.loads(open('config.json', 'r', encoding='utf-8').read())
self.blogBase=config.copy()
- self.blogBase["GMEEK_VERSION"]=options.Gmeek_version
self.blogBase["postListJson"]=json.loads('{}')
-
+ self.blogBase["singeListJson"]=json.loads('{}')
+
if self.blogBase["i18n"]=="CN":
self.i18n=i18nCN
else:
@@ -75,19 +71,24 @@ class GMEEK():
return user.get_repo(repo)
def markdown2html(self,mdstr):
- payload = {"text": mdstr, "mode": "markdown"}
- ret=requests.post("https://api.github.com/markdown", json=payload,headers={"Authorzation":"token {}".format(self.options.github_token)})
- if ret.status_code==200:
- return ret.text
- else:
- raise Exception("markdown2html error status_code=%d"%(ret.status_code))
+ return mdstr
+ # payload = {"text": mdstr, "mode": "markdown"}
+ # ret=requests.post("https://api.github.com/markdown", json=payload,headers={"Authorzation":"token {}".format(self.options.github_token)})
+ # if ret.status_code==200:
+ # return ret.text
+ # else:
+ # raise Exception("markdown2html error status_code=%d"%(ret.status_code))
+
+ def renderHtml(self,template,blogBase,postListJson,htmlDir):
+ file_loader = FileSystemLoader('templates')
+ env = Environment(loader=file_loader)
+ template = env.get_template(template)
+ output = template.render(blogBase=blogBase,postListJson=postListJson,i18n=self.i18n,IconList=IconList)
+ f = open(htmlDir, 'w', encoding='UTF-8')
+ f.write(output)
+ f.close()
def createPostHtml(self,issue):
- if issue["label"] in self.blogBase["singlePage"]:
- gen_Html = 'docs/{}.html'.format(issue["label"])
- else:
- gen_Html = self.post_dir+'{}.html'.format(Pinyin().get_pinyin(issue["postTitle"]))
-
f = open("backup/"+issue["postTitle"]+".md", 'r', encoding='UTF-8')
post_body=self.markdown2html(f.read())
f.close()
@@ -102,27 +103,54 @@ class GMEEK():
postBase["postSourceUrl"]=issue["postSourceUrl"]
postBase["repoName"]=options.repo_name
- file_loader = FileSystemLoader('templates')
- env = Environment(loader=file_loader)
- template = env.get_template('post.html')
- output = template.render(blogBase=postBase,i18n=self.i18n,IconList=IconPost)
-
- f = open(gen_Html, 'w', encoding='UTF-8')
- f.write(output)
- f.close()
- print("create postPage title=%s file=%s " % (issue["postTitle"],gen_Html))
+ self.renderHtml('post.html',postBase,{},issue["htmlDir"])
+ print("create postPage title=%s file=%s " % (issue["postTitle"],issue["htmlDir"]))
def createPlistHtml(self):
self.blogBase["postListJson"]=dict(sorted(self.blogBase["postListJson"].items(),key=lambda x:(x[1]["top"],x[1]["createdAt"]),reverse=True))#使列表由时间排序
- file_loader = FileSystemLoader('templates')
- env = Environment(loader=file_loader)
- template = env.get_template('plist.html')
- output = template.render(blogBase=self.blogBase,postListJson=self.blogBase["postListJson"],i18n=self.i18n,IconList=IconPlist)
- f = open(self.root_dir+"index.html", 'w', encoding='UTF-8')
- f.write(output)
- f.close()
- print("create docs/index.html")
+ postNum=len(self.blogBase["postListJson"])
+ pageFlag=0
+ while True:
+ topNum=pageFlag*self.blogBase["onePageListNum"]
+ print("topNum=%d postNum=%d"%(topNum,postNum))
+ if postNum<=self.blogBase["onePageListNum"]:
+ if pageFlag==0:
+ onePageList=dict(list(self.blogBase["postListJson"].items())[:postNum])
+ htmlDir=self.root_dir+"index.html"
+ self.blogBase["prevUrl"]="disabled"
+ self.blogBase["nextUrl"]="disabled"
+ else:
+ onePageList=dict(list(self.blogBase["postListJson"].items())[topNum:topNum+postNum])
+ htmlDir=self.root_dir+("page%d.html" % (pageFlag+1))
+ if pageFlag==1:
+ self.blogBase["prevUrl"]="/index.html"
+ else:
+ self.blogBase["prevUrl"]="/page%d.html" % pageFlag
+ self.blogBase["nextUrl"]="disabled"
+
+ self.renderHtml('plist.html',self.blogBase,onePageList,htmlDir)
+ print("create "+htmlDir)
+ break
+ else:
+ onePageList=dict(list(self.blogBase["postListJson"].items())[topNum:topNum+self.blogBase["onePageListNum"]])
+ postNum=postNum-self.blogBase["onePageListNum"]
+ if pageFlag==0:
+ htmlDir=self.root_dir+"index.html"
+ self.blogBase["prevUrl"]="disabled"
+ self.blogBase["nextUrl"]="/page2.html"
+ else:
+ htmlDir=self.root_dir+("page%d.html" % (pageFlag+1))
+ if pageFlag==1:
+ self.blogBase["prevUrl"]="/index.html"
+ else:
+ self.blogBase["prevUrl"]="/page%d.html" % pageFlag
+ self.blogBase["nextUrl"]="/page%d.html" % (pageFlag+2)
+
+ self.renderHtml('plist.html',self.blogBase,onePageList,htmlDir)
+ print("create "+htmlDir)
+
+ pageFlag=pageFlag+1
def createFeedXml(self):
self.blogBase["postListJson"]=dict(sorted(self.blogBase["postListJson"].items(),key=lambda x:x[1]["createdAt"],reverse=False))#使列表由时间排序
@@ -137,6 +165,14 @@ class GMEEK():
feed.webMaster(self.blogBase["title"])
feed.ttl("60")
+ for num in self.blogBase["singeListJson"]:
+ item=feed.add_item()
+ item.guid(self.blogBase["homeUrl"]+"/"+self.blogBase["singeListJson"][num]["postUrl"],permalink=True)
+ item.title(self.blogBase["singeListJson"][num]["postTitle"])
+ item.description(self.blogBase["singeListJson"][num]["description"])
+ item.link(href=self.blogBase["homeUrl"]+"/"+self.blogBase["singeListJson"][num]["postUrl"])
+ item.pubDate(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(self.blogBase["singeListJson"][num]["createdAt"])))
+
for num in self.blogBase["postListJson"]:
item=feed.add_item()
item.guid(self.blogBase["homeUrl"]+"/"+self.blogBase["postListJson"][num]["postUrl"],permalink=True)
@@ -149,24 +185,32 @@ class GMEEK():
def addOnePostJson(self,issue):
if len(issue.labels)==1:
+ if issue.labels[0].name in self.blogBase["singlePage"]:
+ listJsonName='singeListJson'
+ gen_Html = 'docs/{}.html'.format(issue.labels[0].name)
+ else:
+ listJsonName='postListJson'
+ gen_Html = self.post_dir+'{}.html'.format(Pinyin().get_pinyin(issue.title))
+
postNum="P"+str(issue.number)
- self.blogBase["postListJson"][postNum]=json.loads('{}')
- self.blogBase["postListJson"][postNum]["label"]=issue.labels[0].name
- self.blogBase["postListJson"][postNum]["labelColor"]=self.labelColorDict[issue.labels[0].name]
- self.blogBase["postListJson"][postNum]["postTitle"]=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]["commentNum"]=issue.get_comments().totalCount
+ self.blogBase[listJsonName][postNum]=json.loads('{}')
+ self.blogBase[listJsonName][postNum]["htmlDir"]=gen_Html
+ self.blogBase[listJsonName][postNum]["label"]=issue.labels[0].name
+ self.blogBase[listJsonName][postNum]["labelColor"]=self.labelColorDict[issue.labels[0].name]
+ self.blogBase[listJsonName][postNum]["postTitle"]=issue.title
+ self.blogBase[listJsonName][postNum]["postUrl"]=urllib.parse.quote(self.post_folder+'{}.html'.format(Pinyin().get_pinyin(issue.title)))
+ self.blogBase[listJsonName][postNum]["postSourceUrl"]="https://github.com/"+options.repo_name+"/issues/"+str(issue.number)
+ self.blogBase[listJsonName][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
+ self.blogBase[listJsonName][postNum]["description"]=issue.body.split(period)[0]+period
- self.blogBase["postListJson"][postNum]["top"]=0
+ self.blogBase[listJsonName][postNum]["top"]=0
for event in issue.get_events():
if event.event=="pinned":
- self.blogBase["postListJson"][postNum]["top"]=1
+ self.blogBase[listJsonName][postNum]["top"]=1
break
elif event.event=="unpinned":
break
@@ -179,22 +223,22 @@ class GMEEK():
postConfig={}
if "timestamp" in postConfig:
- self.blogBase["postListJson"][postNum]["createdAt"]=postConfig["timestamp"]
+ self.blogBase[listJsonName][postNum]["createdAt"]=postConfig["timestamp"]
else:
- self.blogBase["postListJson"][postNum]["createdAt"]=int(time.mktime(issue.created_at.timetuple()))
+ self.blogBase[listJsonName][postNum]["createdAt"]=int(time.mktime(issue.created_at.timetuple()))
if "style" in postConfig:
- self.blogBase["postListJson"][postNum]["style"]=str(postConfig["style"])
+ self.blogBase[listJsonName][postNum]["style"]=str(postConfig["style"])
else:
- self.blogBase["postListJson"][postNum]["style"]=""
+ self.blogBase[listJsonName][postNum]["style"]=""
if "script" in postConfig:
- self.blogBase["postListJson"][postNum]["script"]=str(postConfig["script"])
+ self.blogBase[listJsonName][postNum]["script"]=str(postConfig["script"])
else:
- self.blogBase["postListJson"][postNum]["script"]=""
+ self.blogBase[listJsonName][postNum]["script"]=""
- thisTime=datetime.datetime.fromtimestamp(self.blogBase["postListJson"][postNum]["createdAt"])
+ thisTime=datetime.datetime.fromtimestamp(self.blogBase[listJsonName][postNum]["createdAt"])
thisYear=thisTime.year
- self.blogBase["postListJson"][postNum]["createdDate"]=thisTime.strftime("%Y-%m-%d")
- self.blogBase["postListJson"][postNum]["dateLabelColor"]=self.blogBase["yearColorList"][int(thisYear)%len(self.blogBase["yearColorList"])]
+ self.blogBase[listJsonName][postNum]["createdDate"]=thisTime.strftime("%Y-%m-%d")
+ self.blogBase[listJsonName][postNum]["dateLabelColor"]=self.blogBase["yearColorList"][int(thisYear)%len(self.blogBase["yearColorList"])]
f = open("backup/"+issue.title+".md", 'w', encoding='UTF-8')
f.write(issue.body)
@@ -211,6 +255,9 @@ class GMEEK():
for issue in self.blogBase["postListJson"].values():
self.createPostHtml(issue)
+ for issue in self.blogBase["singeListJson"].values():
+ self.createPostHtml(issue)
+
self.createPlistHtml()
self.createFeedXml()
print("====== create static html end ======")
@@ -228,7 +275,6 @@ class GMEEK():
parser = argparse.ArgumentParser()
parser.add_argument("github_token", help="github_token")
parser.add_argument("repo_name", help="repo_name")
-parser.add_argument("Gmeek_version", help="Gmeek_version")
parser.add_argument("--issue_number", help="issue_number", default=0, required=False)
options = parser.parse_args()
diff --git a/templates/plist.html b/templates/plist.html
index e0fee51..56818c3 100644
--- a/templates/plist.html
+++ b/templates/plist.html
@@ -45,14 +45,12 @@ h1 a:not([href]){color:inherit;text-decoration:none;vertical-align: bottom;font-
- {% for num in postListJson -%}
- {% if postListJson[num]['label'] in blogBase['singlePage'] -%}
-