Skip to content

Commit e38d549

Browse files
author
Tim Bannister
committed
Add shortcode for hyperlinking to examples
1 parent 3ca34b9 commit e38d549

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

layouts/shortcodes/example.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{ $file := .Get "file" }}
2+
{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
3+
{{ $fileDir := path.Split $file }}
4+
{{ $bundlePath := path.Join .Page.File.Dir $fileDir.Dir }}
5+
{{ $filename := printf "/content/%s/examples/%s" .Page.Lang $file | safeURL }}
6+
{{ $ghlink := printf "https://%s/%s%s" site.Params.githubwebsiteraw (default "main" (site.Params.github_branch)) $filename | safeURL }}
7+
8+
<a href="{{ $ghlink }}" download="{{ $file }}">
9+
{{- if gt (len .Inner) 0 -}}
10+
{{- .Inner -}}
11+
{{- else -}}
12+
{{- $file -}}
13+
{{- end -}}
14+
</a>

0 commit comments

Comments
 (0)