File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 5
5
<!-- scripts for algolia docsearch -->
6
6
{{ end }}
7
7
{{/* copy-and-paste helper for codenew shortcode */}}
8
- {{- if or (.HasShortcode "code") (.HasShortcode "codenew") -}}
8
+ {{- if or (.HasShortcode "code_sample") (.HasShortcode " code") (.HasShortcode "codenew") -}}
9
9
< script async src ="{{ "js /sweetalert-2.1.2.min.js" | relURL }}"> </ script >
10
10
< script type ="text/javascript ">
11
11
function copyCode ( elem ) {
Original file line number Diff line number Diff line change
1
+ {{ $p := .Page }}
2
+ {{ $file := .Get "file" }}
3
+ {{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
4
+ {{ $fileDir := path.Split $file }}
5
+ {{ $bundlePath := path.Join .Page.File.Dir $fileDir.Dir }}
6
+ {{ $filename := printf "/content/%s/examples/%s" .Page.Lang $file | safeURL }}
7
+ {{ $ghlink := printf "https://%s/%s%s" site.Params.githubwebsiteraw (default "main" site.Params.docsbranch) $filename | safeURL }}
8
+ {{/* First assume this is a bundle and the file is inside it. */}}
9
+ {{ $resource := $p.Resources.GetMatch (printf "%s*" $file ) }}
10
+ {{ with $resource }}
11
+ {{ $.Scratch.Set "content" .Content }}
12
+ {{ else }}
13
+ {{/* Read the file relative to the content root. */}}
14
+ {{ $resource := readFile $filename}}
15
+ {{ with $resource }}{{ $.Scratch.Set "content" . }}{{ end }}
16
+ {{ end }}
17
+ {{ if not ($.Scratch.Get "content") }}
18
+ {{ errorf "[%s] %q not found in %q" site.Language.Lang $fileDir.File $bundlePath }}
19
+ {{ end }}
20
+ {{ with $.Scratch.Get "content" }}
21
+ < div class ="highlight ">
22
+ < div class ="copy-code-icon " style ="text-align:right ">
23
+ {{ with $ghlink }}< a href ="{{ . }} " download ="{{ $file }} "> {{ end }}< code > {{ $file }}</ code >
24
+ {{ if $ghlink }}</ a > {{ end }}
25
+ < img src ="{{ "images /copycode.svg" | relURL }}" style="max-height:24px; cursor: pointer " onclick ="copyCode('{{ $file | anchorize }}') " title ="Copy {{ $file }} to clipboard ">
26
+ </ img >
27
+ </ div >
28
+ < div class ="includecode " id ="{{ $file | anchorize }} ">
29
+ {{- highlight . $codelang "" -}}
30
+ </ div >
31
+ </ div >
32
+ {{ end }}
You can’t perform that action at this time.
0 commit comments