前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Hexo 基于分类输出文章

Hexo 基于分类输出文章

作者头像
折影轻梦
发布2021-08-11 10:36:22
5660
发布2021-08-11 10:36:22
举报
文章被收录于专栏:折影轻梦

Hexo 基于分类输出文章

2021年04月15日 409 字 大概 1 分钟

本文将教你如何调用 Hexo 指定分类下的文章

本文回答了以下问题

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

https://segmentfault.com/q/1010000017758828

前言

官方的辅助函数 list_categories 根本不够用,只好自己用 categories 这个变量了。

由于没学过 node.js 所以只有瞎折腾一通。

我先用 console.log() 看了看 site.categories.data,它的内容是如下。

折腾一番,这个 object 是用 map() 来调用的。

输出目录标题

代码语言:javascript
复制
<% site.categories.map(function(category){  %>
    <h1><%= category.name %></h1>
<% }) %>

输出文章标题

代码语言:javascript
复制
<% site.categories.map(function(category){  %>
    <h1><%= category.name %></h1>
    <% category.posts.map(function(post){  %>
    <h2><%= post.title %></h2>
    <% }) %>
<% }) %>

变量

描述

类型

post.title

页面标题

string

post.date

页面建立日期

Moment.js 对象

post.updated

页面更新日期

Moment.js 对象

post.comments

留言是否开启

boolean

post.layout

布局名称

string

post.content

页面的完整内容

string

post.excerpt

页面摘要

string

post.more

除了页面摘要的其余内容

string

post.source

页面原始路径

string

post.full_source

页面的完整原始路径

string

post.path

页面网址(不含根路径)。我们通常在主题中使用 url_for(post.path)。

string

post.permalink

页面的完整网址

string

post.prev

上一个页面。如果此为第一个页面则为 null。

string or null

post.next

下一个页面。如果此为最后一个页面则为 null。

string or null

post.raw

文章的原始内容

???

post.photos

文章的照片(用于相簿)

array

post.link

文章的外部链接(用于链接文章)

string

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021年04月15日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Hexo 基于分类输出文章
    • 本文回答了以下问题
      • 前言
        • 输出目录标题
          • 输出文章标题
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档