Add next / previous cards to posts

This commit is contained in:
2024-01-02 16:43:56 -06:00
parent bd2b505a5e
commit 3140ef0b72
16 changed files with 233 additions and 28 deletions

View File

@ -3,7 +3,6 @@ const markdownIt = require("markdown-it");
const markdownItFootnote = require("markdown-it-footnote");
const markdownItAnchor = require("markdown-it-anchor");
const mdfigcaption = require('markdown-it-image-figures');
const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginBundle = require("@11ty/eleventy-plugin-bundle");
@ -16,6 +15,13 @@ const figoptions = {
module.exports = function(eleventyConfig) {
// Helper Functions
const multiReplace = (text, replacementTable) => {
let newText = text;
replacementTable.forEach(x => { newText = newText.replace(x[0], x[1]) });
return newText;
};
eleventyConfig.addWatchTarget("content/**/*.{svg,webp,png,jpeg}");
// Official plugins
@ -35,7 +41,37 @@ module.exports = function(eleventyConfig) {
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('yyyy-LL-dd');
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd');
});
// Shortcodes
eleventyConfig.addNunjucksFilter("cowsay", cowText => {
const cowCaptionReplacementTable = [
[`
o ^__^
o (oo)\\_______
(__)\\ )\\/\\
||----w |
|| ||`, ''],
[/\(\s+/g, ''],
[/\s+\(/g, ''],
[/_{3,}/g, ''],
[/-{3,}/g, ''],
[/\s\)/g, ''],
[/\n/g, ''],
[/\s{2,}/g, ' '],
[/^ /, '']
];
return `
<figure>
<pre class="language-" role="img" aria-label="ASCII COW">${cowText}</pre>
<figcaption id="cow-caption">
A cow thinking: <em>${multiReplace(cowText, cowCaptionReplacementTable)}</em>. The cow is illustrated using
preformatted text characters.
</figcaption>
</figure>
`;
});
// Passthrough
@ -48,10 +84,10 @@ module.exports = function(eleventyConfig) {
// Get the first `n` elements of a collection.
eleventyConfig.addFilter("head", (array, n) => {
if(!Array.isArray(array) || array.length === 0) {
if (!Array.isArray(array) || array.length === 0) {
return [];
}
if( n < 0 ) {
if (n < 0) {
return array.slice(n);
}
@ -66,7 +102,7 @@ module.exports = function(eleventyConfig) {
// Return all the tags used in a collection
eleventyConfig.addFilter("getAllTags", collection => {
let tagSet = new Set();
for(let item of collection) {
for (let item of collection) {
(item.data.tags || []).forEach(tag => tagSet.add(tag));
}
return Array.from(tagSet);
@ -85,13 +121,13 @@ module.exports = function(eleventyConfig) {
symbol: "#",
ariaHidden: false, // Features to make your build faster (when you need them)
// If your passthrough copy gets heavy and cumbersome, add this line
// to emulate the file copy on the dev server. Learn more:
// https://www.11ty.dev/docs/copy/#emulate-passthrough-copy-during-serve
// If your passthrough copy gets heavy and cumbersome, add this line
// to emulate the file copy on the dev server. Learn more:
// https://www.11ty.dev/docs/copy/#emulate-passthrough-copy-during-serve
// eleventyConfig.setServerPassthroughCopyBehavior("passthrough");
// eleventyConfig.setServerPassthroughCopyBehavior("passthrough");
}),
level: [1,2,3,4],
level: [1, 2, 3, 4],
slugify: eleventyConfig.getFilter("slugify")
}).use(markdownItFootnote).use(mdfigcaption, figoptions);
});