提交 ad16968c 编写于 作者: 折影轻梦

归档页,设置默认显示的分类,其他隐藏

上级 7d9dd799
......@@ -5,6 +5,10 @@ search: https://cn.bing.com/search?q= # https://www.google.com/search?q==
order_by: date # date,-date,title,url,...
head: '<!--<script src="" async></script>-->' # 在 <head></head> 中添加自定义的内容
archives:
switch: false # true,false 来开关本功能
categories: [算法,游戏] # 仅你设置的分类会在归档页面显示
menu:
归档: archives
关于: about.html
......
......@@ -5,21 +5,53 @@
</div>
</div>
<div class="container">
<article class="post">
<article class="post archive">
<%- list_tags({
show_count: true,
style: "unordered list",
separator: ", "
}) %>
<% if(theme.archives.switch) { %>
<p>当前默认显示的分类为:
<% for (index in theme.archives.categories) { %>
<%- theme.archives.categories[index] %>
<% } %>
(<a class="display-btn" onclick="displayAll()">显示所有</a>)
</p>
<% } %>
<% // 参考:https://github.com/SukkaW/hexo-theme-suka/blob/master/layout/_pages/archive.ejs %>
<% function buildArchive(posts, year) { %>
<h2><%= year %></h2>
<ul class="catalogue">
<% posts.sort('date',-1).each(post => { %>
<li><a href="<%- url_for(post.path) %>" >
<span class="title"><%- post.title %></span>
<span class="date"><span><%= date(post.date, 'MM-DD') %></span></span>
</a></li>
<% post.categories.map(function(category){ %>
<%
// 判断是否为已设置需要显示的分类
let displayTF = false;
if(theme.archives.switch) {
for (index in theme.archives.categories) {
if(category.name == theme.archives.categories[index]){
displayTF = true;
}
}
} else {
displayTF = true;
}
%>
<% if(displayTF){ %>
<li class="display"><a href="<%- url_for(post.path) %>" >
<span class="title"><%- post.title %></span>
<span class="date"><span><%= date(post.date, 'MM-DD') %></span></span>
</a></li>
<% } else { %>
<li class="hidden"><a href="<%- url_for(post.path) %>" >
<span class="title"><%- post.title %></span>
<span class="date"><span><%= date(post.date, 'MM-DD') %></span></span>
</a></li>
<% } %>
<% }) %>
<% }) %>
</ul>
<% } %>
......@@ -41,4 +73,8 @@
%>
</article>
</div>
</div>
\ No newline at end of file
</div>
<script>
</script>
\ No newline at end of file
......@@ -22,7 +22,7 @@
<article class="post">
<%- page.content %>
<br>
<%- list_tags(page.tags,{
<%- list_tags(page.tags, {
show_count: true,
style: "unordered list",
separator: ", "
......
......@@ -347,6 +347,18 @@ a:hover {
position: relative;
}
.content .catalogue .hidden {
display: none;
}
.content .catalogue .display {
display: block;
}
.content .archive .display-btn {
cursor: pointer;
}
.content .tag-unordered {
word-break: break-word;
}
......
function search() {
window.open(
document.getElementById("search_form").getAttribute("action_e") + " " + document.getElementById("search_value").value
document.getElementById("search_form").getAttribute("action_e") +
" " +
document.getElementById("search_value").value
);
return false;
}
let display = false;
function displayAll() {
let elements = document.querySelectorAll(".catalogue .hidden");
if (!display) {
for (let elem of elements) {
elem.style.display = "block";
display = true;
}
} else {
for (let elem of elements) {
elem.style.display = "none";
display = false;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册