Skip to content

Commit b9475dc

Browse files
authored
Merge pull request #46362 from sftim/20240514_redo_code_sample
Redo code_sample shortcode
2 parents d4b0776 + e2d9c4f commit b9475dc

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed
File renamed without changes.

assets/scss/_custom.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,4 +1407,10 @@ 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;
1415+
padding: 0.2rem;
14101416
}

data/i18n/en/en.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ other = "YouTube"
6868
[conjunction_1]
6969
other = "and"
7070

71+
[copy_sample_to_clipboard]
72+
other = "Copy {{ .filename }} to clipboard"
73+
7174
[cve_id]
7275
other = "CVE ID"
7376

layouts/shortcodes/code.html

Lines changed: 8 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,17 @@
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+
{{- $copyTitle := T "copy_sample_to_clipboard" (dict "filename" $file) -}}
26+
{{- with resources.Get "images/copycode.svg" -}}
27+
<img src="{{ .RelPermalink }}" class="icon-copycode" onclick="copyCode('{{ $file | anchorize }}')" title="{{ $copyTitle }}"></img>
28+
{{- end -}}
2729
</div>
2830
<div class="includecode" id="{{ $file | anchorize }}">
2931
{{- highlight . $codelang "" -}}
3032
</div>
3133
</div>
32-
{{ end }}
34+
{{- end -}}

layouts/shortcodes/code_sample.html

Lines changed: 8 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,17 @@
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+
{{- $copyTitle := T "copy_sample_to_clipboard" (dict "filename" $file) -}}
26+
{{- with resources.Get "images/copycode.svg" -}}
27+
<img src="{{ .RelPermalink }}" class="icon-copycode" onclick="copyCode('{{ $file | anchorize }}')" title="{{ $copyTitle }}"></img>
28+
{{- end -}}
2729
</div>
2830
<div class="includecode" id="{{ $file | anchorize }}">
2931
{{- highlight . $codelang "" -}}
3032
</div>
3133
</div>
32-
{{ end }}
34+
{{- end -}}

layouts/shortcodes/codenew.html

Lines changed: 8 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,17 @@
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+
{{- $copyTitle := T "copy_sample_to_clipboard" (dict "filename" $file) -}}
26+
{{- with resources.Get "images/copycode.svg" -}}
27+
<img src="{{ .RelPermalink }}" class="icon-copycode" onclick="copyCode('{{ $file | anchorize }}')" title="{{ $copyTitle }}"></img>
28+
{{- end -}}
2729
</div>
2830
<div class="includecode" id="{{ $file | anchorize }}">
2931
{{- highlight . $codelang "" -}}
3032
</div>
3133
</div>
32-
{{ end }}
34+
{{- end -}}

0 commit comments

Comments
 (0)