Gmeek/templates/tag.html
2023-11-22 11:14:45 +08:00

175 lines
6.6 KiB
HTML

{% extends 'base.html' %}
{% block head %}
<title>{{ blogBase['title'] }} - Tag</title>
{% endblock %}
{% block style %}
<style>
.tagTitle{margin: auto 0;font-size:40px;font-weight:bold;font-family:Monaco;}
.title-right{display:flex;margin:auto 0 0 auto;}
.title-right .circle{padding: 14px 16px;margin-right:8px;}
.SideNav-icon{margin-right: 16px}
.Label{color: #fff;margin-left:8px;}
.genTime{float: right;}
.d-flex{min-width:0;}
.listTitle{overflow:hidden;white-space:nowrap;text-overflow: ellipsis;max-width: 100%;}
.listLabels{white-space:nowrap;}
@media (max-width: 767px) {
body { padding: 8px;}
.tagTitle{font-size:24px;}
.LabelTime{display:none;}
}
</style>
{% endblock %}
{% block header %}
<span class="tagTitle">Tag</span>
<div class="title-right">
<a href="/"><button id="buttonHome" class="btn btn-invisible circle" title="{{ i18n['home'] }}">
<svg class="octicon" width="16" height="16">
<path id="pathHome" fill-rule="evenodd" d="{{ IconList['home'] }}"></path>
</svg>
</button></a>
{% for num in blogBase['singeListJson'] -%}
<a href="/{{ blogBase['singeListJson'][num]['label'] }}.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>
</button></a>
{%- endfor %}
<a href="/rss.xml" target="_blank"><button id="buttonRSS" class="btn btn-invisible circle" title="RSS">
<svg class="octicon" width="16" height="16" >
<path id="pathRSS" fill-rule="evenodd"></path>
</svg>
</button></a>
<button class="btn btn-invisible circle" onclick="modeSwitch()" title="{{ i18n['switchTheme'] }}">
<svg class="octicon" width="16" height="16" >
<path id="themeSwitch" fill-rule="evenodd"></path>
</svg>
</button>
</div>
{% endblock %}
{% block content %}
<div id="tagLable" style="margin-bottom: 16px;"></div>
<nav class="SideNav border"></nav>
{% endblock %}
{% block script %}
<script>
document.getElementById("pathRSS").setAttribute("d",IconList["rss"]);
{% for num in blogBase['singeListJson'] -%}
document.getElementById("{{ blogBase['singeListJson'][num]['postTitle'] }}").setAttribute("d",value=IconList["{{ blogBase['singeListJson'][num]['label'] }}"]);
{%- endfor %}
tagList=[];
jsonData='';
let requestJson="blogBase.json"
let request=new XMLHttpRequest();
request.open("GET",requestJson);
request.responseType='text';
request.send();
request.onload=function(){
jsonData=JSON.parse(request.response);
console.log(jsonData);
showList();
setClassDisplay(decodeURI(window.location.hash.slice(1)));
}
function showList(){
let SideNav=document.getElementsByClassName("SideNav")[0];
let tagLable=document.getElementById("tagLable");
if(tagList.length==0){
let showLabels=document.createElement("button");
showLabels.setAttribute("class","Label");
showLabels.setAttribute("style","background-color:#000");
showLabels.innerHTML="All";
showLabels.setAttribute("onclick","javascript:updateShowTag('All');");
tagLable.appendChild(showLabels);
}
for(i in jsonData["postListJson"]){
if(!(tagList.includes(jsonData["postListJson"][i]['label']))){
tagList.push(jsonData["postListJson"][i]['label']);
let showLabels=document.createElement("button");
showLabels.setAttribute("class","Label");
showLabels.setAttribute("style","background-color:"+jsonData["postListJson"][i]['labelColor']);
showLabels.innerHTML=jsonData["postListJson"][i]['label'];
showLabels.setAttribute("onclick","javascript:updateShowTag('"+jsonData["postListJson"][i]['label']+"');");
tagLable.appendChild(showLabels);
}
let div=document.createElement("div");
div.setAttribute("class","lists "+jsonData["postListJson"][i]['label']);
let item=document.createElement("a");
item.setAttribute("class","SideNav-item d-flex flex-items-center flex-justify-between");
item.setAttribute("href",jsonData["postListJson"][i]['postUrl']);
let center=document.createElement("div");
center.setAttribute("class","d-flex flex-items-center");
svg=document.createElementNS('http://www.w3.org/2000/svg','svg');
path=document.createElementNS("http://www.w3.org/2000/svg","path");
span=document.createElement("span");
svg.setAttributeNS(null,"class","SideNav-icon octicon");
svg.setAttributeNS(null,"style","witdh:16px;height:16px");
path.setAttributeNS(null, "d", IconList["post"]);
svg.appendChild(path);
let title=document.createElement("span");
title.setAttribute("class","listTitle");
title.innerHTML=jsonData["postListJson"][i]['postTitle'];
center.appendChild(svg);
center.appendChild(title);
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["postListJson"][i]['labelColor']);
LabelName.innerHTML=jsonData["postListJson"][i]['label'];
listLabels.appendChild(LabelName);
let LabelTime=document.createElement("span");
LabelTime.setAttribute("class","Label LabelTime");
LabelTime.setAttribute("style","background-color:"+jsonData["postListJson"][i]['dateLabelColor']);
LabelTime.innerHTML=jsonData["postListJson"][i]['createdDate'];
listLabels.appendChild(LabelTime);
item.appendChild(center);
item.appendChild(listLabels);
div.appendChild(item);
SideNav.appendChild(div);
}
}
function updateShowTag(label){
if(window.location.hash.slice(1)!=encodeURI(label)){
window.location.hash="#"+(label);
setClassDisplay(label);
}
}
function setClassDisplay(lable) {
let lists = document.getElementsByClassName("lists");
let tagTitle = document.getElementsByClassName("tagTitle")[0];
tagTitle.innerHTML="Tag #"+lable;
if(lable=="All"){for(let i = 0; i < lists.length; i++){lists[i].style.display='block';}}
else{
for(let i = 0; i < lists.length; i++){
lists[i].style.display='none';
}
let lables = document.getElementsByClassName(lable);
for(let i = 0; i < lables.length; i++){
lables[i].style.display='block';
}
}
}
</script>
{% endblock %}