Add shortcode for hyperlinking to examples

pull/28464/head
Tim Bannister 2021-06-17 19:44:09 +01:00
parent 3ca34b9a3b
commit e38d549721
1 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,14 @@
{{ $file := .Get "file" }}
{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
{{ $fileDir := path.Split $file }}
{{ $bundlePath := path.Join .Page.File.Dir $fileDir.Dir }}
{{ $filename := printf "/content/%s/examples/%s" .Page.Lang $file | safeURL }}
{{ $ghlink := printf "https://%s/%s%s" site.Params.githubwebsiteraw (default "main" (site.Params.github_branch)) $filename | safeURL }}
<a href="{{ $ghlink }}" download="{{ $file }}">
{{- if gt (len .Inner) 0 -}}
{{- .Inner -}}
{{- else -}}
{{- $file -}}
{{- end -}}
</a>