添加多label支持

This commit is contained in:
Meekdai 2024-04-02 17:41:34 +08:00
parent 38c90b9ab6
commit 11ce33e617
3 changed files with 32 additions and 22 deletions

View File

@ -77,6 +77,7 @@ class GMEEK():
self.blogBase={**dconfig,**config}.copy()
self.blogBase["postListJson"]=json.loads('{}')
self.blogBase["singeListJson"]=json.loads('{}')
self.blogBase["labelColorDict"]=self.labelColorDict
if "displayTitle" not in self.blogBase:
self.blogBase["displayTitle"]=self.blogBase["title"]
@ -148,7 +149,7 @@ class GMEEK():
else:
postBase["highlight"]=0
if issue["label"] in self.blogBase["singlePage"]:
if issue["labels"][0] in self.blogBase["singlePage"]:
postBase["bottomText"]=''
keys=['sun','moon','sync','home','github']
@ -223,10 +224,10 @@ class GMEEK():
for num in self.blogBase["singeListJson"]:
item=feed.add_item()
item.guid(self.blogBase["homeUrl"]+"/"+self.blogBase["singeListJson"][num]["label"]+".html",permalink=True)
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]["label"]+".html")
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"]:
@ -258,7 +259,7 @@ class GMEEK():
feed.rss_file(self.root_dir+'rss.xml')
def addOnePostJson(self,issue):
if len(issue.labels)==1:
if len(issue.labels)>=1:
if issue.labels[0].name in self.blogBase["singlePage"]:
listJsonName='singeListJson'
htmlFile='{}.html'.format(self.createFileName(issue,useLabel=True))
@ -271,8 +272,8 @@ class GMEEK():
postNum="P"+str(issue.number)
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]["labels"]=[label.name for label in issue.labels]
# 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(gen_Html[len(self.root_dir):])
@ -431,6 +432,8 @@ for i in blog.blogBase["postListJson"]:
wordCount=wordCount+blog.blogBase["postListJson"][i]["wordCount"]
del blog.blogBase["postListJson"][i]["wordCount"]
blog.blogBase["postListJson"]["labelColorDict"]=blog.labelColorDict
docListFile=open(blog.root_dir+"postList.json","w")
docListFile.write(json.dumps(blog.blogBase["postListJson"]))
docListFile.close()

View File

@ -47,7 +47,7 @@
</svg>
</button></a>
{% for num in blogBase['singeListJson'] -%}
<a href="{{ blogBase['homeUrl'] }}/{{ blogBase['singeListJson'][num]['label'] }}.html"><button class="btn btn-invisible circle" title="{{ blogBase['singeListJson'][num]['postTitle'] }}">
<a href="{{ blogBase['homeUrl'] }}/{{ blogBase['singeListJson'][num]['labels'][0] }}.html"><button class="btn btn-invisible circle" title="{{ blogBase['singeListJson'][num]['postTitle'] }}">
<svg class="octicon" width="16" height="16" >
<path id="{{ blogBase['singeListJson'][num]['postTitle'] }}" fill-rule="evenodd"></path>
</svg>
@ -78,7 +78,9 @@
</div>
<div class="listLabels">
{% if postListJson[num]['commentNum']>0 %}<span class="Label" style="background-color:{{ blogBase['commentLabelColor'] }}">{{ postListJson[num]['commentNum'] }}</span>{% endif %}
<span class="Label LabelName" style="background-color:{{ postListJson[num]['labelColor'] }}"><object><a style="color:#fff" href="{{ blogBase['homeUrl'] }}/tag.html#{{ postListJson[num]['label'] }}">{{ postListJson[num]['label'] }}</a></object></span>
{% for label in postListJson[num]['labels'] -%}
<span class="Label LabelName" style="background-color:{{ blogBase['labelColorDict'][label] }}"><object><a style="color:#fff" href="tag.html#{{ label }}">{{ label }}</a></object></span>
{%- endfor %}
<span class="Label LabelTime" style="background-color:{{ postListJson[num]['dateLabelColor'] }}">{{ postListJson[num]['createdDate'] }}</span>
</div>
</a>
@ -119,7 +121,7 @@ for(var i=0;i<iconPost.length;i++){
}
{% for num in blogBase['singeListJson'] -%}
document.getElementById("{{ blogBase['singeListJson'][num]['postTitle'] }}").setAttribute("d",value=IconList["{{ blogBase['singeListJson'][num]['label'] }}"]);
document.getElementById("{{ blogBase['singeListJson'][num]['postTitle'] }}").setAttribute("d",value=IconList["{{ blogBase['singeListJson'][num]['labels'][0] }}"]);
{%- endfor %}
</script>
{% endblock %}

View File

@ -91,14 +91,16 @@ function showList(){
tagLable.appendChild(showLabels);
}
for(i in jsonData){
if(!(tagList.includes(jsonData[i]['label']))){
tagList.push(jsonData[i]['label']);
let showLabels=document.createElement("button");
showLabels.setAttribute("class","Label");
showLabels.setAttribute("style","background-color:"+jsonData[i]['labelColor']);
showLabels.innerHTML=jsonData[i]['label'];
showLabels.setAttribute("onclick","javascript:updateShowTag('"+jsonData[i]['label']+"');");
tagLable.appendChild(showLabels);
for(label in jsonData[i]['labels']){
if(!(tagList.includes(label))){
tagList.push(label);
let showLabels=document.createElement("button");
showLabels.setAttribute("class","Label");
showLabels.setAttribute("style","background-color:"+jsonData['labelColorDict'][label]);
showLabels.innerHTML=label;
showLabels.setAttribute("onclick","javascript:updateShowTag('"+label+"');");
tagLable.appendChild(showLabels);
}
}
let div=document.createElement("div");
@ -126,11 +128,14 @@ function showList(){
let listLabels=document.createElement("div");
listLabels.setAttribute("class","listLabels");
let LabelName=document.createElement("span");
LabelName.setAttribute("class","Label LabelName");
LabelName.setAttribute("style","background-color:"+jsonData[i]['labelColor']);
LabelName.innerHTML=jsonData[i]['label'];
listLabels.appendChild(LabelName);
for(label in jsonData[i]['labels']){
let LabelName=document.createElement("span");
LabelName.setAttribute("class","Label LabelName");
LabelName.setAttribute("style","background-color:"+jsonData['labelColorDict'][label]);
LabelName.innerHTML=label;
listLabels.appendChild(LabelName);
}
let LabelTime=document.createElement("span");
LabelTime.setAttribute("class","Label LabelTime");
LabelTime.setAttribute("style","background-color:"+jsonData[i]['dateLabelColor']);