hypnagaga_old/config/collections/index.js
2024-01-30 18:33:58 +01:00

28 lines
738 B
JavaScript

/** All blog posts as a collection. */
const getAllPosts = collection => {
const projects = collection.getFilteredByGlob('./src/posts/*.md');
return projects.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
};