From 7e5a1f5ce7aa1b92d0868320b883307ec46282c9 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Wed, 17 Mar 2021 10:29:29 -0500 Subject: [PATCH] Fixes #62. --- .eleventy.js | 53 ++++++++++++++++++++------------------ _includes/layouts/post.njk | 6 +++-- index.njk | 1 - package.json | 4 +-- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index b2f39d6..177cbf2 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -7,12 +7,15 @@ const markdownIt = require("markdown-it"); const markdownItAnchor = require("markdown-it-anchor"); module.exports = function(eleventyConfig) { + // Add plugins eleventyConfig.addPlugin(pluginRss); eleventyConfig.addPlugin(pluginSyntaxHighlight); eleventyConfig.addPlugin(pluginNavigation); + // https://www.11ty.dev/docs/data-deep-merge/ eleventyConfig.setDataDeepMerge(true); + // Alias `layout: post` to `layout: layouts/post.njk` eleventyConfig.addLayoutAlias("post", "layouts/post.njk"); eleventyConfig.addFilter("readableDate", dateObj => { @@ -33,43 +36,32 @@ module.exports = function(eleventyConfig) { return array.slice(0, n); }); + // Return the smallest number argument eleventyConfig.addFilter("min", (...numbers) => { return Math.min.apply(null, numbers); }); + // Create an array of all tags eleventyConfig.addCollection("tagList", function(collection) { let tagSet = new Set(); collection.getAll().forEach(function(item) { if( "tags" in item.data ) { let tags = item.data.tags; - tags = tags.filter(function(item) { - switch(item) { - // this list should match the `filter` list in tags.njk - case "all": - case "nav": - case "post": - case "posts": - return false; - } - - return true; - }); - - for (const tag of tags) { - tagSet.add(tag); - } + // this list should match the `filter` list in tags.njk + tags.filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1) + .forEach(tag => tagSet.add(tag)); } }); - // returning an array in addCollection works in Eleventy 0.5.3 return [...tagSet]; }); + // Copy the `img` and `css` folders to the output eleventyConfig.addPassthroughCopy("img"); eleventyConfig.addPassthroughCopy("css"); - /* Markdown Overrides */ + // Customize Markdown library and settings: let markdownLibrary = markdownIt({ html: true, breaks: true, @@ -81,7 +73,7 @@ module.exports = function(eleventyConfig) { }); eleventyConfig.setLibrary("md", markdownLibrary); - // Browsersync Overrides + // Override Browsersync defaults (used only with --serve) eleventyConfig.setBrowserSyncConfig({ callbacks: { ready: function(err, browserSync) { @@ -100,6 +92,8 @@ module.exports = function(eleventyConfig) { }); return { + // Control which files Eleventy will process + // e.g.: *.md, *.njk, *.html, *.liquid templateFormats: [ "md", "njk", @@ -107,21 +101,30 @@ module.exports = function(eleventyConfig) { "liquid" ], - // If your site lives in a different subdirectory, change this. - // Leading or trailing slashes are all normalized away, so don’t worry about those. + // ----------------------------------------------------------------- + // If your site deploys to a subdirectory, change `pathPrefix`. + // Don’t worry about leading and trailing slashes, we normalize these. // If you don’t have a subdirectory, use "" or "/" (they do the same thing) // This is only used for link URLs (it does not affect your file structure) // Best paired with the `url` filter: https://www.11ty.dev/docs/filters/url/ // You can also pass this in on the command line using `--pathprefix` - // pathPrefix: "/", + // Optional (default is shown) + pathPrefix: "/", + // ----------------------------------------------------------------- + + // Pre-process *.md files with: (default: `liquid`) markdownTemplateEngine: "liquid", - htmlTemplateEngine: "njk", - dataTemplateEngine: "njk", - // These are all optional, defaults are shown: + // Pre-process *.html files with: (default: `liquid`) + htmlTemplateEngine: "njk", + + // Opt-out of pre-processing global data JSON files: (default: `liquid`) + dataTemplateEngine: false, + + // These are all optional (defaults are shown): dir: { input: ".", includes: "_includes", diff --git a/_includes/layouts/post.njk b/_includes/layouts/post.njk index 2c046b3..83eae7a 100644 --- a/_includes/layouts/post.njk +++ b/_includes/layouts/post.njk @@ -6,10 +6,12 @@ templateClass: tmpl-post {{ content | safe }} +{%- set nextPost = collections.posts | getNextCollectionItem(page) %} +{%- set previousPost = collections.posts | getPreviousCollectionItem(page) %} +{% if nextPost or previousPost %}
+{% endif %} diff --git a/index.njk b/index.njk index d492062..bf096f7 100644 --- a/index.njk +++ b/index.njk @@ -4,7 +4,6 @@ eleventyNavigation: key: Home order: 1 --- - {% set maxPosts = collections.posts.length | min(3) %}

Latest {% if maxPosts == 1 %}Post{% else %}{{ maxPosts }} Posts{% endif %}

diff --git a/package.json b/package.json index 65bfc56..2168fd7 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ "@11ty/eleventy": "^0.11.1", "@11ty/eleventy-navigation": "^0.1.6", "@11ty/eleventy-plugin-rss": "^1.1.0", - "@11ty/eleventy-plugin-syntaxhighlight": "^3.0.6", - "luxon": "^1.25.0", + "@11ty/eleventy-plugin-syntaxhighlight": "^3.1.0", + "luxon": "^1.26.0", "markdown-it": "^8.4.2", "markdown-it-anchor": "^5.2.5" }