add target=blank automation

This commit is contained in:
2026-09-15 18:09:41 -07:00
parent 857ae39afe
commit a35ddd1ccc
3 changed files with 81 additions and 26 deletions
+16 -1
View File
@@ -1,5 +1,8 @@
import { attrs } from "@mdit/plugin-attrs";
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import { attrs } from "@mdit/plugin-attrs";
import { markdownitLinkAttributes } from 'markdown-it-link-attributes';
import path from "node:path";
import pluginFilters from "./_config/filters.js";
@@ -8,6 +11,18 @@ export default async function (eleventyConfig) {
/* Markdown HTML attribute parsing */
eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(attrs));
/* Markdown apply target="_blank" to all external links */
const milaOptions = {
matcher(href) {
return href.match(/^https?:\/\//);
},
attrs: {
target: "_blank",
rel: "external",
},
};
eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(markdownitLinkAttributes, milaOptions));
/* Bundles */
/* CSS */
eleventyConfig.addBundle("css", {