diff --git a/eleventy.config.js b/eleventy.config.js
index c5d9c5b7..156c8d7d 100644
--- a/eleventy.config.js
+++ b/eleventy.config.js
@@ -1,83 +1,43 @@
// Installed Plugins
import pluginRss from "@11ty/eleventy-plugin-rss";
import eleventyNavigationPlugin from "@11ty/eleventy-navigation";
+import embedEverything from "eleventy-plugin-embed-everything";
import metagen from 'eleventy-plugin-metagen';
import emojiReadTime from "@11tyrocks/eleventy-plugin-emoji-readtime";
+import pluginTOC from '@uncenter/eleventy-plugin-toc';
-import slugify from "slugify";
-
-import markdownPlugin from "./eleventy.config.md.js";
+// Custom Configurations
+import markdownItConfig from "./src/_config/markdown-it.js";
+import copyConfig from "./src/_config/copy.js";
+import collectionsConfig from "./src/_config/collections.js";
+import filterConfig from "./src/_config/filter.js";
+import shortCodesConfig from "./src/_config/shortcodes.js";
export default function(eleventyConfig) {
- // Copy files
- eleventyConfig.addPassthroughCopy("./src/assets/");
- eleventyConfig.addWatchTarget("./src/assets/");
- eleventyConfig.addWatchTarget("./src/_bundle/");
- eleventyConfig.addPassthroughCopy({
- "node_modules/@zachleat/details-utils/details-utils.js": "assets/js/details-utils.js",
- });
-
- // Custom Plugins
- eleventyConfig.addPlugin(markdownPlugin);
-
// Installed Plugins
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(eleventyNavigationPlugin);
+ eleventyConfig.addPlugin(embedEverything, { add: ['soundcloud'] });
eleventyConfig.addPlugin(metagen);
eleventyConfig.addPlugin(emojiReadTime);
+ eleventyConfig.addPlugin(pluginTOC, {
+ tags: ['h2', 'h3', 'h4', 'h5', 'h6'],
+ wrapper: function (toc) {
+ return ``;
+ },
+ });
+
+ // Custom Configurations
+ eleventyConfig.addPlugin(markdownItConfig);
+ eleventyConfig.addPlugin(copyConfig);
+ eleventyConfig.addPlugin(collectionsConfig);
+ eleventyConfig.addPlugin(filterConfig);
+ eleventyConfig.addPlugin(shortCodesConfig);
// Eleventy bundle plugin
eleventyConfig.addBundle("css");
eleventyConfig.addBundle("js", { toFileDirectory: "assets/js" });
- // Add content categories to a collection
- eleventyConfig.addCollection("categories", function(collectionApi) {
- let categories = new Set();
- let contents = collectionApi.getFilteredByTag('contents');
- contents.forEach(p => {
- let cats = p.data.categories;
- cats.forEach(c => categories.add(c));
- });
- return Array.from(categories).sort();
- });
-
- // Filter contents by category
- eleventyConfig.addFilter("filterByCategory", function(contents, cat) {
- cat = cat.toLowerCase();
- let result = contents.filter(item => {
- let cats = item.data.categories.map(c => c.toLowerCase());
- return cats.includes(cat);
- });
- return result;
- });
-
- // Filter: Format dates
- const dateOptions = {
- year: 'numeric',
- month: 'long',
- day: 'numeric',
- };
- const dateTimeLocale = new Intl.DateTimeFormat("en-GB", dateOptions);
- eleventyConfig.addFilter("formatDate", function(date) {
- return dateTimeLocale.format(date);
- });
-
- // Filter: Limit number of items displayed
- eleventyConfig.addFilter("itemLimit", function(array, itemLimit) {
- return array.slice(0, itemLimit);
- });
-
- // Shortcode: tag
- eleventyConfig.addShortcode('cite', (str) => `${str}`);
-
- // Paired shortcode: Manual heading anchor
- eleventyConfig.addPairedShortcode('headingAnchor', (title, hLevel, id=slugify(title)) => {
- return ``;
- });
-
return {
dir: {
input: "src"
diff --git a/src/_config/collections.js b/src/_config/collections.js
new file mode 100644
index 00000000..502fbf5a
--- /dev/null
+++ b/src/_config/collections.js
@@ -0,0 +1,12 @@
+export default function(eleventyConfig) {
+ // Add content categories to a collection
+ eleventyConfig.addCollection("categories", function(collectionApi) {
+ let categories = new Set();
+ let contents = collectionApi.getFilteredByTag('contents');
+ contents.forEach(p => {
+ let cats = p.data.categories;
+ cats.forEach(c => categories.add(c));
+ });
+ return Array.from(categories).sort();
+ });
+}
\ No newline at end of file
diff --git a/src/_config/copy.js b/src/_config/copy.js
new file mode 100644
index 00000000..6fe387fd
--- /dev/null
+++ b/src/_config/copy.js
@@ -0,0 +1,9 @@
+// Passthrough File Copy
+export default function(eleventyConfig) {
+ eleventyConfig.addPassthroughCopy("./src/assets/");
+ eleventyConfig.addWatchTarget("./src/assets/");
+ eleventyConfig.addWatchTarget("./src/_bundle/");
+ eleventyConfig.addPassthroughCopy({
+ "node_modules/@zachleat/details-utils/details-utils.js": "assets/js/details-utils.js",
+ });
+}
\ No newline at end of file
diff --git a/src/_config/filter.js b/src/_config/filter.js
new file mode 100644
index 00000000..b0258515
--- /dev/null
+++ b/src/_config/filter.js
@@ -0,0 +1,27 @@
+export default function(eleventyConfig) {
+ // Filter contents by category
+ eleventyConfig.addFilter("filterByCategory", function(contents, cat) {
+ cat = cat.toLowerCase();
+ let result = contents.filter(item => {
+ let cats = item.data.categories.map(c => c.toLowerCase());
+ return cats.includes(cat);
+ });
+ return result;
+ });
+
+ // Format dates
+ const dateOptions = {
+ year: 'numeric',
+ month: 'long',
+ day: 'numeric',
+ };
+ const dateTimeLocale = new Intl.DateTimeFormat("en-GB", dateOptions);
+ eleventyConfig.addFilter("formatDate", function(date) {
+ return dateTimeLocale.format(date);
+ });
+
+ // Limit number of items displayed
+ eleventyConfig.addFilter("itemLimit", function(array, itemLimit) {
+ return array.slice(0, itemLimit);
+ });
+}
\ No newline at end of file
diff --git a/eleventy.config.md.js b/src/_config/markdown-it.js
similarity index 61%
rename from eleventy.config.md.js
rename to src/_config/markdown-it.js
index 9685338d..ef1a2baa 100644
--- a/eleventy.config.md.js
+++ b/src/_config/markdown-it.js
@@ -1,12 +1,3 @@
-/* CONFIGURATION FOR MARKDOWN TEMPLATES */
-
-// Installed Plugins
-import pluginTOC from '@uncenter/eleventy-plugin-toc';
-import embedEverything from "eleventy-plugin-embed-everything";
-
-// Configure slug filter
-import slugify from "slugify";
-
// markdown-it plugins
import markdownIt from "markdown-it";
import markdownItAnchor from "markdown-it-anchor";
@@ -16,16 +7,13 @@ import markdownItBracketedSpans from 'markdown-it-bracketed-spans';
import markdownItDefList from "markdown-it-deflist";
import markdownItFootnote from "markdown-it-footnote";
-export default function(eleventyConfig) {
- // Installed Plugins
- eleventyConfig.addPlugin(pluginTOC, {
- tags: ['h2', 'h3', 'h4', 'h5', 'h6'],
- wrapper: function (toc) {
- return ``;
- },
- });
- eleventyConfig.addPlugin(embedEverything, { add: ['soundcloud'] });
+// Configure slug filter
+import slugify from "slugify";
+// Enable exporting markdown-it library to another module
+export let markdownLibrary;
+
+export default function(eleventyConfig) {
// Configure slug filter
eleventyConfig.addFilter("slug", (str) => {
if (!str) {
@@ -74,7 +62,7 @@ export default function(eleventyConfig) {
};
/* Markdown Overrides */
- let markdownLibrary = markdownIt({
+ markdownLibrary = markdownIt({
html: true,
linkify: true,
})
@@ -118,42 +106,6 @@ export default function(eleventyConfig) {
}
});
- // Paired shortcode: custom container
- eleventyConfig.addPairedShortcode('container', (children, el, className) => {
- const classMarkup = className ? ` class="${className}"` : "";
- const content = markdownLibrary.render(children);
- return `<${el}${classMarkup}>${content}${el}>`;
- });
-
- // Paired shortcode: image figure and figcaption
- eleventyConfig.addPairedShortcode('imgFigure', (caption, img, alt=caption, enableLazyLoading=true) => {
- const figcaption = markdownLibrary.renderInline(caption);
- return `
-
- ${figcaption}
- `;
- });
-
- // Paired shorcode: Content accordion
- eleventyConfig.addPairedShortcode('accordion', (content, summary) => {
- const summaryMarkup = markdownLibrary.renderInline(summary);
- const contentMarkup = markdownLibrary.render(content);
- return `
- ${summaryMarkup}
- ${contentMarkup}
- `;
- });
-
- // Paired shorcode: Content warning accordion
- eleventyConfig.addPairedShortcode('contentWarning', (content, warning) => {
- const warningMarkup = markdownLibrary.renderInline(warning);
- const contentMarkup = markdownLibrary.render(content);
- return `
- ⚠️ Content Warning: ${warningMarkup}
- ${contentMarkup}
- `;
- });
-
/* This is the part that tells 11ty to swap to our custom config */
eleventyConfig.setLibrary("md", markdownLibrary);
-}
+}
\ No newline at end of file
diff --git a/src/_config/shortcodes.js b/src/_config/shortcodes.js
new file mode 100644
index 00000000..50076927
--- /dev/null
+++ b/src/_config/shortcodes.js
@@ -0,0 +1,51 @@
+import slugify from "slugify";
+import { markdownLibrary } from "./markdown-it.js";
+
+export default function(eleventyConfig) {
+ // tag
+ eleventyConfig.addShortcode('cite', (str) => `${str}`);
+
+ // Manual heading anchor
+ eleventyConfig.addPairedShortcode('headingAnchor', (title, hLevel, id=slugify(title)) => {
+ return ``;
+ });
+
+ // Paired shortcode: custom container
+ eleventyConfig.addPairedShortcode('container', (children, el, className) => {
+ const classMarkup = className ? ` class="${className}"` : "";
+ const content = markdownLibrary.render(children);
+ return `<${el}${classMarkup}>${content}${el}>`;
+ });
+
+ // Paired shortcode: image figure and figcaption
+ eleventyConfig.addPairedShortcode('imgFigure', (caption, img, alt=caption, enableLazyLoading=true) => {
+ const figcaption = markdownLibrary.renderInline(caption);
+ return `
+
+ ${figcaption}
+ `;
+ });
+
+ // Paired shorcode: Content accordion
+ eleventyConfig.addPairedShortcode('accordion', (content, summary) => {
+ const summaryMarkup = markdownLibrary.renderInline(summary);
+ const contentMarkup = markdownLibrary.render(content);
+ return `
+ ${summaryMarkup}
+ ${contentMarkup}
+ `;
+ });
+
+ // Paired shorcode: Content warning accordion
+ eleventyConfig.addPairedShortcode('contentWarning', (content, warning) => {
+ const warningMarkup = markdownLibrary.renderInline(warning);
+ const contentMarkup = markdownLibrary.render(content);
+ return `
+ ⚠️ Content Warning: ${warningMarkup}
+ ${contentMarkup}
+ `;
+ });
+}
\ No newline at end of file