From 5036ae46548365cf16499e25555c5b3a970bac88 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 30 Dec 2025 19:31:37 -0600 Subject: [PATCH] feat: open mdx post urls in a new tab --- astro.config.mjs | 14 ++++++++++++-- package.json | 1 + pnpm-lock.yaml | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index f1fd94c..cecd5c9 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,7 +1,8 @@ import { defineConfig } from "astro/config"; import mdx from "@astrojs/mdx"; -import remarkMath from "remark-math"; +import rehypeExternalLinks from "rehype-external-links"; import rehypeKatex from "rehype-katex"; +import remarkMath from "remark-math"; import path from "path"; const midnight = { @@ -73,7 +74,16 @@ export default defineConfig({ integrations: [ mdx({ remarkPlugins: [remarkMath], - rehypePlugins: [rehypeKatex], + rehypePlugins: [ + rehypeKatex, + [ + rehypeExternalLinks, + { + target: "_blank", + rel: ["noopener", "noreferrer"], + }, + ], + ], }), ], vite: { diff --git a/package.json b/package.json index 3afab55..1cdab3e 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "dependencies": { "@astrojs/mdx": "^4.3.6", "astro": "^5.14.1", + "rehype-external-links": "^3.0.0", "rehype-katex": "^7.0.1", "remark-math": "^6.0.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b5081b7..288fd53 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: astro: specifier: ^5.14.1 version: 5.14.1(@types/node@24.7.0)(rollup@4.52.4)(typescript@5.9.3)(yaml@2.8.1) + rehype-external-links: + specifier: ^3.0.0 + version: 3.0.0 rehype-katex: specifier: ^7.0.1 version: 7.0.1 @@ -1308,6 +1311,10 @@ packages: iron-webcrypto@1.2.1: resolution: {integrity: sha512-feOM6FaSr6rEABp/eDfVseKyTMDt+KGpeB35SkVn9Tyn0CqvVsY3EwI0v5i8nMHyJnzCIQf7nsy3p41TPkJZhg==} + is-absolute-url@4.0.1: + resolution: {integrity: sha512-/51/TKE88Lmm7Gc4/8btclNXWS+g50wXhYJq8HWIBAGUBnoAdRu1aXeh364t/O7wXDAcTJDP8PNuNKWUDWie+A==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + is-alphabetical@2.0.1: resolution: {integrity: sha512-FWyyY60MeTNyeSRpkM2Iry0G9hpr7/9kD40mD/cGQEuilcZYS4okz8SN2Q6rLCJ8gbCt6fN+rC+6tMGS99LaxQ==} @@ -1830,6 +1837,9 @@ packages: regex@6.0.1: resolution: {integrity: sha512-uorlqlzAKjKQZ5P+kTJr3eeJGSVroLKoHmquUj4zHWuR+hEyNqlXsSKlYYF5F4NI6nl7tWCs0apKJ0lmfsXAPA==} + rehype-external-links@3.0.0: + resolution: {integrity: sha512-yp+e5N9V3C6bwBeAC4n796kc86M4gJCdlVhiMTxIrJG5UHDMh+PJANf9heqORJbt1nrCbDwIlAZKjANIaVBbvw==} + rehype-katex@7.0.1: resolution: {integrity: sha512-OiM2wrZ/wuhKkigASodFoo8wimG3H12LWQaH8qSPVJn9apWKFSH3YOCtbKpBorTVw/eI7cuT21XBbvwEswbIOA==} @@ -3889,6 +3899,8 @@ snapshots: iron-webcrypto@1.2.1: {} + is-absolute-url@4.0.1: {} + is-alphabetical@2.0.1: {} is-alphanumerical@2.0.1: @@ -4683,6 +4695,15 @@ snapshots: dependencies: regex-utilities: 2.3.0 + rehype-external-links@3.0.0: + dependencies: + '@types/hast': 3.0.4 + '@ungap/structured-clone': 1.3.0 + hast-util-is-element: 3.0.0 + is-absolute-url: 4.0.1 + space-separated-tokens: 2.0.2 + unist-util-visit: 5.0.0 + rehype-katex@7.0.1: dependencies: '@types/hast': 3.0.4