57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
|
import markdownIt from "markdown-it";
|
||
|
import markdownItAnchor from "markdown-it-anchor";
|
||
|
import { formatISO9075 } from "date-fns";
|
||
|
import { format } from "date-fns";
|
||
|
|
||
|
export default async function(eleventyConfig) {
|
||
|
// Options for the `markdown-it` library
|
||
|
const markdownItOptions = {
|
||
|
html: true,
|
||
|
}
|
||
|
|
||
|
// Options for the `markdown-it-anchor` library
|
||
|
const markdownItAnchorOptions = {
|
||
|
permalink: true, permalinkBefore: true, permalinkSymbol: '#'
|
||
|
}
|
||
|
|
||
|
const markdownLib = markdownIt(markdownItOptions).use(
|
||
|
markdownItAnchor,
|
||
|
markdownItAnchorOptions
|
||
|
);
|
||
|
eleventyConfig.addFilter("firstUrlSegment", function(permalink) {
|
||
|
if (typeof permalink === "string") {
|
||
|
permalink = permalink.replace(/^\/+|\/+$/g, '');
|
||
|
const segments = permalink.split('/');
|
||
|
return segments.length > 0 ? segments[0] : '';
|
||
|
}
|
||
|
return '';
|
||
|
});
|
||
|
eleventyConfig.addFilter("ISO", (dateObj) => {
|
||
|
return formatISO9075(dateObj);
|
||
|
});
|
||
|
eleventyConfig.addFilter("humanReadable", (dateObj) => {
|
||
|
return format(dateObj, ("LLLL d, yyyy"));
|
||
|
});
|
||
|
eleventyConfig.setLibrary("md", markdownLib);
|
||
|
|
||
|
// Set directories to pass through to the _site folder
|
||
|
eleventyConfig.addPassthroughCopy("./_src/assets/");
|
||
|
|
||
|
// Watch scss folder for changes
|
||
|
eleventyConfig.addWatchTarget("./_src/assets/");
|
||
|
|
||
|
// Open a browser window on --watch
|
||
|
eleventyConfig.setBrowserSyncConfig({
|
||
|
open: true,
|
||
|
});
|
||
|
};
|
||
|
|
||
|
// This named export is optional
|
||
|
export const config = {
|
||
|
dir: {
|
||
|
input: "_src",
|
||
|
output: "_site"
|
||
|
}
|
||
|
};
|
||
|
|