Skip to content

Commit

Permalink
support tags, categories display as a line
Browse files Browse the repository at this point in the history
  • Loading branch information
joinwu committed Jan 8, 2024
1 parent b789344 commit ad08dc3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 20 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ layout: "tags"
```
tags: true
```

如果想让 tags 页展示在一列,可以添加配置
```
style:
tags:
# support line, list; default list
display: line
```
### categories 页
`source` 路径下,与 `_posts` 文件夹平行,建立一个 `categories`

Expand All @@ -169,6 +175,13 @@ layout: "categories"
```
categories: true
```
如果想让 categories 页展示在一列,可以添加配置
```
style:
categories:
# support line, list; default list
display: line
```

## 2 文章树、目录树
页面左侧的文章树是根据 source 文件夹里的文章和文件夹生成的
Expand Down
32 changes: 23 additions & 9 deletions layout/categories.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,29 @@
</h3>

<div id="article-content">
<ul>
<% if (theme.style && theme.style.categories && theme.style.categories.display=="line") { %>
<% if (site.categories && site.categories.length) { %>
<% site.categories.forEach(function(category){ %>
<li class="menu-item">
<span>
<a href="/<%- category.path %>"><%- category.name %>(<%- category.length %>)</a>
</span>
</li>
<% }); %>
<%
var categories = [];
site.categories.forEach(function(category){
categories.push('<a href="' + config.root + category.path + '">' + category.name + '</a>');
});
%>
<div class="categories">
<%- categories.join(', ') %>
</div>
<% } %>
</ul>
<% } else { %>
<ul>
<% if (site.categories && site.categories.length) { %>
<% site.categories.forEach(function(category){ %>
<li class="menu-item">
<span>
<a href="/<%- category.path %>"><%- category.name %>(<%- category.length %>)</a>
</span>
</li>
<% }); %>
<% } %>
</ul>
<% } %>
</div>
33 changes: 23 additions & 10 deletions layout/tags.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,30 @@
<%= __('tags.counts') %> <%- site.tags.length %>
</h3>


<div id="article-content">
<ul>
<% if (theme.style && theme.style.tags && theme.style.tags.display=="line") { %>
<% if (site.tags && site.tags.length) { %>
<% site.tags.forEach(function(tag){ %>
<li class="menu-item">
<span>
<a href="/<%- tag.path %>"><%- tag.name %>(<%- tag.length %>)</a>
</span>
</li>
<% }); %>
<%
var tags = [];
site.tags.forEach(function(tag){
tags.push('<a href="' + config.root + tag.path + '">' + tag.name + '</a>');
});
%>
<div class="tags">
<%- tags.join(', ') %>
</div>
<% } %>
</ul>
<% } else { %>
<ul>
<% if (site.tags && site.tags.length) { %>
<% site.tags.forEach(function(tag){ %>
<li class="menu-item">
<span>
<a href="/<%- tag.path %>"><%- tag.name %>(<%- tag.length %>)</a>
</span>
</li>
<% }); %>
<% } %>
</ul>
<% } %>
</div>

0 comments on commit ad08dc3

Please sign in to comment.