Update dependencies (and to Eleventy v2)

This commit is contained in:
Zach Leatherman 2022-06-27 15:50:25 -05:00
parent 2d3774c225
commit 35e07cc5f9
3 changed files with 26 additions and 49 deletions

View File

@ -1,7 +1,4 @@
const fs = require("fs");
const { DateTime } = require("luxon"); const { DateTime } = require("luxon");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor"); const markdownItAnchor = require("markdown-it-anchor");
const pluginRss = require("@11ty/eleventy-plugin-rss"); const pluginRss = require("@11ty/eleventy-plugin-rss");
@ -44,28 +41,22 @@ module.exports = function(eleventyConfig) {
return Math.min.apply(null, numbers); return Math.min.apply(null, numbers);
}); });
function filterTagList(tags) { // Return all the tags used in a collection
return (tags || []).filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1); eleventyConfig.addFilter("getAllTags", collection => {
}
eleventyConfig.addFilter("filterTagList", filterTagList)
// Create an array of all tags
eleventyConfig.addCollection("tagList", function(collection) {
let tagSet = new Set(); let tagSet = new Set();
collection.getAll().forEach(item => { for(let item of collection) {
(item.data.tags || []).forEach(tag => tagSet.add(tag)); (item.data.tags || []).forEach(tag => tagSet.add(tag));
}
return Array.from(tagSet);
}); });
return filterTagList([...tagSet]); eleventyConfig.addFilter("filterTagList", function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1);
}); });
// Customize Markdown library and settings: // Customize Markdown library and settings:
let markdownLibrary = markdownIt({ eleventyConfig.amendLibrary("md", mdLib => {
html: true, mdLib.use(markdownItAnchor, {
breaks: true,
linkify: true
}).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({ permalink: markdownItAnchor.permalink.ariaHidden({
placement: "after", placement: "after",
class: "direct-link", class: "direct-link",
@ -74,24 +65,11 @@ module.exports = function(eleventyConfig) {
}), }),
slugify: eleventyConfig.getFilter("slug") slugify: eleventyConfig.getFilter("slug")
}); });
eleventyConfig.setLibrary("md", markdownLibrary);
// Override Browsersync defaults (used only with --serve)
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: function(err, browserSync) {
const content_404 = fs.readFileSync('_site/404.html');
browserSync.addMiddleware("*", (req, res) => {
// Provides the 404 content without redirect.
res.writeHead(404, {"Content-Type": "text/html; charset=UTF-8"});
res.write(content_404);
res.end();
}); });
},
}, // Override @11ty/eleventy-dev-server defaults (used only with --serve)
ui: false, eleventyConfig.setServerOptions({
ghostMode: false showVersion: true,
}); });
return { return {

View File

@ -7,8 +7,8 @@
"bench": "DEBUG=Eleventy:Benchmark* npx @11ty/eleventy", "bench": "DEBUG=Eleventy:Benchmark* npx @11ty/eleventy",
"watch": "npx @11ty/eleventy --watch", "watch": "npx @11ty/eleventy --watch",
"serve": "npx @11ty/eleventy --serve", "serve": "npx @11ty/eleventy --serve",
"start": "npx @11ty/eleventy --serve", "start": "npx @11ty/eleventy --serve --quiet",
"debug": "DEBUG=* npx @11ty/eleventy" "debug": "DEBUG=Eleventy* npx @11ty/eleventy"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -25,12 +25,11 @@
}, },
"homepage": "https://github.com/11ty/eleventy-base-blog#readme", "homepage": "https://github.com/11ty/eleventy-base-blog#readme",
"dependencies": { "dependencies": {
"@11ty/eleventy": "^1.0.1", "@11ty/eleventy": "^2.0.0-canary.12",
"@11ty/eleventy-navigation": "^0.3.3", "@11ty/eleventy-navigation": "^0.3.3",
"@11ty/eleventy-plugin-rss": "^1.1.2", "@11ty/eleventy-plugin-rss": "^1.2.0",
"@11ty/eleventy-plugin-syntaxhighlight": "^4.0.0", "@11ty/eleventy-plugin-syntaxhighlight": "^4.0.0",
"luxon": "^2.4.0", "luxon": "^2.4.0",
"markdown-it": "^13.0.1",
"markdown-it-anchor": "^8.6.4" "markdown-it-anchor": "^8.6.4"
} }
} }

View File

@ -4,7 +4,7 @@ layout: layouts/home.njk
--- ---
<h1>Tags</h1> <h1>Tags</h1>
{% for tag in collections.tagList %} {% for tag in collections.all | getAllTags | filterTagList %}
{% set tagUrl %}/tags/{{ tag | slug }}/{% endset %} {% set tagUrl %}/tags/{{ tag | slug }}/{% endset %}
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a> <a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a>
{% endfor %} {% endfor %}