Skip to content

Commit b2c565f

Browse files
enhancement/issue 220 open all external links in a new browser tab (#221)
1 parent 2396dad commit b2c565f

9 files changed

Lines changed: 55 additions & 6 deletions

File tree

greenwood.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ export default {
4747
"rehype-autolink-headings",
4848
"remark-github",
4949
"remark-gfm",
50+
{
51+
name: "rehype-external-links",
52+
options: {
53+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a#security_and_privacy
54+
rel: ["nofollow", "noopener", "noreferrer"],
55+
target: "_blank",
56+
contentProperties: { className: ["no-show-screen-reader"] },
57+
content: [{ type: "text", value: " (opens in a new window)" }],
58+
properties: { className: ["external-link-icon"] },
59+
},
60+
},
5061
],
5162
},
5263

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"node-html-parser": "^6.1.13",
6767
"prettier": "^3.2.5",
6868
"rehype-autolink-headings": "^4.0.0",
69+
"rehype-external-links": "^3.0.0",
6970
"rehype-slug": "^3.0.0",
7071
"remark-gfm": "^4.0.0",
7172
"remark-github": "^10.0.1",

src/assets/external-link.svg

Lines changed: 8 additions & 0 deletions
Loading

src/components/get-started/get-started.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ export default class GetStarted extends HTMLElement {
1515
</div>
1616
1717
<div>
18-
<a href="https://stackblitz.com/github/projectevergreen/greenwood-getting-started" class="${styles.buttonBlitz}">
18+
<a href="https://stackblitz.com/github/projectevergreen/greenwood-getting-started" class="${styles.buttonBlitz}" target="_blank">
1919
<span>View in Stackblitz</span>
20+
<span class="no-show-screen-reader"> (opens in a new window)</span>
2021
</a>
2122
2223
<a href="/guides/getting-started/" class="${styles.buttonStarted}">

src/components/hero-banner/hero-banner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export default class HeroBanner extends HTMLElement {
1212
<p class="${styles.headingSub}">Greenwood is your workbench for the web, embracing web standards from the ground up to empower your stack from front to back.</p>
1313
1414
<div class="${styles.ctaContainer}">
15-
<a href="https://stackblitz.com/github/projectevergreen/greenwood-getting-started" class="${styles.buttonBlitz}">
15+
<a href="https://stackblitz.com/github/projectevergreen/greenwood-getting-started" class="${styles.buttonBlitz}" target="_blank">
1616
<span>View in Stackblitz</span>
17+
<span class="no-show-screen-reader"> (opens in a new window)</span>
1718
</a>
1819
1920
<a href="/guides/getting-started/" class="${styles.buttonStarted}">

src/components/social-tray/social-tray.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,30 @@ export default class SocialTray extends HTMLElement {
99
this.innerHTML = `
1010
<ul class="${styles.socialTray}">
1111
<li class="${styles.socialIcon}">
12-
<a href="https://github.com/ProjectEvergreen/greenwood" title="GitHub">
12+
<a href="https://github.com/ProjectEvergreen/greenwood" title="GitHub" target="_blank">
1313
${githubIcon}
14+
<span class="no-show-screen-reader"> (opens in a new window)</span>
1415
</a>
1516
</li>
1617
1718
<li class="${styles.socialIcon}">
18-
<a href="/discord/" title="Discord">
19+
<a href="/discord/" title="Discord" target="_blank">
1920
${discordIcon}
21+
<span class="no-show-screen-reader"> (opens in a new window)</span>
2022
</a>
2123
</li>
2224
2325
<li class="${styles.socialIcon}">
24-
<a href="https://bsky.app/profile/projectevergreen.bsky.social" title="BlueSky">
26+
<a href="https://bsky.app/profile/projectevergreen.bsky.social" title="BlueSky" target="_blank">
2527
${blueskyIcon}
28+
<span class="no-show-screen-reader"> (opens in a new window)</span>
2629
</a>
2730
</li>
2831
2932
<li class="${styles.socialIcon}">
30-
<a href="https://twitter.com/PrjEvergreen" title="Twitter">
33+
<a href="https://twitter.com/PrjEvergreen" title="Twitter" target="_blank">
3134
${twitterIcon}
35+
<span class="no-show-screen-reader"> (opens in a new window)</span>
3236
</a>
3337
</li>
3438
</ul>

src/components/social-tray/social-tray.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ describe("Components/Social Tray", () => {
4040
it("should have the expected social link icons", () => {
4141
const links = tray.querySelectorAll("ul li a");
4242
const icons = tray.querySelectorAll("ul li a svg");
43+
const noShowScreenReader = tray.querySelectorAll("ul li a span.no-show-screen-reader");
4344

4445
expect(links.length).to.equal(4);
4546
expect(icons.length).to.equal(4);
47+
expect(noShowScreenReader.length).to.equal(4);
4648

4749
Array.from(links).forEach((link) => {
4850
const iconItem = ICONS.find((icon) => icon.title === link.getAttribute("title"));
4951

5052
expect(iconItem).to.not.equal(undefined);
5153
expect(link.getAttribute("href")).to.equal(iconItem.link);
54+
expect(link.getAttribute("target")).equal("_blank");
5255
});
5356
});
5457
});

src/styles/theme.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,20 @@ li {
144144
font-style: italic;
145145
}
146146
}
147+
148+
/* external links styling */
149+
.no-show-screen-reader {
150+
clip: rect(0 0 0 0);
151+
clip-path: inset(50%);
152+
height: 1px;
153+
overflow: hidden;
154+
position: absolute;
155+
white-space: nowrap;
156+
width: 1px;
157+
}
158+
159+
.external-link-icon::after {
160+
content: url(/assets/external-link.svg);
161+
margin: 0 0 0 var(--size-1);
162+
vertical-align: middle;
163+
}

0 commit comments

Comments
 (0)