gpt4 book ai didi

javascript - 如何使用hexo按类别获取帖子?

转载 作者:行者123 更新时间:2023-12-03 02:50:12 24 4
gpt4 key购买 nike

摆弄 Hexo 博客..我有一个类别页面,列出了每个类别中的所有帖子。但我想要一个类别独有的单独页面。我不熟悉这里的语法。如何过滤名为“特色”的类别?

<div class="archives-wrap" style="margin: 0px;">
<div class="archives-category-wrap">
<blockquote>
<% if(site.categories.length) { %>
<%- list_categories(site.categories) %>
<% } %>
</blockquote>
</div>

<% site.categories.sort('name').map(function(category){ %>
<div class="archives-wrap">
<div class="archive-year-wrap" id="<%= category.name %>">
<h1 class="archive-category"><%= category.name %></h1>
</div>
<div class="archives">
<% category.posts.sort('-date').map(function(post, i){ %>
<%- partial('_partial/archive-post', {post: post, index: true}) %>
<% if (post.subtitle && post.subtitle.length) { %>
<h3 class="post-subtitle">
<%- post.subtitle %>
</h3>
<% } %>
<% }) %>
</div>
</div>
<% }) %>

最佳答案

我也不熟悉 Hexo,但我认为一个简单的 IF 语句就可以完成这项工作:

<div class="archives-wrap" style="margin: 0px;">
<div class="archives-category-wrap">
<blockquote>
<% if(site.categories.length) { %>
<%- list_categories(site.categories) %>
<% } %>
</blockquote>
</div>

<% site.categories.sort('name').map(function(category){ %>
<% if(category.name == 'featured') { %>
<div class="archives-wrap">
<div class="archive-year-wrap" id="<%= category.name %>">
<h1 class="archive-category"><%= category.name %></h1>
</div>
<div class="archives">
<% category.posts.sort('-date').map(function(post, i){ %>
<%- partial('_partial/archive-post', {post: post, index: true}) %>
<% if (post.subtitle && post.subtitle.length) { %>
<h3 class="post-subtitle">
<%- post.subtitle %>
</h3>
<% } %>
<% }) %>
</div>
</div>
<% } %>
<% }) %>

更复杂的解决方案可能是在 map 之前使用过滤功能,但我在他们的文档中没有找到这样的功能。

关于javascript - 如何使用hexo按类别获取帖子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47902383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com