This commit is contained in:
Zach Leatherman 2021-03-17 10:29:29 -05:00
parent a9fdacc9a6
commit 7e5a1f5ce7
4 changed files with 34 additions and 30 deletions

View File

@ -7,12 +7,15 @@ const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor"); const markdownItAnchor = require("markdown-it-anchor");
module.exports = function(eleventyConfig) { module.exports = function(eleventyConfig) {
// Add plugins
eleventyConfig.addPlugin(pluginRss); eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginSyntaxHighlight); eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.addPlugin(pluginNavigation); eleventyConfig.addPlugin(pluginNavigation);
// https://www.11ty.dev/docs/data-deep-merge/
eleventyConfig.setDataDeepMerge(true); eleventyConfig.setDataDeepMerge(true);
// Alias `layout: post` to `layout: layouts/post.njk`
eleventyConfig.addLayoutAlias("post", "layouts/post.njk"); eleventyConfig.addLayoutAlias("post", "layouts/post.njk");
eleventyConfig.addFilter("readableDate", dateObj => { eleventyConfig.addFilter("readableDate", dateObj => {
@ -33,43 +36,32 @@ module.exports = function(eleventyConfig) {
return array.slice(0, n); return array.slice(0, n);
}); });
// Return the smallest number argument
eleventyConfig.addFilter("min", (...numbers) => { eleventyConfig.addFilter("min", (...numbers) => {
return Math.min.apply(null, numbers); return Math.min.apply(null, numbers);
}); });
// Create an array of all tags
eleventyConfig.addCollection("tagList", function(collection) { eleventyConfig.addCollection("tagList", function(collection) {
let tagSet = new Set(); let tagSet = new Set();
collection.getAll().forEach(function(item) { collection.getAll().forEach(function(item) {
if( "tags" in item.data ) { if( "tags" in item.data ) {
let tags = item.data.tags; let tags = item.data.tags;
tags = tags.filter(function(item) {
switch(item) {
// this list should match the `filter` list in tags.njk // this list should match the `filter` list in tags.njk
case "all": tags.filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1)
case "nav": .forEach(tag => tagSet.add(tag));
case "post":
case "posts":
return false;
}
return true;
});
for (const tag of tags) {
tagSet.add(tag);
}
} }
}); });
// returning an array in addCollection works in Eleventy 0.5.3
return [...tagSet]; return [...tagSet];
}); });
// Copy the `img` and `css` folders to the output
eleventyConfig.addPassthroughCopy("img"); eleventyConfig.addPassthroughCopy("img");
eleventyConfig.addPassthroughCopy("css"); eleventyConfig.addPassthroughCopy("css");
/* Markdown Overrides */ // Customize Markdown library and settings:
let markdownLibrary = markdownIt({ let markdownLibrary = markdownIt({
html: true, html: true,
breaks: true, breaks: true,
@ -81,7 +73,7 @@ module.exports = function(eleventyConfig) {
}); });
eleventyConfig.setLibrary("md", markdownLibrary); eleventyConfig.setLibrary("md", markdownLibrary);
// Browsersync Overrides // Override Browsersync defaults (used only with --serve)
eleventyConfig.setBrowserSyncConfig({ eleventyConfig.setBrowserSyncConfig({
callbacks: { callbacks: {
ready: function(err, browserSync) { ready: function(err, browserSync) {
@ -100,6 +92,8 @@ module.exports = function(eleventyConfig) {
}); });
return { return {
// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
templateFormats: [ templateFormats: [
"md", "md",
"njk", "njk",
@ -107,21 +101,30 @@ module.exports = function(eleventyConfig) {
"liquid" "liquid"
], ],
// If your site lives in a different subdirectory, change this. // -----------------------------------------------------------------
// Leading or trailing slashes are all normalized away, so dont worry about those. // If your site deploys to a subdirectory, change `pathPrefix`.
// Dont worry about leading and trailing slashes, we normalize these.
// If you dont have a subdirectory, use "" or "/" (they do the same thing) // If you dont have a subdirectory, use "" or "/" (they do the same thing)
// This is only used for link URLs (it does not affect your file structure) // 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/ // 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` // 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", 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: { dir: {
input: ".", input: ".",
includes: "_includes", includes: "_includes",

View File

@ -6,10 +6,12 @@ templateClass: tmpl-post
{{ content | safe }} {{ content | safe }}
{%- set nextPost = collections.posts | getNextCollectionItem(page) %}
{%- set previousPost = collections.posts | getPreviousCollectionItem(page) %}
{% if nextPost or previousPost %}
<hr> <hr>
<ul> <ul>
{%- set nextPost = collections.posts | getNextCollectionItem(page) %}
{%- if nextPost %}<li>Next: <a href="{{ nextPost.url | url }}">{{ nextPost.data.title }}</a></li>{% endif %} {%- if nextPost %}<li>Next: <a href="{{ nextPost.url | url }}">{{ nextPost.data.title }}</a></li>{% endif %}
{%- set previousPost = collections.posts | getPreviousCollectionItem(page) %}
{%- if previousPost %}<li>Previous: <a href="{{ previousPost.url | url }}">{{ previousPost.data.title }}</a></li>{% endif %} {%- if previousPost %}<li>Previous: <a href="{{ previousPost.url | url }}">{{ previousPost.data.title }}</a></li>{% endif %}
</ul> </ul>
{% endif %}

View File

@ -4,7 +4,6 @@ eleventyNavigation:
key: Home key: Home
order: 1 order: 1
--- ---
{% set maxPosts = collections.posts.length | min(3) %} {% set maxPosts = collections.posts.length | min(3) %}
<h1>Latest {% if maxPosts == 1 %}Post{% else %}{{ maxPosts }} Posts{% endif %}</h1> <h1>Latest {% if maxPosts == 1 %}Post{% else %}{{ maxPosts }} Posts{% endif %}</h1>

View File

@ -27,8 +27,8 @@
"@11ty/eleventy": "^0.11.1", "@11ty/eleventy": "^0.11.1",
"@11ty/eleventy-navigation": "^0.1.6", "@11ty/eleventy-navigation": "^0.1.6",
"@11ty/eleventy-plugin-rss": "^1.1.0", "@11ty/eleventy-plugin-rss": "^1.1.0",
"@11ty/eleventy-plugin-syntaxhighlight": "^3.0.6", "@11ty/eleventy-plugin-syntaxhighlight": "^3.1.0",
"luxon": "^1.25.0", "luxon": "^1.26.0",
"markdown-it": "^8.4.2", "markdown-it": "^8.4.2",
"markdown-it-anchor": "^5.2.5" "markdown-it-anchor": "^5.2.5"
} }