From 699feac2f20b4613e49682f5c7132409be8b4c72 Mon Sep 17 00:00:00 2001 From: Joshua Seigler Date: Thu, 29 May 2025 15:10:03 -0400 Subject: [PATCH] new-window links in md and footer --- eleventy.config.js | 12 +++++++++++- package-lock.json | 7 +++++++ package.json | 1 + site/_includes/-footer.njk | 2 +- site/pages/books.md | 2 +- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/eleventy.config.js b/eleventy.config.js index 2d14697..9b369c7 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -3,6 +3,7 @@ import path from "path"; import md from "markdown-it"; import mdAnchor from "markdown-it-anchor"; import mdFootnote from "markdown-it-footnote"; +import mdLinkAttributes from "markdown-it-link-attributes"; import prettier from "prettier"; import dayjs from "dayjs"; import utc from "dayjs/plugin/utc.js"; @@ -27,7 +28,16 @@ export default (config) => { symbol: "", }), }) - .use(mdFootnote); + .use(mdFootnote) + .use(mdLinkAttributes, { + matcher(href) { + return href.match(/^https?:\/\//); + }, + attrs: { + target: "_blank", + rel: "noopener", + }, + }); config.setLibrary("md", mdLib); config.addPassthroughCopy({ assets: "/", diff --git a/package-lock.json b/package-lock.json index f56eedc..ba056a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "eleventy-plugin-clean": "^2.0.1", "markdown-it-anchor": "^9.0.1", "markdown-it-footnote": "^4.0.0", + "markdown-it-link-attributes": "^4.0.1", "prettier": "^3.3.1" } }, @@ -1563,6 +1564,12 @@ "integrity": "sha512-WYJ7urf+khJYl3DqofQpYfEYkZKbmXmwxQV8c8mO/hGIhgZ1wOe7R4HLFNwqx7TjILbnC98fuyeSsin19JdFcQ==", "license": "MIT" }, + "node_modules/markdown-it-link-attributes": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/markdown-it-link-attributes/-/markdown-it-link-attributes-4.0.1.tgz", + "integrity": "sha512-pg5OK0jPLg62H4k7M9mRJLT61gUp9nvG0XveKYHMOOluASo9OEF13WlXrpAp2aj35LbedAy3QOCgQCw0tkLKAQ==", + "license": "MIT" + }, "node_modules/markdown-it/node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", diff --git a/package.json b/package.json index e4cc711..895d3be 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "eleventy-plugin-clean": "^2.0.1", "markdown-it-anchor": "^9.0.1", "markdown-it-footnote": "^4.0.0", + "markdown-it-link-attributes": "^4.0.1", "prettier": "^3.3.1" } } diff --git a/site/_includes/-footer.njk b/site/_includes/-footer.njk index 7e6535a..0d278ea 100644 --- a/site/_includes/-footer.njk +++ b/site/_includes/-footer.njk @@ -1,7 +1,7 @@