顶部添加所有Tag标签

This commit is contained in:
Meekdai 2023-11-21 18:17:59 +08:00
parent 95fdccf3b6
commit 93e0487703

View File

@ -56,7 +56,7 @@ h1 a:not([href]){color:inherit;text-decoration:none;vertical-align: bottom;font-
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div style="margin-bottom: 16px;">{{ blogBase['subTitle'] }}</div> <div id="tagLable" style="margin-bottom: 16px;"></div>
<nav class="SideNav border"></nav> <nav class="SideNav border"></nav>
{% endblock %} {% endblock %}
@ -68,6 +68,8 @@ document.getElementById("pathRSS").setAttribute("d",IconList["rss"]);
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]['label'] }}"]);
{%- endfor %} {%- endfor %}
tag=window.location.hash.slice(1);
tagList=[];
let requestJson="blogBase.json" let requestJson="blogBase.json"
let request=new XMLHttpRequest(); let request=new XMLHttpRequest();
request.open("GET",requestJson); request.open("GET",requestJson);
@ -79,12 +81,21 @@ request.onload=function(){
showList(jsonData); showList(jsonData);
} }
tag=window.location.hash.slice(1)
function showList(jsonData){ function showList(jsonData){
let SideNav=document.getElementsByClassName("SideNav")[0]; let SideNav=document.getElementsByClassName("SideNav")[0];
let tagLable=document.getElementById("tagLable");
for(i in jsonData["postListJson"]){ for(i in jsonData["postListJson"]){
if(!(jsonData["postListJson"][i]['label'] in tagList)){
tagList.push(jsonData["postListJson"][i]['label']);
let showLabels=document.createElement("span");
showLabels.setAttribute("class","Label");
showLabels.setAttribute("style","background-color:"+jsonData["postListJson"][i]['labelColor']);
showLabels.innerHTML=jsonData["postListJson"][i]['label'];
showLabels.setAttribute("href",'#'+jsonData["postListJson"][i]['label']);
tagLable.appendChild(showLabels);
}
if(jsonData["postListJson"][i]['label']==tag || tag==''){ if(jsonData["postListJson"][i]['label']==tag || tag==''){
let item=document.createElement("a"); let item=document.createElement("a");
item.setAttribute("class","SideNav-item d-flex flex-items-center flex-justify-between"); item.setAttribute("class","SideNav-item d-flex flex-items-center flex-justify-between");