add the thing that auto does target=blank

This commit is contained in:
2026-09-15 18:12:18 -07:00
parent 5a8b4d4b9b
commit 3b22f8dab9
3 changed files with 27 additions and 4 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", {
+9 -2
View File
@@ -5,14 +5,14 @@
"requires": true,
"packages": {
"": {
"name": "11ty",
"version": "1.0.0",
"license": "AGPL-3.0-only",
"devDependencies": {
"@11ty/eleventy": "^3.1.5",
"@11ty/eleventy-img": "^6.0.4",
"@mdit/plugin-attrs": "^0.25.1",
"luxon": "^3.7.2"
"luxon": "^3.7.2",
"markdown-it-link-attributes": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main"
}
},
"node_modules/@11ty/dependency-tree": {
@@ -1798,6 +1798,13 @@
"markdown-it": "bin/markdown-it.mjs"
}
},
"node_modules/markdown-it-link-attributes": {
"version": "4.0.1",
"resolved": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main",
"integrity": "sha512-AWUn7JiBi431HkZyXR2MRJxU0wQolHmG/TFCrRSq+w/q4mIzY7c3QKBF1eYEQwXx8IKLdmBVxZA37tp3S1ZkYQ==",
"dev": true,
"license": "MIT"
},
"node_modules/markdown-it/node_modules/entities": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
+2 -1
View File
@@ -13,6 +13,7 @@
"@11ty/eleventy": "^3.1.5",
"@11ty/eleventy-img": "^6.0.4",
"@mdit/plugin-attrs": "^0.25.1",
"luxon": "^3.7.2"
"luxon": "^3.7.2",
"markdown-it-link-attributes": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main"
}
}