Reorganise configurations for blog post categories
This commit is contained in:
+2
-2
@@ -10,7 +10,7 @@ import { VentoPlugin } from 'eleventy-plugin-vento';
|
||||
import markdownItConfig from "./src/_config/markdown-it.js";
|
||||
import feedsConfig from "./src/_config/feeds.js";
|
||||
import filesConfig from "./src/_config/files.js";
|
||||
import collectionsConfig from "./src/_config/collections.js";
|
||||
import categoriesConfig from "./src/_config/categories.js";
|
||||
import filtersConfig from "./src/_config/filters.js";
|
||||
import shortCodesConfig from "./src/_config/shortcodes.js";
|
||||
|
||||
@@ -34,7 +34,7 @@ export default function(eleventyConfig) {
|
||||
eleventyConfig.addPlugin(markdownItConfig);
|
||||
eleventyConfig.addPlugin(feedsConfig);
|
||||
eleventyConfig.addPlugin(filesConfig);
|
||||
eleventyConfig.addPlugin(collectionsConfig);
|
||||
eleventyConfig.addPlugin(categoriesConfig);
|
||||
eleventyConfig.addPlugin(filtersConfig);
|
||||
eleventyConfig.addPlugin(shortCodesConfig);
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
export default function(eleventyConfig) {
|
||||
// Add blog post categories to collections
|
||||
eleventyConfig.addCollection("categories", (collectionApi) => {
|
||||
let categories = new Set();
|
||||
let posts = collectionApi.getFilteredByTag('posts');
|
||||
posts.forEach(p => {
|
||||
let cats = p.data.categories;
|
||||
if (cats) {
|
||||
cats.forEach(c => categories.add(c));
|
||||
}
|
||||
});
|
||||
return Array.from(categories).sort();
|
||||
});
|
||||
|
||||
// Filter: Filter blog posts by category
|
||||
eleventyConfig.addFilter("filterByCategory", (posts, cat) => {
|
||||
cat = cat.toLowerCase();
|
||||
let result = posts.filter(p => {
|
||||
let cats = p.data.categories.map(s => s.toLowerCase());
|
||||
if (cats) {
|
||||
return cats.includes(cat);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
});
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
export default function(eleventyConfig) {
|
||||
// Add blog post categories to collections
|
||||
eleventyConfig.addCollection("categories", (collectionApi) => {
|
||||
let categories = new Set();
|
||||
let posts = collectionApi.getFilteredByTag('posts');
|
||||
posts.forEach(p => {
|
||||
let cats = p.data.categories;
|
||||
cats.forEach(c => categories.add(c));
|
||||
});
|
||||
return Array.from(categories).sort();
|
||||
});
|
||||
}
|
||||
@@ -22,14 +22,4 @@ export default function(eleventyConfig) {
|
||||
eleventyConfig.addFilter("thousands", (num) => {
|
||||
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
});
|
||||
|
||||
// Filter: Filter blog posts by category
|
||||
eleventyConfig.addFilter("filterByCategory", (posts, cat) => {
|
||||
cat = cat.toLowerCase();
|
||||
let result = posts.filter(p => {
|
||||
let cats = p.data.categories.map(s => s.toLowerCase());
|
||||
return cats.includes(cat);
|
||||
});
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user