feat: clean up collections
This commit is contained in:
parent
322c6709aa
commit
db109dd216
2 changed files with 4 additions and 35 deletions
|
@ -1,20 +1,3 @@
|
||||||
import dayjs from "dayjs";
|
|
||||||
|
|
||||||
export const postsByTag = (collection) => {
|
|
||||||
const posts = collection.getFilteredByTag("post");
|
|
||||||
|
|
||||||
const postsByTag = {};
|
|
||||||
|
|
||||||
for (const post of posts) {
|
|
||||||
for (const tag of post.data.tags) {
|
|
||||||
postsByTag[tag] ??= [];
|
|
||||||
postsByTag[tag].push(post);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return postsByTag;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const collectionByTag = (collection, collectionName) => {
|
export const collectionByTag = (collection, collectionName) => {
|
||||||
const items = collection.getFilteredByTag(collectionName);
|
const items = collection.getFilteredByTag(collectionName);
|
||||||
|
|
||||||
|
@ -29,19 +12,3 @@ export const collectionByTag = (collection, collectionName) => {
|
||||||
|
|
||||||
return itemsByTag;
|
return itemsByTag;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const catalogueByType = (collection) => {
|
|
||||||
const allItems = collection.getFilteredByTag("catalogue");
|
|
||||||
|
|
||||||
const catalogueByType = {};
|
|
||||||
|
|
||||||
for (const item of allItems) {
|
|
||||||
const type = item.data.tags[1];
|
|
||||||
if (!type) continue;
|
|
||||||
|
|
||||||
catalogueByType[type] ??= [];
|
|
||||||
catalogueByType[type].push(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return catalogueByType;
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import pluginNoRobots from "eleventy-plugin-no-robots";
|
import pluginNoRobots from "eleventy-plugin-no-robots";
|
||||||
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
|
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
|
||||||
|
|
||||||
import { collectionByTag, postsByTag } from "./config/collections/index.js";
|
import { collectionByTag } from "./config/collections/index.js";
|
||||||
|
|
||||||
import filters from "./config/filters/index.js";
|
import filters from "./config/filters/index.js";
|
||||||
import markdown from "./config/plugins/markdown.js";
|
import markdown from "./config/plugins/markdown.js";
|
||||||
|
@ -17,7 +17,9 @@ export default function (eleventyConfig) {
|
||||||
eleventyConfig.addPlugin(pluginNoRobots);
|
eleventyConfig.addPlugin(pluginNoRobots);
|
||||||
|
|
||||||
// --------------------- Custom Collections -----------------------
|
// --------------------- Custom Collections -----------------------
|
||||||
eleventyConfig.addCollection("postsByTag", postsByTag);
|
eleventyConfig.addCollection("postsByTag", (collection) =>
|
||||||
|
collectionByTag(collection, "post"),
|
||||||
|
);
|
||||||
eleventyConfig.addCollection("booksByTag", (collection) =>
|
eleventyConfig.addCollection("booksByTag", (collection) =>
|
||||||
collectionByTag(collection, "book"),
|
collectionByTag(collection, "book"),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue