Build and copy to prod / build-and-copy (push) Successful in 4m15s
Eleventy Image v7 removed its synchronous stats API, which broke the build. Rather than downgrade (older versions bundle a vulnerable sharp), adapt to v7 and clear out the remaining vulnerable dependencies: - Make the `image` shortcode async - Replace the unmaintained markdown-it-eleventy-img with a local plugin that pre-loads image metadata in eleventy.before, so markdown (and feed) images keep rendering as <picture> elements - Upgrade @11ty/eleventy-fetch to v6 - Swap npm-run-all for the maintained npm-run-all2 fork - Override eleventy-plugin-og-image's satori (and its pinned fflate) to patched versions, and set explicit heading weights in the OG template so newer satori doesn't synthesise bold text
83 lines
2.3 KiB
JavaScript
83 lines
2.3 KiB
JavaScript
import path from "node:path";
|
|
import fs from "node:fs";
|
|
import markdownIt from 'markdown-it';
|
|
import markdownItPrism from 'markdown-it-prism';
|
|
import markdownItAnchor from 'markdown-it-anchor';
|
|
import markdownItClass from '@toycode/markdown-it-class';
|
|
import markdownItLinkAttributes from 'markdown-it-link-attributes';
|
|
import { full as markdownItEmoji } from 'markdown-it-emoji';
|
|
import markdownItFootnote from 'markdown-it-footnote';
|
|
import markdownitMark from 'markdown-it-mark';
|
|
import markdownitAbbr from 'markdown-it-abbr';
|
|
import markdownItCallouts from 'markdown-it-obsidian-callouts';
|
|
import { slugifyString } from '../utils.js';
|
|
import { createMarkdownImages } from './markdown-it-image.js';
|
|
|
|
const icons = JSON.parse(fs.readFileSync('./config/plugins/icons.json'), 'utf-8');
|
|
|
|
const markdownImages = createMarkdownImages({
|
|
imageDir: path.join("src", "images"),
|
|
imgOptions: {
|
|
widths: [300, 600, 1000, 1440],
|
|
urlPath: "/img/",
|
|
outputDir: path.join("_site", "img"),
|
|
formats: ["avif", "webp", "jpeg"]
|
|
},
|
|
globalAttributes: {
|
|
sizes: `(max-width: 300px) 300px,
|
|
(max-width: 600px) 600px,
|
|
(max-width: 1000px) 1000px,
|
|
(max-width: 1440px) 1440px,
|
|
100%`
|
|
}
|
|
});
|
|
|
|
const markdownLib = markdownIt({
|
|
html: true,
|
|
breaks: true,
|
|
linkify: true,
|
|
typographer: true
|
|
})
|
|
.disable('code')
|
|
.use(markdownItPrism, {
|
|
defaultLanguage: 'plaintext'
|
|
})
|
|
.use(markdownItAnchor, {
|
|
slugify: slugifyString,
|
|
tabIndex: false,
|
|
permalink: markdownItAnchor.permalink.headerLink({
|
|
class: 'heading-anchor'
|
|
})
|
|
})
|
|
.use(markdownItClass, {
|
|
ol: 'list',
|
|
ul: 'list'
|
|
})
|
|
.use(markdownItLinkAttributes, [
|
|
{
|
|
// match external links
|
|
matcher(href) {
|
|
return href.match(/^https?:\/\//);
|
|
},
|
|
attrs: {
|
|
target: '_blank',
|
|
rel: 'noreferrer noopener'
|
|
}
|
|
}
|
|
])
|
|
.use(markdownItEmoji, { defs: icons })
|
|
.use(markdownItFootnote)
|
|
.use(markdownitMark)
|
|
.use(markdownitAbbr)
|
|
.use(markdownItCallouts)
|
|
.use(markdownImages.markdownItPlugin);
|
|
|
|
markdownLib.renderer.rules.emoji = function(token, idx) {
|
|
return `<span class="fa-li"><i class="fa-solid fa-${token[idx].markup}" aria-hidden="true"></i></span>`;
|
|
};
|
|
|
|
export default function(eleventyConfig) {
|
|
eleventyConfig.addPlugin(markdownImages.eleventyPlugin);
|
|
eleventyConfig.addFilter('md', content => content ? markdownLib.render(content) : "");
|
|
eleventyConfig.setLibrary('md', markdownLib);
|
|
} |