Move all src JS into external plugins installed through NPM:

@11ty/eleventy-plugin-rss
@11ty/eleventy-plugin-syntaxhighlight
This commit is contained in:
Zach Leatherman
2018-01-28 21:27:41 -06:00
parent c4b6550f4e
commit ac5c7edb44
11 changed files with 14 additions and 235 deletions

View File

@@ -1,50 +1,17 @@
const { DateTime } = require("luxon");
const metadata = require("./_data/metadata.json");
const absoluteUrl = require("./_src/AbsoluteUrl");
const HtmlToAbsoluteUrls = require("./_src/HtmlToAbsoluteUrls");
const syntaxHighlighter = require("./_src/eleventy-liquidjs-tag-highlight-prismjs");
function dateToISO(dateObj) {
return DateTime.fromJSDate(dateObj).toISO({ includeOffset: true, suppressMilliseconds: true });
}
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.addLayoutAlias("post", "layouts/post.njk");
eleventyConfig.addFilter("rssLastUpdatedDate", collection => {
if( !collection.length ) {
throw new Error( "Collection is empty in lastUpdatedDate filter." );
}
// Newest date in the collection
return dateToISO(collection[ collection.length - 1 ].date);
});
eleventyConfig.addFilter("rssDate", dateObj => {
return dateToISO(dateObj);
});
eleventyConfig.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(dateObj).toFormat("dd LLL yyyy");
});
eleventyConfig.addNunjucksFilter("absoluteUrl", function(href, base) {
return absoluteUrl(href, base);
});
eleventyConfig.addNunjucksFilter("htmlToAbsoluteUrls", function(htmlContent, base, callback) {
if(!htmlContent) {
callback(null, "");
return;
}
HtmlToAbsoluteUrls(htmlContent, base).then(result => {
callback(null, result.html);
});
}, true);
// compatibility with existing {% highlight js %} and others
eleventyConfig.addLiquidTag("highlight", syntaxHighlighter);
// only content in the `posts/` directory
eleventyConfig.addCollection("posts", function(collection) {
return collection.getAllSorted().filter(function(item) {