Created
February 18, 2020 19:07
-
-
Save ericwbailey/2507b3102ae3b6340b750aa591050a39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { DateTime } = require("luxon"); | |
const pluginRss = require("@11ty/eleventy-plugin-rss"); | |
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight"); | |
module.exports = function (eleventyConfig) { | |
eleventyConfig.addPlugin(pluginRss); | |
eleventyConfig.addPlugin(pluginSyntaxHighlight); | |
eleventyConfig.setDataDeepMerge(true); | |
eleventyConfig.addLayoutAlias("post", "layouts/post.njk"); | |
eleventyConfig.addFilter("readableDate", dateObj => { | |
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat("dd LLL yyyy"); | |
}); | |
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string | |
eleventyConfig.addFilter('htmlDateString', (dateObj) => { | |
return DateTime.fromJSDate(dateObj).toFormat('yyyy-LL-dd'); | |
}); | |
// Get the first `n` elements of a collection. | |
eleventyConfig.addFilter("head", (array, n) => { | |
if (n < 0) { | |
return array.slice(n); | |
} | |
return array.slice(0, n); | |
}); | |
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string | |
eleventyConfig.addFilter('htmlDateString', (dateObj) => { | |
return DateTime.fromJSDate(dateObj).toFormat('yyyy-LL-dd'); | |
}); | |
// only content in the `posts/` directory | |
eleventyConfig.addCollection("posts", function (collection) { | |
return collection.getFilteredByGlob("./src/posts/*").sort(function (a, b) { | |
return a.date - b.date; | |
}); | |
}); | |
// Universal slug filter strips unsafe chars from URLs | |
eleventyConfig.addFilter("slugify", function (str) { | |
return slugify(str, { | |
lower: true, | |
replacement: "-", | |
remove: /[*+~.·,()'"`´%!?¿:@]/g | |
}); | |
}); | |
eleventyConfig.addCollection("tagList", require("./src/_11ty/getTagList")); | |
/* Markdown Plugins */ | |
let markdownIt = require("markdown-it"); | |
let markdownItAnchor = require("markdown-it-anchor"); | |
let options = { | |
html: true, | |
breaks: true, | |
linkify: true | |
}; | |
let opts = { | |
permalink: true, | |
permalinkClass: "direct-link", | |
permalinkSymbol: "#" | |
}; | |
eleventyConfig.setLibrary("md", markdownIt(options) | |
.use(markdownItAnchor, opts) | |
); | |
return { | |
templateFormats: [ | |
"md", | |
"njk", | |
"html", | |
"liquid" | |
], | |
// If your site lives in a different subdirectory, change this. | |
// Leading or trailing slashes are all normalized away, so don’t worry about it. | |
// If you don’t have a subdirectory, use "" or "/" (they do the same thing) | |
// This is only used for URLs (it does not affect your file structure) | |
pathPrefix: "/", | |
markdownTemplateEngine: "liquid", | |
htmlTemplateEngine: "njk", | |
dataTemplateEngine: "njk", | |
passthroughFileCopy: true, | |
dir: { | |
input: "./src", | |
includes: "_includes", | |
data: "_data", | |
output: "dist" | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment