Skip to content

Commit 9e128e3

Browse files
author
Tim Bannister
committed
Reimplement code_sample shortcode
Use Hugo Pipes for the icon asset pipeline, and avoid inline styling.
1 parent 6908c84 commit 9e128e3

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed
File renamed without changes.

assets/scss/_custom.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,4 +1407,9 @@ div.alert > em.javascript-required {
14071407
cursor: pointer;
14081408
font-size: calc(5vw + 10px);
14091409
color: #333;
1410+
}
1411+
1412+
.code-sample > .copy-code-icon {
1413+
cursor: pointer;
1414+
text-align: right;
14101415
}

layouts/shortcodes/code.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{ $p := .Page }}
22
{{ $file := .Get "file" }}
3-
{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
3+
{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
44
{{ $fileDir := path.Split $file }}
55
{{ $bundlePath := path.Join .Page.File.Dir $fileDir.Dir }}
66
{{ $filename := printf "/content/%s/examples/%s" .Page.Lang $file | safeURL }}
@@ -18,15 +18,16 @@
1818
{{ errorf "[%s] %q not found in %q" site.Language.Lang $fileDir.File $bundlePath }}
1919
{{ end }}
2020
{{ with $.Scratch.Get "content" }}
21-
<div class="highlight">
22-
<div class="copy-code-icon" style="text-align:right">
21+
<div class="highlight code-sample">
22+
<div class="copy-code-icon">
2323
{{ with $ghlink }}<a href="{{ . }}" download="{{ $file }}">{{ end }}<code>{{ $file }}</code>
2424
{{ 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>
25+
{{- with resources.Get "images/copycode.svg" -}}
26+
<img src="{{ .RelPermalink }}" class="icon-copycode" onclick="copyCode('{{ $file | anchorize }}')" title="Copy {{ $file }} to clipboard"></img>
27+
{{- end -}}
2728
</div>
2829
<div class="includecode" id="{{ $file | anchorize }}">
2930
{{- highlight . $codelang "" -}}
3031
</div>
3132
</div>
32-
{{ end }}
33+
{{- end -}}

layouts/shortcodes/code_sample.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{ $p := .Page }}
22
{{ $file := .Get "file" }}
3-
{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
3+
{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
44
{{ $fileDir := path.Split $file }}
55
{{ $bundlePath := path.Join .Page.File.Dir $fileDir.Dir }}
66
{{ $filename := printf "/content/%s/examples/%s" .Page.Lang $file | safeURL }}
@@ -18,15 +18,16 @@
1818
{{ errorf "[%s] %q not found in %q" site.Language.Lang $fileDir.File $bundlePath }}
1919
{{ end }}
2020
{{ with $.Scratch.Get "content" }}
21-
<div class="highlight">
22-
<div class="copy-code-icon" style="text-align:right">
21+
<div class="highlight code-sample">
22+
<div class="copy-code-icon">
2323
{{ with $ghlink }}<a href="{{ . }}" download="{{ $file }}">{{ end }}<code>{{ $file }}</code>
2424
{{ 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>
25+
{{- with resources.Get "images/copycode.svg" -}}
26+
<img src="{{ .RelPermalink }}" class="icon-copycode" onclick="copyCode('{{ $file | anchorize }}')" title="Copy {{ $file }} to clipboard"></img>
27+
{{- end -}}
2728
</div>
2829
<div class="includecode" id="{{ $file | anchorize }}">
2930
{{- highlight . $codelang "" -}}
3031
</div>
3132
</div>
32-
{{ end }}
33+
{{- end -}}

layouts/shortcodes/codenew.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{ $p := .Page }}
22
{{ $file := .Get "file" }}
3-
{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
3+
{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
44
{{ $fileDir := path.Split $file }}
55
{{ $bundlePath := path.Join .Page.File.Dir $fileDir.Dir }}
66
{{ $filename := printf "/content/%s/examples/%s" .Page.Lang $file | safeURL }}
@@ -18,15 +18,16 @@
1818
{{ errorf "[%s] %q not found in %q" site.Language.Lang $fileDir.File $bundlePath }}
1919
{{ end }}
2020
{{ with $.Scratch.Get "content" }}
21-
<div class="highlight">
22-
<div class="copy-code-icon" style="text-align:right">
21+
<div class="highlight code-sample">
22+
<div class="copy-code-icon">
2323
{{ with $ghlink }}<a href="{{ . }}" download="{{ $file }}">{{ end }}<code>{{ $file }}</code>
2424
{{ 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>
25+
{{- with resources.Get "images/copycode.svg" -}}
26+
<img src="{{ .RelPermalink }}" class="icon-copycode" onclick="copyCode('{{ $file | anchorize }}')" title="Copy {{ $file }} to clipboard"></img>
27+
{{- end -}}
2728
</div>
2829
<div class="includecode" id="{{ $file | anchorize }}">
2930
{{- highlight . $codelang "" -}}
3031
</div>
3132
</div>
32-
{{ end }}
33+
{{- end -}}

0 commit comments

Comments
 (0)