|
|
发表于 2022-11-26 21:10:44
|
显示全部楼层
前言
官方的辅助函数 list_categories 根本不够用,只好自己用 categories 这个变量了。
由于没学过 node.js 所以只有瞎折腾一通。
我先用 console.log() 看了看 site.categories.data,它的内容是如下。
折腾一番,这个 object 是用 map() 来调用的。
输出目录标题
<% site.categories.map(function(category){ %> <h1><%= category.name %></h1><% }) %>
输出文章标题
<% site.categories.map(function(category){ %> <h1><%= category.name %></h1> <% category.posts.map(function(post){ %> <h2><%= post.title %></h2> <% }) %><% }) %>
原文链接: |
|