2018-01-16 22:08:47 -05:00
|
|
|
|
const { DateTime } = require("luxon");
|
2018-01-27 22:08:43 -05:00
|
|
|
|
const metadata = require("./_data/metadata.json");
|
|
|
|
|
const absoluteUrl = require("./_src/absoluteUrl");
|
|
|
|
|
const HtmlToAbsoluteUrls = require("./_src/HtmlToAbsoluteUrls");
|
Refactors Liquid syntax highlighters to add line highlights.
Usage (ranges are space separated):
{% highlight js 1,4-6 %}
One range
Adds `highlight-line-active` to lines 1,4,5,6
{% highlight js 3-4 -1 %}
Two ranges (add/remove), remove is N/A
Adds `highlight-line-add` to lines 3,4
{% highlight js -1 3-4 %}
Two ranges (add/remove), add is N/A
Adds `highlight-line-remove` to lines 3,4
{% highlight js 3-4 5,8-10 %}
Two ranges, both are used
Adds `highlight-line-add` to lines 3-4
Adds `highlight-line-remove` to lines 5,8,9,10
2018-01-26 23:12:46 -05:00
|
|
|
|
const highlighters = require("./_src/eleventy-liquidjs-tag-highlight");
|
2018-01-16 22:08:47 -05:00
|
|
|
|
|
2018-01-22 09:17:48 -05:00
|
|
|
|
function dateToISO(dateObj) {
|
|
|
|
|
return DateTime.fromJSDate(dateObj).toISO({ includeOffset: true, suppressMilliseconds: true });
|
2018-01-16 22:08:47 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 09:17:48 -05:00
|
|
|
|
module.exports = function(eleventyConfig) {
|
|
|
|
|
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");
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-27 22:08:43 -05:00
|
|
|
|
eleventyConfig.addNunjucksFilter("absoluteUrl", function(href, base) {
|
|
|
|
|
return absoluteUrl(href, base);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
eleventyConfig.addNunjucksFilter("htmlToAbsoluteUrls", function(htmlContent, base, callback) {
|
|
|
|
|
if(!htmlContent) {
|
|
|
|
|
callback(null, "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-28 00:21:32 -05:00
|
|
|
|
HtmlToAbsoluteUrls(htmlContent, base).then(result => {
|
2018-01-27 22:08:43 -05:00
|
|
|
|
callback(null, result.html);
|
|
|
|
|
});
|
|
|
|
|
}, true);
|
|
|
|
|
|
2018-01-22 09:17:48 -05:00
|
|
|
|
// compatibility with existing {% highlight js %} and others
|
2018-01-28 00:31:42 -05:00
|
|
|
|
eleventyConfig.addLiquidTag("highlight", highlighters.plain);
|
2018-01-22 09:17:48 -05:00
|
|
|
|
|
|
|
|
|
// only content in the `posts/` directory
|
|
|
|
|
eleventyConfig.addCollection("posts", function(collection) {
|
|
|
|
|
return collection.getAllSorted().filter(function(item) {
|
|
|
|
|
return item.inputPath.match(/^\.\/posts\//) !== null;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
templateFormats: [
|
2018-01-16 22:08:47 -05:00
|
|
|
|
"md",
|
|
|
|
|
"njk",
|
|
|
|
|
"html",
|
|
|
|
|
"png",
|
2018-01-22 09:17:48 -05:00
|
|
|
|
"jpg",
|
2018-01-16 22:08:47 -05:00
|
|
|
|
"css"
|
|
|
|
|
],
|
2018-01-22 09:17:48 -05:00
|
|
|
|
|
2018-01-25 22:03:57 -05:00
|
|
|
|
// 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: "/",
|
2018-01-22 09:17:48 -05:00
|
|
|
|
|
|
|
|
|
markdownTemplateEngine: "liquid",
|
2018-01-16 22:08:47 -05:00
|
|
|
|
htmlTemplateEngine: "njk",
|
|
|
|
|
dataTemplateEngine: "njk",
|
|
|
|
|
passthroughFileCopy: true,
|
|
|
|
|
dir: {
|
|
|
|
|
input: ".",
|
|
|
|
|
includes: "_includes",
|
|
|
|
|
data: "_data",
|
|
|
|
|
output: "_site"
|
2018-01-22 09:17:48 -05:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|