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 markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const pluginRss = require("@11ty/eleventy-plugin-rss");
@ -44,54 +41,35 @@ module.exports = function(eleventyConfig) {
return Math.min.apply(null, numbers);
});
function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1);
}
eleventyConfig.addFilter("filterTagList", filterTagList)
// Create an array of all tags
eleventyConfig.addCollection("tagList", function(collection) {
// Return all the tags used in a collection
eleventyConfig.addFilter("getAllTags", collection => {
let tagSet = new Set();
collection.getAll().forEach(item => {
for(let item of collection) {
(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:
let markdownLibrary = markdownIt({
html: true,
breaks: true,
linkify: true
}).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
placement: "after",
class: "direct-link",
symbol: "#",
level: [1,2,3,4],
}),
slugify: eleventyConfig.getFilter("slug")
eleventyConfig.amendLibrary("md", mdLib => {
mdLib.use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
placement: "after",
class: "direct-link",
symbol: "#",
level: [1,2,3,4],
}),
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();
});
},
},
ui: false,
ghostMode: false
// Override @11ty/eleventy-dev-server defaults (used only with --serve)
eleventyConfig.setServerOptions({
showVersion: true,
});
return {

View File

@ -7,8 +7,8 @@
"bench": "DEBUG=Eleventy:Benchmark* npx @11ty/eleventy",
"watch": "npx @11ty/eleventy --watch",
"serve": "npx @11ty/eleventy --serve",
"start": "npx @11ty/eleventy --serve",
"debug": "DEBUG=* npx @11ty/eleventy"
"start": "npx @11ty/eleventy --serve --quiet",
"debug": "DEBUG=Eleventy* npx @11ty/eleventy"
},
"repository": {
"type": "git",
@ -25,12 +25,11 @@
},
"homepage": "https://github.com/11ty/eleventy-base-blog#readme",
"dependencies": {
"@11ty/eleventy": "^1.0.1",
"@11ty/eleventy": "^2.0.0-canary.12",
"@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",
"luxon": "^2.4.0",
"markdown-it": "^13.0.1",
"markdown-it-anchor": "^8.6.4"
}
}

View File

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