hypnagaga_old/config/collections/index.js
2024-02-13 11:55:14 +01:00

28 lines
735 B
JavaScript

/** All blog posts as a collection. */
const getAllPosts = collection => {
const posts = collection.getFilteredByGlob('./src/posts/**/*.md');
return posts.reverse();
};
/** All markdown files as a collection for sitemap.xml */
const onlyMarkdown = collection => {
return collection.getFilteredByGlob('./src/**/*.md');
};
/** All tags from all posts as a collection. */
const tagList = collection => {
const tagsSet = new Set();
collection.getAll().forEach(item => {
if (!item.data.tags) return;
item.data.tags
.filter(tag => !['posts', 'all'].includes(tag))
.forEach(tag => tagsSet.add(tag));
});
return Array.from(tagsSet).sort();
};
module.exports = {
getAllPosts,
onlyMarkdown,
tagList
};