start of eleventy-base-blog that pairs with 0.2.8

This commit is contained in:
Zach Leatherman
2018-01-22 08:17:48 -06:00
parent 283df5ef4c
commit b9c0d87306
13 changed files with 193 additions and 87 deletions

View File

@@ -1,19 +1,53 @@
const { DateTime } = require("luxon");
const liquidjsSyntaxHighlighter = require("./_src/eleventy-liquidjs-tag-highlight-prismjs");
function dateToISO(str) {
return DateTime.fromJSDate(str).toISO({ includeOffset: true, suppressMilliseconds: true });
function dateToISO(dateObj) {
return DateTime.fromJSDate(dateObj).toISO({ includeOffset: true, suppressMilliseconds: true });
}
module.exports = function(config) {
return {
templateFormats: [
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");
});
// compatibility with existing {% highlight js %} and others
eleventyConfig.addLiquidTag("highlight", liquidjsSyntaxHighlighter);
// 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: [
"md",
"njk",
"html",
"png",
"jpg",
"css"
],
markdownTemplateEngine: "njk",
// if your site lives in a subdirectory, change this
urlPrefix: "/",
markdownTemplateEngine: "liquid",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
passthroughFileCopy: true,
@@ -22,23 +56,6 @@ module.exports = function(config) {
includes: "_includes",
data: "_data",
output: "_site"
},
nunjucksFilters: {
lastUpdatedDate: collection => {
// Newest date in the collection
return dateToISO(collection[ collection.length - 1 ].date);
},
rssDate: dateObj => {
return dateToISO(dateObj);
},
url: url => {
// If your blog lives in a subdirectory, change this:
let rootDir = "/";
if( !url || url === "/" ) {
return rootDir;
}
return rootDir + url;
}
}
};
};
}
};
};