diff --git a/.eleventy.js b/.eleventy.js index 47c32aa..380eaaa 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -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; - } - } - }; -}; \ No newline at end of file + } + }; +}; diff --git a/_data/metadata.json b/_data/metadata.json index 930064f..1852675 100644 --- a/_data/metadata.json +++ b/_data/metadata.json @@ -1,11 +1,13 @@ { - "title": "Eleventy, the Blog", - "subtitle": "This is a sample project to showcase the Eleventy Static Site Generator.", - "feedurl": "https://11ty.io/feed/", - "url": "https://11ty.io/", - "id": "https://11ty.io/", + "title": "Your Blog Name", + "url": "https://myurl.com/", + "feed": { + "subtitle": "I am writing about my experiences as a naval navel-gazer.", + "url": "https://myurl.com/feed/", + "id": "https://myurl.com/" + }, "author": { - "name": "Zach Leatherman", - "email": "zachleat@zachleat.com" + "name": "Your Name Here", + "email": "youremailaddress@example.com" } } \ No newline at end of file diff --git a/_includes/layouts/base.njk b/_includes/layouts/base.njk index f483819..5b2c13c 100644 --- a/_includes/layouts/base.njk +++ b/_includes/layouts/base.njk @@ -3,24 +3,28 @@
-