Loading .eleventy.js +51 −10 Original line number Diff line number Diff line Loading @@ -38,14 +38,30 @@ export default async function (eleventyConfig) { }); }); // Custom Eleventy filter to sort a collection by its "kapitel" array eleventyConfig.addFilter("sortByKapitel", collection => { return collection.sort((a, b) => { function compareByKapitel(a, b) { if (a.data.kapitel < b.data.kapitel) return -1; else if (a.data.kapitel > b.data.kapitel) return 1; else return 0; } function sortByKapitel(collection) { return collection.sort(compareByKapitel); } function addSubKapitel(collection) { return collection.map(item => { // Add a derived "subkapitel" string (everything after the first level) // Example: [2, 3] → "3" const kapitel = item.data.kapitel; if (Array.isArray(kapitel)) { item.data["subkapitel"] = kapitel.slice(1).join("."); } return item; }); }); } // Custom Eleventy filter to sort a collection by its "kapitel" array eleventyConfig.addFilter("sortByKapitel", sortByKapitel); // Breadcrumb filter for building navigation trails from a page's URL eleventyConfig.addFilter("breadcrumbs", (page, collections) => { Loading Loading @@ -82,6 +98,31 @@ export default async function (eleventyConfig) { return breadcrumbs; }); // Add a custom Eleventy filter to get direct subpages of a given parent "kapitel" eleventyConfig.addFilter("subpagesOf", (collection, parentKapitel) => { const filtered = collection.filter(item => { const kapitel = item.data.kapitel; // Keep items that: // 1. Have a "kapitel" array // 2. Are exactly one level deeper than the parent // 3. Share the same prefix as the parent (i.e., they are direct children) return ( kapitel && kapitel.length === parentKapitel.length + 1 && parentKapitel.every((val, i) => kapitel[i] === val) ) }).sort(compareByKapitel); return addSubKapitel(filtered); }); // Add subkapitel array eleventyConfig.addFilter("addSubKapitel", collection => { return addSubKapitel(collection); }); // SHORTCODES eleventyConfig.addShortcode("svg", name => { return ` Loading @@ -98,12 +139,12 @@ export default async function (eleventyConfig) { // Paired shortcode "hint": creates a collapsible hint box with a title and content eleventyConfig.addPairedShortcode("hint", (content, title) => { return ` <div class="my-6 rounded-lg border border-gray-300 bg-gray-100 text-gray-800 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100"> <div class="my-6 text-gray-800 bg-gray-100 rounded-lg border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100"> <button type="button" class="flex w-full items-center justify-between px-4 py-2 text-left text-sm font-medium hover:bg-gray-200 dark:hover:bg-gray-700" class="flex justify-between items-center px-4 py-2 w-full text-sm font-medium text-left hover:bg-gray-200 dark:hover:bg-gray-700" onclick="this.nextElementSibling.classList.toggle('hidden'); this.querySelector('svg').classList.toggle('rotate-180')"> <span class="text-gray-800 dark:text-gray-100">${title}</span> <svg class="w-4 h-4 transition-transform duration-300 text-gray-600 dark:text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg class="w-4 h-4 text-gray-600 transition-transform duration-300 dark:text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" /> </svg> </button> Loading src/_includes/partials/_debug.njk +7 −3 Original line number Diff line number Diff line {# DEBUGGING INFO #} <aside class="fixed z-50 max-w-sm p-4 text-sm text-gray-100 shadow-lg bottom-4 right-4 rounded-xl bg-black/90 ring-1 ring-white/10"> class="fixed right-4 bottom-4 z-50 p-4 max-w-sm text-sm text-gray-100 rounded-xl ring-1 shadow-lg bg-black/90 ring-white/10"> <h2 class="mb-2 font-bold text-orange-400">🛠 Debug Info</h2> <ul class="space-y-1"> <li> Loading @@ -23,6 +23,10 @@ <strong>kapitel:</strong> {{ kapitel or "n/a" }} </li> <li> <strong>subkapitel:</strong> {{ subkapitel or "n/a" }} </li> <li> <strong>pageTitleParts:</strong> {{ pageTitleParts or "n/a" }} Loading src/pages/blog.md +4 −4 Original line number Diff line number Diff line Loading @@ -11,10 +11,10 @@ mainSection: blog <div> <h2>Programmierung</h2> <ul> {%- for post in collections.programmierung | filterByTags(["index"]) | sortByKapitel -%} {%- for post in collections.programmierung | subpagesOf([2]) -%} <li> <a href="{{ post.url }}"> {{ post.data.kapitel | join(".") }} - {{ post.data.subkapitel }} - {{ post.data.title }} </a> </li> Loading @@ -25,10 +25,10 @@ mainSection: blog <div> <h2>Datenbanken</h2> <ul> {%- for post in collections.datenbanken | filterByTags(["index"]) | excludeByTags(["subindex"]) | sortByKapitel -%} {%- for post in collections.datenbanken | subpagesOf([3]) -%} <li> <a href="{{ post.url }}"> {{ post.data.kapitel | join(".") }} - {{ post.data.subkapitel }} - {{ post.data.title }} </a> </li> Loading src/pages/datenbanken.md +3 −3 Original line number Diff line number Diff line --- title: Datenbanken kapitel: 3 kapitel: [3] mainSection: datenbanken --- # Alles zum Thema Datenbanken <ul> {%- for post in collections.datenbanken | filterByTags(["index"]) | sortByKapitel -%} {%- for post in collections.datenbanken | subpagesOf(kapitel) -%} <li> <a href="{{ post.url }}"> {{ post.data.kapitel | join(".") }} - {{ post.data.subkapitel }} - {{ post.data.title }} </a> </li> Loading src/pages/programmierung.md +3 −3 Original line number Diff line number Diff line --- title: Programmierung kapitel: 2 kapitel: [2] mainSection: programmierung --- # Alles zum Thema Programmierung <ul> {%- for post in collections.programmierung | filterByTags(["index"]) | sortByKapitel -%} {%- for post in collections.programmierung | subpagesOf(kapitel) -%} <li> <a href="{{ post.url }}"> {{ post.data.kapitel | join(".") }} - {{ post.data.subkapitel }} - {{ post.data.title }} </a> </li> Loading Loading
.eleventy.js +51 −10 Original line number Diff line number Diff line Loading @@ -38,14 +38,30 @@ export default async function (eleventyConfig) { }); }); // Custom Eleventy filter to sort a collection by its "kapitel" array eleventyConfig.addFilter("sortByKapitel", collection => { return collection.sort((a, b) => { function compareByKapitel(a, b) { if (a.data.kapitel < b.data.kapitel) return -1; else if (a.data.kapitel > b.data.kapitel) return 1; else return 0; } function sortByKapitel(collection) { return collection.sort(compareByKapitel); } function addSubKapitel(collection) { return collection.map(item => { // Add a derived "subkapitel" string (everything after the first level) // Example: [2, 3] → "3" const kapitel = item.data.kapitel; if (Array.isArray(kapitel)) { item.data["subkapitel"] = kapitel.slice(1).join("."); } return item; }); }); } // Custom Eleventy filter to sort a collection by its "kapitel" array eleventyConfig.addFilter("sortByKapitel", sortByKapitel); // Breadcrumb filter for building navigation trails from a page's URL eleventyConfig.addFilter("breadcrumbs", (page, collections) => { Loading Loading @@ -82,6 +98,31 @@ export default async function (eleventyConfig) { return breadcrumbs; }); // Add a custom Eleventy filter to get direct subpages of a given parent "kapitel" eleventyConfig.addFilter("subpagesOf", (collection, parentKapitel) => { const filtered = collection.filter(item => { const kapitel = item.data.kapitel; // Keep items that: // 1. Have a "kapitel" array // 2. Are exactly one level deeper than the parent // 3. Share the same prefix as the parent (i.e., they are direct children) return ( kapitel && kapitel.length === parentKapitel.length + 1 && parentKapitel.every((val, i) => kapitel[i] === val) ) }).sort(compareByKapitel); return addSubKapitel(filtered); }); // Add subkapitel array eleventyConfig.addFilter("addSubKapitel", collection => { return addSubKapitel(collection); }); // SHORTCODES eleventyConfig.addShortcode("svg", name => { return ` Loading @@ -98,12 +139,12 @@ export default async function (eleventyConfig) { // Paired shortcode "hint": creates a collapsible hint box with a title and content eleventyConfig.addPairedShortcode("hint", (content, title) => { return ` <div class="my-6 rounded-lg border border-gray-300 bg-gray-100 text-gray-800 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100"> <div class="my-6 text-gray-800 bg-gray-100 rounded-lg border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100"> <button type="button" class="flex w-full items-center justify-between px-4 py-2 text-left text-sm font-medium hover:bg-gray-200 dark:hover:bg-gray-700" class="flex justify-between items-center px-4 py-2 w-full text-sm font-medium text-left hover:bg-gray-200 dark:hover:bg-gray-700" onclick="this.nextElementSibling.classList.toggle('hidden'); this.querySelector('svg').classList.toggle('rotate-180')"> <span class="text-gray-800 dark:text-gray-100">${title}</span> <svg class="w-4 h-4 transition-transform duration-300 text-gray-600 dark:text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg class="w-4 h-4 text-gray-600 transition-transform duration-300 dark:text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" /> </svg> </button> Loading
src/_includes/partials/_debug.njk +7 −3 Original line number Diff line number Diff line {# DEBUGGING INFO #} <aside class="fixed z-50 max-w-sm p-4 text-sm text-gray-100 shadow-lg bottom-4 right-4 rounded-xl bg-black/90 ring-1 ring-white/10"> class="fixed right-4 bottom-4 z-50 p-4 max-w-sm text-sm text-gray-100 rounded-xl ring-1 shadow-lg bg-black/90 ring-white/10"> <h2 class="mb-2 font-bold text-orange-400">🛠 Debug Info</h2> <ul class="space-y-1"> <li> Loading @@ -23,6 +23,10 @@ <strong>kapitel:</strong> {{ kapitel or "n/a" }} </li> <li> <strong>subkapitel:</strong> {{ subkapitel or "n/a" }} </li> <li> <strong>pageTitleParts:</strong> {{ pageTitleParts or "n/a" }} Loading
src/pages/blog.md +4 −4 Original line number Diff line number Diff line Loading @@ -11,10 +11,10 @@ mainSection: blog <div> <h2>Programmierung</h2> <ul> {%- for post in collections.programmierung | filterByTags(["index"]) | sortByKapitel -%} {%- for post in collections.programmierung | subpagesOf([2]) -%} <li> <a href="{{ post.url }}"> {{ post.data.kapitel | join(".") }} - {{ post.data.subkapitel }} - {{ post.data.title }} </a> </li> Loading @@ -25,10 +25,10 @@ mainSection: blog <div> <h2>Datenbanken</h2> <ul> {%- for post in collections.datenbanken | filterByTags(["index"]) | excludeByTags(["subindex"]) | sortByKapitel -%} {%- for post in collections.datenbanken | subpagesOf([3]) -%} <li> <a href="{{ post.url }}"> {{ post.data.kapitel | join(".") }} - {{ post.data.subkapitel }} - {{ post.data.title }} </a> </li> Loading
src/pages/datenbanken.md +3 −3 Original line number Diff line number Diff line --- title: Datenbanken kapitel: 3 kapitel: [3] mainSection: datenbanken --- # Alles zum Thema Datenbanken <ul> {%- for post in collections.datenbanken | filterByTags(["index"]) | sortByKapitel -%} {%- for post in collections.datenbanken | subpagesOf(kapitel) -%} <li> <a href="{{ post.url }}"> {{ post.data.kapitel | join(".") }} - {{ post.data.subkapitel }} - {{ post.data.title }} </a> </li> Loading
src/pages/programmierung.md +3 −3 Original line number Diff line number Diff line --- title: Programmierung kapitel: 2 kapitel: [2] mainSection: programmierung --- # Alles zum Thema Programmierung <ul> {%- for post in collections.programmierung | filterByTags(["index"]) | sortByKapitel -%} {%- for post in collections.programmierung | subpagesOf(kapitel) -%} <li> <a href="{{ post.url }}"> {{ post.data.kapitel | join(".") }} - {{ post.data.subkapitel }} - {{ post.data.title }} </a> </li> Loading