Merge pull request #46362 from sftim/20240514_redo_code_sample

Redo code_sample shortcode
This commit is contained in:
Kubernetes Prow Robot 2024-05-15 07:19:53 -07:00 committed by GitHub
commit b9475dc06d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 33 additions and 18 deletions

View File

Before

Width:  |  Height:  |  Size: 249 B

After

Width:  |  Height:  |  Size: 249 B

View File

@ -1407,4 +1407,10 @@ div.alert > em.javascript-required {
cursor: pointer;
font-size: calc(5vw + 10px);
color: #333;
}
.code-sample > .copy-code-icon {
cursor: pointer;
text-align: right;
padding: 0.2rem;
}

View File

@ -68,6 +68,9 @@ other = "YouTube"
[conjunction_1]
other = "and"
[copy_sample_to_clipboard]
other = "Copy {{ .filename }} to clipboard"
[cve_id]
other = "CVE ID"

View File

@ -1,6 +1,6 @@
{{ $p := .Page }}
{{ $file := .Get "file" }}
{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
{{ $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 }}
@ -18,15 +18,17 @@
{{ errorf "[%s] %q not found in %q" site.Language.Lang $fileDir.File $bundlePath }}
{{ end }}
{{ with $.Scratch.Get "content" }}
<div class="highlight">
<div class="copy-code-icon" style="text-align:right">
<div class="highlight code-sample">
<div class="copy-code-icon">
{{ with $ghlink }}<a href="{{ . }}" download="{{ $file }}">{{ end }}<code>{{ $file }}</code>
{{ if $ghlink }}</a>{{ end }}
<img src="{{ "images/copycode.svg" | relURL }}" style="max-height:24px; cursor: pointer" onclick="copyCode('{{ $file | anchorize }}')" title="Copy {{ $file }} to clipboard">
</img>
{{- $copyTitle := T "copy_sample_to_clipboard" (dict "filename" $file) -}}
{{- with resources.Get "images/copycode.svg" -}}
<img src="{{ .RelPermalink }}" class="icon-copycode" onclick="copyCode('{{ $file | anchorize }}')" title="{{ $copyTitle }}"></img>
{{- end -}}
</div>
<div class="includecode" id="{{ $file | anchorize }}">
{{- highlight . $codelang "" -}}
</div>
</div>
{{ end }}
{{- end -}}

View File

@ -1,6 +1,6 @@
{{ $p := .Page }}
{{ $file := .Get "file" }}
{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
{{ $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 }}
@ -18,15 +18,17 @@
{{ errorf "[%s] %q not found in %q" site.Language.Lang $fileDir.File $bundlePath }}
{{ end }}
{{ with $.Scratch.Get "content" }}
<div class="highlight">
<div class="copy-code-icon" style="text-align:right">
<div class="highlight code-sample">
<div class="copy-code-icon">
{{ with $ghlink }}<a href="{{ . }}" download="{{ $file }}">{{ end }}<code>{{ $file }}</code>
{{ if $ghlink }}</a>{{ end }}
<img src="{{ "images/copycode.svg" | relURL }}" style="max-height:24px; cursor: pointer" onclick="copyCode('{{ $file | anchorize }}')" title="Copy {{ $file }} to clipboard">
</img>
{{- $copyTitle := T "copy_sample_to_clipboard" (dict "filename" $file) -}}
{{- with resources.Get "images/copycode.svg" -}}
<img src="{{ .RelPermalink }}" class="icon-copycode" onclick="copyCode('{{ $file | anchorize }}')" title="{{ $copyTitle }}"></img>
{{- end -}}
</div>
<div class="includecode" id="{{ $file | anchorize }}">
{{- highlight . $codelang "" -}}
</div>
</div>
{{ end }}
{{- end -}}

View File

@ -1,6 +1,6 @@
{{ $p := .Page }}
{{ $file := .Get "file" }}
{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
{{ $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 }}
@ -18,15 +18,17 @@
{{ errorf "[%s] %q not found in %q" site.Language.Lang $fileDir.File $bundlePath }}
{{ end }}
{{ with $.Scratch.Get "content" }}
<div class="highlight">
<div class="copy-code-icon" style="text-align:right">
<div class="highlight code-sample">
<div class="copy-code-icon">
{{ with $ghlink }}<a href="{{ . }}" download="{{ $file }}">{{ end }}<code>{{ $file }}</code>
{{ if $ghlink }}</a>{{ end }}
<img src="{{ "images/copycode.svg" | relURL }}" style="max-height:24px; cursor: pointer" onclick="copyCode('{{ $file | anchorize }}')" title="Copy {{ $file }} to clipboard">
</img>
{{- $copyTitle := T "copy_sample_to_clipboard" (dict "filename" $file) -}}
{{- with resources.Get "images/copycode.svg" -}}
<img src="{{ .RelPermalink }}" class="icon-copycode" onclick="copyCode('{{ $file | anchorize }}')" title="{{ $copyTitle }}"></img>
{{- end -}}
</div>
<div class="includecode" id="{{ $file | anchorize }}">
{{- highlight . $codelang "" -}}
</div>
</div>
{{ end }}
{{- end -}}