diff --git a/eleventy.config.js b/eleventy.config.js index 06e0086..f3f1715 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -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", { diff --git a/package-lock.json b/package-lock.json index c9e9156..fa41c34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 36ffc7c..47c3e6e 100644 --- a/package.json +++ b/package.json @@ -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" } }