The tag plugin I created to display a list of articles for a specific category only shows two items #5194
Replies: 7 comments 6 replies
-
Have you run this through VScode debugger? Reference |
Beta Was this translation helpful? Give feedback.
-
I'm not sure what you want to do, but what about this code? hexo.extend.tag.register('post_list', (args) => {
const categoryNames = Array.from(new Set(args[0].split(',').map((cat) => {
return cat.trim().toUpperCase();
})));
let result = '<ol>';
hexo.locals.get('posts').sort('-date').forEach((post) => {
if (post.categories && post.categories.length > 0) {
const postCategories = post.categories.map((c) => c.name.trim().toUpperCase());
const matchedCategories = postCategories.filter(pc => {
return categoryNames.find(cn => cn === pc);
});
if (matchedCategories.length > 0) {
result += '<li><a href="' + post.permalink + '">' + post.title + '</a></li>';
}
}
});
result += '</ol>';
return result;
}); |
Beta Was this translation helpful? Give feedback.
-
@nagongze Your code actually works fine in my blog. Can you provide your source repository, so I can help debugging? |
Beta Was this translation helpful? Give feedback.
-
I hava same problem, hexo.locals.get('posts') return 2 items rather than all post @nagongze how to solve it ? |
Beta Was this translation helpful? Give feedback.
-
I tried it and it works. test in v6.3 and v7 hexo.extend.tag.register("post_list", function (args) {
var result = "<ol>";
console.log(hexo.locals.get('posts').length);
hexo.locals.get("posts").sort("-date").forEach(function (post) {
console.log(post.title, post.permalink);
result += '<li><a href="' + post.permalink + '">' + post.title + "</a></li>";
});
result += "</ol>";
return result;
}); |
Beta Was this translation helpful? Give feedback.
-
It's so strange, I changed the number of articles containing the tag and the output is different |
Beta Was this translation helpful? Give feedback.
-
Can you output your node environment settings? I'm wondering if you have a poorly configured heap config... |
Beta Was this translation helpful? Give feedback.
-
I don't even know what the reason is. Whether it's the tag syntax or the Front matter, I've copied them, and theoretically, it should have more items, but it just displays two items.
Beta Was this translation helpful? Give feedback.
All reactions