sigs.k8s.io/kueue@v0.6.2/site/layouts/shortcodes/include.html (about)

     1  
     2  {{/* Handle the "file" and "lang" named parameter or two unnamed parameter as the filepath and coding language*/}}
     3  {{/* The first parameter should be a relative path to the "static" directory. Ex: "examples/jobs/sample-job.yaml" */}}
     4  {{ if .IsNamedParams }}
     5  	{{ $.Scratch.Set "fparameter" ( .Get "file" ) }}
     6    {{ $.Scratch.Set "lang" ( .Get "lang") }}
     7  {{ else }}
     8  	{{ $.Scratch.Set "fparameter" ( .Get 0 ) }}
     9    {{ $.Scratch.Set "lang" ( .Get 1 ) }}
    10  {{ end }}
    11  
    12  {{/* If coding language are specified, then the static file is a code file; If not, then the static are non-code file. */}}
    13  {{ if eq ($.Scratch.Get "lang") "" }}
    14  {{ $.Scratch.Set "iscode" "false"}}
    15  {{ else }}
    16  {{ $.Scratch.Set "iscode" "true" }}
    17  {{ end }}
    18  
    19  {{/* `fparameter is a relative path of the static file from the `static` diretory. For exampl, `/example/python/install-kueue-queues.py` */}}
    20  {{ $.Scratch.Set "filepath" "/" }}
    21  {{ $.Scratch.Add "filepath" "static/" }}
    22  {{ $.Scratch.Add "filepath" ($.Scratch.Get "fparameter") }}
    23  
    24  {{/* If the file exists, read it and highlight it if it's code.
    25  Throw a compile error or print an error on the page if the file is not found */}}
    26  
    27  {{ if fileExists ($.Scratch.Get "filepath") }}
    28    {{ $filename := (path.Split ($.Scratch.Get "filepath")).File }}
    29    {{ $link := printf "/%s"  ($.Scratch.Get "fparameter") | safeURL }}
    30    <div class="highlight">
    31      <a href="{{ $link }}" download="{{ $filename }}" class="d-flex flex-row-reverse p-2"> <button class="btn btn-outline-primary btn-sm position-absolute"> <i class="fa-solid fa-file-arrow-down"></i> {{ $filename }}   </button> </a>
    32    {{ if eq ($.Scratch.Get "iscode") "true" }}
    33      {{- highlight ($.Scratch.Get "filepath" | readFile | htmlUnescape |
    34      safeHTML ) ($.Scratch.Get "lang") "" -}}
    35    {{ else }}
    36      {{- $.Scratch.Get "filepath" | os.ReadFile | .Page.RenderString | safeHTML -}}
    37    {{ end }}
    38   </div> 
    39  {{ else if eq (.Get "draft") "true" }}
    40  
    41    <p style="color: #D74848"><b><i>The file <code>{{ $.Scratch.Get "filepath" }}</code> was not found.</i></b></p> 
    42  
    43  {{ else }}{{- errorf "Shortcode %q: file %q not found at %s" .Name ($.Scratch.Get "filepath") .Position -}}{{ end }}