Welcome to mirror list, hosted at ThFree Co, Russian Federation.

highlightfile.html « shortcodes « layouts - github.com/it-gro/hugo-theme-w3css-basic.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 20bb0af85f329b0a91a49e6dba82509fef581537 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!--
Highlights file and provides download link.
File should be located either in the same directory or full path should be specified.
-->

{{- $src   := .Get "file"                                 }}
{{- $lang  := .Get "language" | default ("python")        }}
{{- $opt   := .Get "opt"      | default ("linenos=table") }}
{{- $theme := .Get "theme"    | default ("")              }}

{{- if eq $theme "default" -}}
  {{ $theme = (default "w3-theme-l3" ($.Site.Param `colorShortcodeHighlightfile`) ) }}
{{- end -}}

{{- if in $theme "w3-theme" -}}
 <div class="w3-container {{ $theme }}" >
{{- end -}}

{{- if in $src "/" -}}
  {{ $filelink := (strings.TrimPrefix "/static" $src ) }}
  {{ $justTheSplit := split $filelink "/" }}
  {{ $lastPartOnly := index (last 1 $justTheSplit) 0}}

  {{/* <a class="linktofile" href="{{ .Site.BaseURL }}/{{ $filelink }}"/> */}}
  {{/* <a class="linktofile" href="{{ $filelink | absURL }}"/> */}}
  <a class="linktofile" href="{{ cond (eq (len .Site.BaseURL) 0) ($filelink | absURL) (printf `%s/%s` .Site.BaseURL $filelink)}}"/>
      {{  $lastPartOnly }}
  </a>

  {{$file := $src | readFile}}
  {{/* {{ highlight (print $file) $lang $opt}} */}}
  {{/* highlight ($file | replaceRE `\r` ``) $lang $opt */}}
  {{ highlight ( trim (readFile $src | replaceRE "\r\n" "\n") "\n") $lang $opt }}

{{- else -}}
  {{ $file := (printf "%s%s" $.Page.File.Dir $src) }}

  {{/* <a class="linktofile" href="{{ .Site.BaseURL }}/{{ $file }}"/> */}}
  {{/* <a class="linktofile" href="{{ $file | absURL }}"/> */}}
  <a class="linktofile" href="{{ cond (eq (len .Site.BaseURL) 0) ($file | absURL) (printf `%s/%s` .Site.BaseURL $file)}}"/>
      {{  $src }}
  </a>

  {{ highlight (trim (readFile (printf "content/%s" $file)) "\n") $lang $opt}}

{{- end -}}

{{- if in $theme "w3-theme" -}}
 </div>
{{- end -}}