I want the home page to use just `title` as the page title, but I want other pages to add the site name to the page title. This filter does that and spits out the final title.
81 lines
2.7 KiB
JavaScript
81 lines
2.7 KiB
JavaScript
const path = require("path");
|
|
const markdownIt = require("markdown-it");
|
|
const slugify = require("@sindresorhus/slugify");
|
|
const markdownItAnchor = require("markdown-it-anchor");
|
|
const markdownItObsidian = require("markdown-it-obsidian");
|
|
const markdownItAttrs = require("markdown-it-attrs");
|
|
const markdownItEleventyImg = require("markdown-it-eleventy-img");
|
|
const pluginRss = require("@11ty/eleventy-plugin-rss");
|
|
const embedYouTube = require("eleventy-plugin-youtube-embed");
|
|
|
|
module.exports = function(eleventyConfig) {
|
|
eleventyConfig.addPlugin(embedYouTube);
|
|
eleventyConfig.addPlugin(pluginRss);
|
|
|
|
eleventyConfig.addPassthroughCopy({ "assets/css": "css" });
|
|
eleventyConfig.addPassthroughCopy({ "assets/fonts": "fonts" });
|
|
eleventyConfig.addPassthroughCopy({ "assets/images/*": "images" });
|
|
eleventyConfig.addPassthroughCopy({ "assets/favicon": "/" });
|
|
eleventyConfig.addPassthroughCopy({
|
|
"node_modules/simpledotcss/simple.css": "css/simple.css",
|
|
});
|
|
|
|
eleventyConfig.addFilter("buildPageTitle", function(title) {
|
|
if (this.page.url === '/') {
|
|
return title;
|
|
} else {
|
|
return title + ' ⇢ Devon.LoL 😆';
|
|
}
|
|
});
|
|
eleventyConfig.addFilter("stringToDate", function(value) {
|
|
return new Date(value);
|
|
});
|
|
eleventyConfig.addFilter("formatDatetimeForHumans", function(value) {
|
|
const dt = new Date(value);
|
|
const formattedDt = new Intl.DateTimeFormat("en", {
|
|
dateStyle: "medium",
|
|
timeStyle: "medium",
|
|
}).format(dt);
|
|
return formattedDt;
|
|
});
|
|
eleventyConfig.addFilter("formatDateForHumans", function(value) {
|
|
const dt = new Date(value);
|
|
const formattedDt = new Intl.DateTimeFormat("en", {
|
|
dateStyle: "medium",
|
|
}).format(dt);
|
|
return formattedDt;
|
|
});
|
|
eleventyConfig.addFilter("convertYouTubeURLsToEmbeds", function(value) {
|
|
const youtubeUrlRegex = /<p>\s*(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?!channel\/|@)([^\s&<>"']*)\s*<\/p>/gim;
|
|
return value.replace(youtubeUrlRegex, function(match, videoId) {
|
|
return '<iframe width="560" height="315" src="https://www.youtube.com/embed/' + videoId + '" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
|
|
});
|
|
});
|
|
|
|
|
|
const markdownLibrary = markdownIt()
|
|
.use(markdownItAnchor, { slugify })
|
|
.use(
|
|
markdownItObsidian({
|
|
slugifyOnPageLinks: slugify,
|
|
})
|
|
)
|
|
.use(markdownItAttrs)
|
|
.use(markdownItEleventyImg, {
|
|
imgOptions: {
|
|
outputDir: path.join("dist", "img"),
|
|
},
|
|
globalAttributes: {
|
|
loading: "lazy",
|
|
decoding: "async",
|
|
},
|
|
});
|
|
eleventyConfig.setLibrary("md", markdownLibrary);
|
|
|
|
return {
|
|
dir: {
|
|
input: "src",
|
|
output: "dist",
|
|
},
|
|
};
|
|
};
|