Skip to content

Commit 271b01c

Browse files
committed
feat: add support for external links with external-link icon
- Updated `icon.html` to include an SVG for the `external-link` icon. - Introduced `render-link.html` partial to handle external link rendering with appropriate attributes (e.g., `target="_blank"`, `rel="noopener noreferrer nofollow"`). - External links now display an inline icon for improved UX.
1 parent 867d05e commit 271b01c

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{ $isExternal := or (hasPrefix .Destination "http://") (hasPrefix .Destination "https://") }}
2+
3+
<a href="{{ .Destination | safeURL }}"
4+
{{ with .Title }}title="{{ . }}"{{ end }}
5+
{{ if $isExternal }}class="inline-flex items-center gap-1" target="_blank" rel="noopener noreferrer nofollow"{{ end }}>
6+
{{ .Text | safeHTML }}
7+
{{- if $isExternal -}}
8+
{{- partial "icon.html" (dict "name" "external-link" "class" "h-4 w-4 stroke-current" "size" 16) -}}
9+
{{- end -}}
10+
</a>

themes/custom/layouts/partials/icon.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- $name := .name | default "" | lower -}}
2-
{{- $supported := slice "github" "linkedin" "bluesky" "x" -}}
2+
{{- $supported := slice "github" "linkedin" "bluesky" "x" "external-link" -}}
33
{{- if in $supported $name -}}
44
{{- $size := .size | default 24 -}}
55
{{- $class := .class -}}
@@ -36,5 +36,10 @@
3636
{{- if eq $name "bluesky" }}
3737
<path d="M6.335 5.144c-1.654 -1.199 -4.335 -2.127 -4.335 .826c0 .59 .35 4.953 .556 5.661c.713 2.463 3.13 2.75 5.444 2.369c-4.045 .665 -4.889 3.208 -2.667 5.41c1.03 1.018 1.913 1.59 2.667 1.59c2 0 3.134 -2.769 3.5 -3.5c.333 -.667 .5 -1.167 .5 -1.5c0 .333 .167 .833 .5 1.5c.366 .731 1.5 3.5 3.5 3.5c.754 0 1.637 -.571 2.667 -1.59c2.222 -2.203 1.378 -4.746 -2.667 -5.41c2.314 .38 4.73 .094 5.444 -2.369c.206 -.708 .556 -5.072 .556 -5.661c0 -2.953 -2.68 -2.025 -4.335 -.826c-2.293 1.662 -4.76 5.048 -5.665 6.856c-.905 -1.808 -3.372 -5.194 -5.665 -6.856z" />
3838
{{- end }}
39+
{{- if eq $name "external-link" }}
40+
<path d="M12 6h-6a2 2 0 0 0 -2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-6" />
41+
<path d="M11 13l9 -9" />
42+
<path d="M15 4h5v5" />
43+
{{- end }}
3944
</svg>
4045
{{- end -}}

0 commit comments

Comments
 (0)