Browse Source

feat(shortcode): add trusted custom attr to external

Josh Habdas 6 months ago
parent
commit
9b0d5f5f2b
Signed by: Josh Habdas <jhabdas@protonmail.com> GPG Key ID: B148B31154C75A74

+ 15
- 5
docs/content/shortcode/external.md View File

@@ -4,7 +4,7 @@ description = "Create links with external icon and custom behavior."
4 4
 categories = ["navigation"]
5 5
 tags = ["links", "security", "privacy"]
6 6
 html_attributes = ["href", "class", "referrerpolicy", "target", "type", "rel"]
7
-custom_attributes = ["text"]
7
+custom_attributes = ["text", "trusted"]
8 8
 snippets_used = ["external", "button", "alert"]
9 9
 +++
10 10
 
@@ -20,20 +20,30 @@ Basic usage:
20 20
 
21 21
 Shorthand usage:
22 22
 
23
-```
23
+```term
24 24
 {{</* external "https://after-dark.habd.as" "After Dark" /*/>}}
25
-{{</* external "https://go.habd.as/after-dark" /*/>}}
25
+{{</* external href="https://go.habd.as/after-dark" /*/>}}
26 26
 {{</* external "wss://fs1.habd.as:80" /*/>}}
27 27
 ```
28 28
 
29 29
 {{< external "https://after-dark.habd.as" "After Dark" />}}
30
-{{< external "https://go.habd.as/after-dark" />}}
31
-{{< external href="wss://fs1.habd.as:80" />}}
30
+{{< external href="https://go.habd.as/after-dark" />}}
31
+{{< external "wss://fs1.habd.as:80" />}}
32 32
 
33 33
 {{< hackcss-alert type="info" >}}
34 34
 <strong>Note:</strong> URIs such as those using the <code>wss</code> scheme may be considered unsafe by the {{< external "https://golang.org/pkg/html/template/" "Go template package" />}}. Learn more in the package {{< external "https://golang.org/pkg/html/template/#hdr-Security_Model" "Security Model" />}}.
35 35
 {{< /hackcss-alert >}}
36 36
 
37
+With a trusted URL:
38
+
39
+```html
40
+{{</* external trusted="true" href="wss://fs1.habd.as:80" /*/>}}
41
+{{</* external trusted="true" href="irc://chat.freenode.net:6667/after-dark" /*/>}}
42
+```
43
+
44
+{{< external trusted="true" href="wss://fs1.habd.as:80" />}}
45
+{{< external trusted="true" href="irc://chat.freenode.net:6667/after-dark" />}}
46
+
37 47
 With external link styling removed:
38 48
 
39 49
 ```html

+ 1
- 1
layouts/partials/components/external.html View File

@@ -1 +1 @@
1
-<a {{ with .itemtype }} itemprop itemtype="https://schema.org/{{ . }}"{{ end }} target="{{ .target | default "_blank" }}"{{ with .type }} type="{{ . }}"{{ end }}{{ with .title }} title="{{ . }}"{{ end }}{{ with .rel }} rel="{{ . }}"{{ else }} rel="{{ if ne .supress_external true }}external{{ end }} noopener"{{ end }} href="{{ .href }}"{{ with .referrerpolicy }} referrerpolicy="{{ . }}"{{ end }}{{ with .class }} class="{{ . }}"{{ end }}>{{ .body | default (replaceRE "^https?://(.*)" "$1" .href) }}</a>
1
+<a {{ with .itemtype }} itemprop itemtype="https://schema.org/{{ . }}"{{ end }} target="{{ .target | default "_blank" }}"{{ with .type }} type="{{ . }}"{{ end }}{{ with .title }} title="{{ . }}"{{ end }}{{ with .rel }} rel="{{ . }}"{{ else }} rel="{{ if ne .supress_external true }}external{{ end }} noopener"{{ end }}{{ if eq .trusted "true" }} href="{{ .href | safeURL }}"{{ else }} href="{{ .href }}"{{ end }}{{ with .referrerpolicy }} referrerpolicy="{{ . }}"{{ end }}{{ with .class }} class="{{ . }}"{{ end }}>{{ .body | default (replaceRE "^https?://(.*)" "$1" .href) }}</a>

+ 2
- 1
layouts/shortcodes/external.html View File

@@ -7,8 +7,9 @@
7 7
 {{ $type := .Get "type" -}}
8 8
 {{ $rel := .Get "rel" -}}
9 9
 {{ $itemtype := .Get "itemtype" -}}
10
+{{ $trusted := .Get "trusted" -}}
10 11
 {{- if .IsNamedParams -}}
11
-  {{ partial "components/external.html" (dict "href" $href "body" $body "class" $class "referrerpolicy" $referrerpolicy "target" $target "type" $type "title" $title "rel" $rel "itemtype" $itemtype "suppress_external" (and .Inner (eq (len (findRE "external" $rel)) 0))) }}
12
+  {{ partial "components/external.html" (dict "href" $href "body" $body "class" $class "referrerpolicy" $referrerpolicy "target" $target "type" $type "title" $title "rel" $rel "itemtype" $itemtype "trusted" $trusted "suppress_external" (and .Inner (eq (len (findRE "external" $rel)) 0))) }}
12 13
 {{- else if gt (len .Params) 1 -}}
13 14
   {{ partial "components/external.html" (dict "href" (.Get 0) "body" (.Get 1)) }}
14 15
 {{- else -}}

Loading…
Cancel
Save