Skip to content

Commit f91ea19

Browse files
authored
Allow referer to be sent to *.defined.net urls (#330)
1 parent 4014478 commit f91ea19

4 files changed

Lines changed: 43 additions & 5 deletions

File tree

docusaurus.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,17 @@ const config: Config = {
134134
{
135135
label: 'Home',
136136
href: 'https://defined.net',
137+
rel: 'noopener',
137138
},
138139
{
139140
label: 'Blog',
140141
href: 'https://defined.net/blog',
142+
rel: 'noopener',
141143
},
142144
{
143145
label: 'Docs',
144146
href: 'https://docs.defined.net',
147+
rel: 'noopener',
145148
},
146149
],
147150
},

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@docusaurus/core": "3.9.2",
1818
"@docusaurus/preset-classic": "3.9.2",
19+
"@docusaurus/theme-common": "3.9.2",
1920
"@mdx-js/react": "^3.1.1",
2021
"clsx": "^2.1.1",
2122
"parse-domain": "^8.2.2",

pnpm-lock.yaml

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Link from '@docusaurus/Link';
2+
import { useAnchorTargetClassName } from '@docusaurus/theme-common';
3+
import type { Props } from '@theme/MDXComponents/A';
4+
import clsx from 'clsx';
5+
import React, { type ReactNode } from 'react';
6+
7+
export default function MDXA(props: Props): ReactNode {
8+
// MDX Footnotes have ids such as <a id="user-content-fn-1-953011" ...>
9+
const anchorTargetClassName = useAnchorTargetClassName(props.id);
10+
11+
// Customize rel attribute for *.defined.net links
12+
let customRel = props.rel;
13+
let customTarget = props.target;
14+
if (props.href && typeof props.href === 'string') {
15+
try {
16+
const url = new URL(props.href, window.location.href);
17+
// Check if it's an external link to *.defined.net
18+
if (url.hostname.endsWith('.defined.net') || url.hostname === 'defined.net') {
19+
// Override to only use 'noopener' (exclude 'noreferrer')
20+
customRel = 'noopener';
21+
customTarget = '_blank';
22+
}
23+
} catch {
24+
// Invalid URL, let default behavior handle it
25+
}
26+
}
27+
28+
return (
29+
<Link {...props} rel={customRel} target={customTarget} className={clsx(anchorTargetClassName, props.className)} />
30+
);
31+
}

0 commit comments

Comments
 (0)