Acrylic 主题自定义五:新增文章隐藏功能
有时候,文章文件已经创建好了,但内容还没完成,上传时就会出现内容出错的问题,文章隐藏就是不错的解决方案
注意:个人参考文章效果,可以通过 abbrlink 进入
文章参数
在文章参数中添加 hide 属性
hide: true
时隐藏,默认不隐藏
1 2 3 4
| --- title: Acrylic主题自定义五:新增文章隐藏功能 hide: true ---
|
修改代码
首页
代码文件位置:themes/Acrylic/layout/index.ejs
1 2 3
| <% for (const item of page.posts.sort('-date').data){ %> <%- partial('partial/component/home/postList', {post: item}) %> <% } %>
|
替换成 👇 下面代码
1 2 3 4 5
| <% for (const item of page.posts.sort('-date').data){ %> <% if(!item.hide){ %> <%- partial('partial/component/home/postList', {post: item}) %> <% } %> <% } %>
|
最近文章
代码文件位置:themes/Acrylic/layout/partial/component/aside/asideNewestPost.ejs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <div class="aside-list-item"> <a class="thumbnail" href="<%= url_for(post.path) %>" title="<%= post.title %>"> <img alt="<%= post.title %>" src="<%= post.cover %>"> </a> <div class="content"> <% post.categories.data.forEach(categories=> { %> <a class="article-recent_post_categories" href="<%= url_for(post.path) %>"> <%= categories.name %> </a> <% }) %> <a class="title" href="<%= url_for(post.path) %>" title="<%= post.title %>"> <%= post.title %> </a> </div> </div> <% index++;if(index> 5)break; %>
|
替换成 👇 下面代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <% if(!post.hide){ %> <div class="aside-list-item"> <a class="thumbnail" href="<%= url_for(post.path) %>" title="<%= post.title %>"> <img alt="<%= post.title %>" src="<%= post.cover %>"> </a> <div class="content"> <% post.categories.data.forEach(categories=> { %> <a class="article-recent_post_categories" href="<%= url_for(post.path) %>"> <%= categories.name %> </a> <% }) %> <a class="title" href="<%= url_for(post.path) %>" title="<%= post.title %>"> <%= post.title %> </a> </div> </div> <% index++;if(index> 5)break; %> <% } %>
|
标签/分类/档案
代码文件位置:themes/Acrylic/layout/partial/component/mixins/articleSort.ejs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <div class="article-sort-item"> <a class="article-sort-item-img" href="<%= url_for(post.path) %>" title="<%= post.title %>"> <img src="<%= post.cover %>" alt="<%= post.title %>"> </a> <div class="article-sort-item-info"> <a class="article-sort-item-title" href="<%= url_for(post.path) %>" title="<%= post.title %>" onclick="window.event.cancelBubble=true;"> <%= post.title %> </a> <div class="article-sort-item-tags"> <% post.tags.data.forEach(tags=> { %> <a class="article-meta__tags" href="<%= url_for(tags.path) %>" onclick="window.event.cancelBubble=true;"> <span class="tags-punctuation">#</span> <%= tags.name %> </a> <% }) %> </div> </div> </div>
|
替换成 👇 下面代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <% if(!post.hide){ %> <div class="article-sort-item"> <a class="article-sort-item-img" href="<%= url_for(post.path) %>" title="<%= post.title %>"> <img src="<%= post.cover %>" alt="<%= post.title %>"> </a> <div class="article-sort-item-info"> <a class="article-sort-item-title" href="<%= url_for(post.path) %>" title="<%= post.title %>" onclick="window.event.cancelBubble=true;"> <%= post.title %> </a> <div class="article-sort-item-tags"> <% post.tags.data.forEach(tags=> { %> <a class="article-meta__tags" href="<%= url_for(tags.path) %>" onclick="window.event.cancelBubble=true;"> <span class="tags-punctuation">#</span> <%= tags.name %> </a> <% }) %> </div> </div> </div> <% } %>
|
404
代码文件位置:themes/Acrylic/layout/404.ejs
1 2 3 4 5 6 7 8 9 10
| <div class="aside-list-item"> <a class="thumbnail" href="<%= url_for(post.path) %>" title="<%= post.title %>"> <img src="<%= post.cover %>" alt="<%= post.title %>"> </a> <div class="content"> <a class="title" href="<%= url_for(post.path) %>" title="<%= post.title %>"> <%= post.title %> </a> </div> </div>
|
替换成 👇 下面代码
1 2 3 4 5 6 7 8 9 10 11 12
| <% if(!post.hide){ %> <div class="aside-list-item"> <a class="thumbnail" href="<%= url_for(post.path) %>" title="<%= post.title %>"> <img src="<%= post.cover %>" alt="<%= post.title %>"> </a> <div class="content"> <a class="title" href="<%= url_for(post.path) %>" title="<%= post.title %>"> <%= post.title %> </a> </div> </div> <% } %>
|
随机文章
代码文件位置:themes/Acrylic/scripts/filter/randomPosts.js
1 2 3
| hexo.locals.get("posts").map(function (post) { if (post.random !== false) posts.push(post.path); });
|
替换成 👇 下面代码
1 2 3
| hexo.locals.get("posts").map(function (post) { if (post.random !== false && !post.hide) posts.push(post.path); });
|