Nexmoe

Nexmoe

一个开发者。关于勇敢与热爱,互联网/创造/赛博朋克
twitter
github

Hexo is a platform that allows for the categorization and output of articles.

This article will teach you how to call articles under a specified category in Hexo.

This article answers the following questions#

https://www.zhihu.com/question/404351568

https://segmentfault.com/q/1010000017758828

Introduction#

The official helper function list_categories is not sufficient, so I had to use the variable "categories" myself.

Since I haven't learned node.js, I had to experiment blindly.

First, I used console.log() to see the content of site.categories.data, which is as follows.

image

After some experimentation, I found that this object is called using map().

Output category titles#

<% site.categories.map(function(category){  %>
    <h1><%= category.name %></h1>
<% }) %>

Output article titles#

<% site.categories.map(function(category){  %>
    <h1><%= category.name %></h1>
    <% category.posts.map(function(post){  %>
		<h2><%= post.title %></h2>
    <% }) %>
<% }) %>
VariableDescriptionType
post.titlePage titlestring
post.datePage creation dateMoment.js object
post.updatedPage update dateMoment.js object
post.commentsWhether comments are enabledboolean
post.layoutLayout namestring
post.contentFull content of the pagestring
post.excerptPage excerptstring
post.moreRest of the content except for the excerptstring
post.sourceOriginal path of the pagestring
post.full_sourceFull original path of the pagestring
post.pathPage URL (without the root path). We usually use url_for(post.path) in themes.string
post.permalinkFull URL of the pagestring
post.prevPrevious page. If this is the first page, it is null.string or null
post.nextNext page. If this is the last page, it is null.string or null
post.rawRaw content of the article???
post.photosPhotos in the article (for albums)array
post.linkExternal link of the article (for linked articles)string
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.