2024-11-27
This commit is contained in:
94
.eleventy.js
94
.eleventy.js
@@ -3,10 +3,11 @@ const handlebars = require('handlebars');
|
||||
const sass = require("sass");
|
||||
const pluginRss = require("@11ty/eleventy-plugin-rss");
|
||||
const handlebarsHelpers = require('handlebars-helpers')
|
||||
const markdownit = require('markdown-it')
|
||||
const md = markdownit()
|
||||
|
||||
|
||||
const htmlmin = require("html-minifier");
|
||||
const { DateTime } = require("luxon");
|
||||
|
||||
const utilsPlugin = require("./utils/plugin");
|
||||
require('dotenv').config();
|
||||
|
||||
module.exports = function(eleventyConfig) {
|
||||
@@ -15,96 +16,17 @@ module.exports = function(eleventyConfig) {
|
||||
eleventyConfig.addPassthroughCopy("content/episodes/**/*.jpg");
|
||||
eleventyConfig.addPassthroughCopy("content/episodes/**/*.webp");
|
||||
eleventyConfig.addPassthroughCopy("content/episodes/**/*.png");
|
||||
eleventyConfig.addPassthroughCopy("content/images/*.jpg");
|
||||
eleventyConfig.addPassthroughCopy("content/images/*.webp");
|
||||
eleventyConfig.addPassthroughCopy("content/images");
|
||||
eleventyConfig.addPassthroughCopy("content/feeds/*.jpg");
|
||||
eleventyConfig.addPlugin(utilsPlugin, {immediate: true});
|
||||
eleventyConfig.addPlugin(handlebarsPlugin);
|
||||
eleventyConfig.addPlugin(pluginRss);
|
||||
|
||||
|
||||
|
||||
handlebarsHelpers({
|
||||
handlebars
|
||||
})
|
||||
|
||||
eleventyConfig.addFilter(
|
||||
"seasonEpisodeFormat",
|
||||
require("./filters/utils").seasonEpisodeFormat
|
||||
);
|
||||
|
||||
eleventyConfig.addFilter("formatDate", (date, format = "MMMM d, yyyy") => {
|
||||
return DateTime.fromJSDate(new Date(date)).toFormat(format);
|
||||
});
|
||||
|
||||
|
||||
eleventyConfig.addFilter("episodeNumber", function (s, episode) {
|
||||
return episode ? Number(episode) : Number(s.replace(/[^0-9]/,''))
|
||||
});
|
||||
eleventyConfig.addFilter("episodesInSeason", function (season) {
|
||||
return this.eleventy.collection.episode.filter(ep=>ep.season == season)
|
||||
return episode ? Number(episode) : Number(s.replace(/[^0-9]/,''))
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter("extractUniqueTags", function (object, tagPrefix = "") {
|
||||
// Flatten all pages into a single array of items
|
||||
let allItems
|
||||
if (object.pages) {allItems = object.pages.flat()} else { object }
|
||||
|
||||
// Extract the desired property from each item
|
||||
const extractedValues = allItems
|
||||
.map(item => item.data.tags)
|
||||
.flat(); // Flatten arrays if the property contains arrays, like tags
|
||||
|
||||
// Filter for unique values with the "campaign" prefix
|
||||
const uniqueValues = [...new Set(extractedValues)]
|
||||
.filter(tag => tag.startsWith(tagPrefix));
|
||||
|
||||
return uniqueValues;
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter("findPageByTag", function (tag, collections) {
|
||||
// Split the tag to get the collection name and slug
|
||||
const [collectionName, slug] = tag.split(":");
|
||||
|
||||
if (!collectionName || !slug) {
|
||||
console.error(`Invalid tag format: "${tag}". Expected format "collection:slug".`);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Ensure the collection exists
|
||||
const collection = collections[collectionName];
|
||||
if (!collection) {
|
||||
console.error(`Collection "${collectionName}" not found in collections.`);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Search for the page in the inferred collection
|
||||
// TO-DO: this logic will break once we get into season 10, since season 1 will match 1 and 10
|
||||
const matchingPage = collection.find(item => item.fileSlug.includes(slug));
|
||||
|
||||
// Return the matching page (or null if not found)
|
||||
return matchingPage || null;
|
||||
});
|
||||
|
||||
// Shortcodes
|
||||
eleventyConfig.addPairedShortcode(
|
||||
"prologue",
|
||||
function(content) { return `<h1>Prologue</h1><hr><section class="prologue">${md.render(content)}</section>` }
|
||||
);
|
||||
eleventyConfig.addPairedShortcode(
|
||||
"masthead",
|
||||
function(content) {
|
||||
return `<hgroup class="masthead" markdown="1">${md.render(content)}<time datetime="${this.page.date.toISOString()}">${this.page.date.toLocaleDateString()}</time></hgroup>` }
|
||||
);
|
||||
eleventyConfig.addPairedShortcode(
|
||||
"headline",
|
||||
function(content) {
|
||||
return `
|
||||
<hgroup class="headline">${md.render(content.trim())}</hgroup>` }
|
||||
);
|
||||
eleventyConfig.addPairedShortcode(
|
||||
"alternateTitles",
|
||||
function(content) { return `<section class="alternate-titles"><h1>Alternate Titles</h1><hr>${md.render(content)}</section>` }
|
||||
);
|
||||
|
||||
eleventyConfig.addTransform("htmlmin", (content, outputPath) => {
|
||||
if (outputPath.endsWith(".html")) {
|
||||
return htmlmin.minify(content, {
|
||||
|
||||
Reference in New Issue
Block a user