Personal-Site/eleventy.config.js

89 lines
2.7 KiB
JavaScript
Raw Normal View History

2023-07-06 23:24:56 +00:00
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const eleventySyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
2023-07-06 23:24:56 +00:00
const eleventySass = require("eleventy-sass");
2023-07-13 21:31:21 +00:00
const eleventyRss = require("@11ty/eleventy-plugin-rss");
const eleventyDrafts = require("./eleventy.config.drafts");
2023-07-06 23:24:56 +00:00
const mdDefList = require("markdown-it-deflist");
2023-07-12 21:46:34 +00:00
const mdToc = require("markdown-it-table-of-contents");
const mdAnchor = require("markdown-it-anchor");
2023-10-27 21:59:22 +00:00
const { markdownItImageSize } = require("./markdown-it-image-size");
2023-07-13 18:10:39 +00:00
const nunjucksDate = require("nunjucks-date");
2023-10-20 16:48:24 +00:00
const markdownIt = require("markdown-it");
2023-07-06 23:24:56 +00:00
2023-07-13 21:31:21 +00:00
function addEleventyPlugins(eleventyConfig) {
2023-07-06 23:24:56 +00:00
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(eleventySyntaxHighlight);
2023-07-10 21:22:04 +00:00
eleventyConfig.addPlugin(eleventyRss);
eleventyConfig.addPlugin(eleventyDrafts);
2023-07-06 23:24:56 +00:00
eleventyConfig.addPlugin(eleventySass, {
sass: {
loadPaths: ["node_modules"],
},
});
2023-07-13 21:31:21 +00:00
}
function configureMarkdown(eleventyConfig) {
2023-10-27 21:59:22 +00:00
console.log("markdownItImageSize", markdownItImageSize);
2023-07-12 21:46:34 +00:00
eleventyConfig.amendLibrary("md", mdLib => mdLib
.use(mdDefList)
2023-07-12 22:28:16 +00:00
.use(mdToc, {
includeLevel: [ 1, 2, 3, 4, 5, 6 ]
})
2023-10-27 21:59:22 +00:00
.use(mdAnchor)
.use(markdownItImageSize));
2023-07-13 21:31:21 +00:00
}
2023-07-06 23:24:56 +00:00
2023-07-13 21:31:21 +00:00
function addFilters(eleventyConfig) {
2023-10-20 16:48:24 +00:00
let md = new markdownIt();
eleventyConfig.addFilter("renderMarkdown", (mdString) => md.render(mdString));
2023-07-13 21:31:21 +00:00
eleventyConfig.addFilter("log", (value) => console.log(value));
2023-07-13 18:10:39 +00:00
eleventyConfig.addFilter("date", nunjucksDate);
2023-07-06 23:24:56 +00:00
eleventyConfig.addFilter("IsNotPage", (collection, url) =>
collection.filter(item => item.url != url));
eleventyConfig.addFilter("IsMainPageSection", (collection) => {
return collection.filter(item => !item.url || item.url.startsWith("/_sections"));
});
eleventyConfig.addFilter("IsNotMainPageSection", (collection) => {
2023-07-07 23:42:16 +00:00
return collection.filter(item => {
if (item.url == null || item.url == false)
return false;
if (item.data.tags == null)
return true;
if (item.data.tags.includes("MainPage"))
return false;
return true;
});
2023-07-06 23:24:56 +00:00
});
2023-07-13 21:31:21 +00:00
}
module.exports = function (eleventyConfig) {
eleventyConfig.setBrowserSyncConfig({
files: "./_site/css/**/*.css",
});
2023-10-20 17:37:09 +00:00
eleventyConfig.addPassthroughCopy("src/img");
2023-07-13 21:31:21 +00:00
eleventyConfig.addPassthroughCopy({
"node_modules/prism-themes/themes/prism-material-light.min.css":
"css/prism-material-light.min.css",
"node_modules/prism-themes/themes/prism-material-oceanic.min.css":
"css/prism-material-oceanic.min.css",
"node_modules/feather-icons/dist/feather-sprite.svg": "images/feather-sprite.svg",
"src/js/site.js": "js/site.js"
});
addEleventyPlugins(eleventyConfig);
configureMarkdown(eleventyConfig);
addFilters(eleventyConfig);
2023-07-06 23:24:56 +00:00
return {
dir: {
input: "src",
},
};
};