72 lines
2.7 KiB
JavaScript
72 lines
2.7 KiB
JavaScript
const handlebarsPlugin = require("@11ty/eleventy-plugin-handlebars");
|
|
const handlebars = require('handlebars');
|
|
const sass = require("sass");
|
|
const pluginRss = require("@11ty/eleventy-plugin-rss");
|
|
require('dotenv').config();
|
|
|
|
module.exports = function(eleventyConfig) {
|
|
// Passthrough episodes directory to include both markdown and audio files
|
|
eleventyConfig.addPassthroughCopy("content/episodes/*/*.mp3");
|
|
eleventyConfig.addPassthroughCopy("content/images/*.jpg");
|
|
eleventyConfig.addPlugin(handlebarsPlugin);
|
|
eleventyConfig.addPlugin(pluginRss);
|
|
|
|
// handlebars helpers
|
|
handlebars.registerHelper("formatSeasonEpisode", function(season, episode) {
|
|
// Convert strings to integers and pad with zeros
|
|
const seasonNumber = parseInt(season, 10).toString().padStart(2, '0');
|
|
const episodeNumber = parseInt(episode, 10).toString().padStart(2, '0');
|
|
|
|
// Return the formatted string
|
|
return `<span class="season">S${seasonNumber}</span><span class="episode">E${episodeNumber}</span>`;
|
|
// return `S${seasonNumber}E${episodeNumber}`;
|
|
});
|
|
|
|
eleventyConfig.addFilter("seasonEpisodeFormat", function (season, episode, separator="") {
|
|
const seasonNumber = parseInt(season, 10).toString().padStart(2, '0');
|
|
const episodeNumber = parseInt(episode, 10).toString().padStart(2, '0');
|
|
return [seasonNumber, episodeNumber].join(separator)
|
|
return value;
|
|
});
|
|
|
|
handlebars.registerHelper('ifEquals', function(arg1, arg2, options) {
|
|
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
|
|
});
|
|
|
|
handlebars.registerHelper('ifIncludes', function(set, candidate, options) {
|
|
return (set.includes(candidate)) ? options.fn(this) : options.inverse(this);
|
|
});
|
|
|
|
// Creates the extension for use
|
|
eleventyConfig.addTemplateFormats("scss");
|
|
eleventyConfig.addExtension("scss", {
|
|
outputFileExtension: "css", // optional, default: "html"
|
|
|
|
// `compile` is called once per .scss file in the input directory
|
|
compile: async function (inputContent) {
|
|
let result = sass.compileString(inputContent);
|
|
|
|
// This is the render function, `data` is the full data cascade
|
|
return async (data) => {
|
|
return result.css;
|
|
};
|
|
},
|
|
});
|
|
|
|
eleventyConfig.addNunjucksFilter("podcastUrl", function(post) {
|
|
// Convert the season and episode to zero-padded numbers
|
|
const seasonNumber = parseInt(post.data.season, 10).toString().padStart(2, '0');
|
|
const episodeNumber = parseInt(post.data.episode, 10).toString().padStart(2, '0');
|
|
|
|
// Construct the podcast URL
|
|
return `/episodes/s${seasonNumber}/s${seasonNumber}e${episodeNumber}.mp3`;
|
|
});
|
|
|
|
return {
|
|
dir: {
|
|
data: "data",
|
|
input: "content",
|
|
includes: "../layouts"
|
|
}
|
|
};
|
|
}; |