fix: open in new tab for links (#22820)

## Description
- Update Contribute `links.md` to verify that internal and external
links open in the same tab.
- Remove "open in new" tab icon 

## Related issues or tickets
https://docker.atlassian.net/browse/ENGDOCS-2717

## Reviews
- [ ] Technical review
- [ ] Editorial review
- [ ] Product review
This commit is contained in:
Sarah Sanders 2025-06-11 12:36:53 -04:00 committed by GitHub
parent 7a31d0c3ed
commit d50fe6664f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 25 deletions

View File

@ -6,18 +6,17 @@ toc_max: 3
## Examples
- [External links](https://docker.com) open in a new tab
- [Internal links](links.md) open in the same tab
[External links](https://docker.com) and [internal links](links.md) both
open in the same tab.
You can use relative links, using source filenames,
or you can use absolute links for pages as they appear on the final site.
Use relative links, using source filenames.
#### Links to auto-generated content
When you link to heading IDs in auto-generated pages, such as CLI reference content,
you won't get any help from your editor in resolving the anchor names. That's
because the pages are generated at build-time and your editor or LSP doesn't know
about them in advance.
When you link to heading IDs in auto-generated pages, such as CLI
reference content, you won't get any help from your editor in resolving the
anchor names. That's because the pages are generated at build-time and your
editor or LSP doesn't know about them in advance.
## Syntax

View File

@ -2,7 +2,6 @@
"htmlElements": {
"tags": null,
"classes": [
"!mt-0",
"--mount",
"--tmpfs",
"-mr-8",
@ -33,13 +32,15 @@
"Command-Prompt-CLI",
"Compliant",
"Custom-builder",
"DNS-resolution",
"Debian",
"Debian-GNU/Linux",
"Diff",
"Docker-Desktop",
"Docker-Engine",
"Docker-Hub",
"Docker-Scout-Dashboard",
"Docker-plan",
"Docker-subscription",
"Download",
"Entra-ID",
"Entra-ID-SAML-2.0",
@ -47,6 +48,8 @@
"Fedora",
"For-Mac-with-Apple-silicon",
"For-Mac-with-Intel-chip",
"From-Docker-Desktop",
"From-the-Docker-CLI",
"From-the-GUI",
"From-the-command-line",
"GUI",
@ -65,8 +68,8 @@
"JavaScript",
"Jenkins",
"Latest",
"Legacy-Docker-plan",
"Legacy-Docker-plans",
"Legacy-Docker-subscription",
"Linux",
"Local-or-Hub-storage",
"MDM",
@ -80,6 +83,7 @@
"Mac-with-Intel-chip",
"Manually-create-assets",
"NetworkManager",
"Networking-mode",
"Node",
"Non-compliant",
"Okta",
@ -146,8 +150,8 @@
"bg-amber-500",
"bg-background-light",
"bg-background-toc",
"bg-black/100",
"bg-black/50",
"bg-black/70",
"bg-blue",
"bg-blue-400",
"bg-blue-500",
@ -445,7 +449,6 @@
"overflow-x-auto",
"overflow-x-hidden",
"overflow-y-auto",
"p-1",
"p-2",
"p-3",
"p-4",
@ -459,7 +462,6 @@
"pb-20",
"pb-4",
"pb-8",
"pl-1",
"pl-2",
"pl-3",
"pl-4",
@ -513,7 +515,6 @@
"sm:hidden",
"sm:items-center",
"sm:w-full",
"space-x-2",
"space-y-2",
"space-y-4",
"sticky",
@ -523,6 +524,9 @@
"svg-container",
"syntax-light",
"systemd-networkd",
"tab-item",
"tablist",
"tabs",
"text-2xl",
"text-base",
"text-black",

View File

@ -1,22 +1,13 @@
{{ $url := .Destination }}
{{- if (strings.HasPrefix $url "http") -}}
{{/* external link, add icon */}}
<a class="link" href="{{ $url | safeURL }}" rel="noopener">
{{ .Text | safeHTML }}
<span class="pl-1 icon-svg icon-sm">
{{ partialCached "icon" "open_in_new" "open_in_new" }}
</span>
</a>
<a class="link" href="{{ $url | safeURL }}" rel="noopener">{{ .Text | safeHTML }}</a>
{{- else if (strings.HasPrefix $url "mailto:") -}}
{{/* mailto link, render as normal link */}}
<a class="link" href="{{ $url }}">{{ .Text | safeHTML }}</a>
{{- else if (strings.HasPrefix $url "/") -}}
{{ if (strings.HasSuffix (urls.Parse $url).Path ".md") }}
{{/* abs path to markdown file, use ref */}}
{{ $url = (ref page $url) }}
{{ end }}
<a class="link" href="{{ $url }}">{{ .Text | safeHTML }}</a>
{{- else -}}
{{/* relative link, use ref */}}
<a class="link" href="{{ ref page $url }}">{{ .Text | safeHTML }}</a>
{{- end -}}