wonderfulfrog.com/config/collections/index.js
2024-02-06 23:00:04 -08:00

32 lines
675 B
JavaScript

const path = require("path");
const { dir } = require("../constants.js");
const getAllPosts = (collection) => {
const posts = collection.getFilteredByGlob(
path.join(dir.input, "content/posts/**/*.md"),
);
return posts.reverse();
};
const getAllPostCategories = (collection) => {
const posts = getAllPosts(collection);
const allCategories = posts.flatMap((post) => post.data.categories);
const categories = allCategories.reduce((acc, category) => {
if (acc[category]) {
acc[category]++;
} else {
acc[category] = 1;
}
return acc;
}, {});
return categories;
};
module.exports = {
getAllPosts,
getAllPostCategories,
};