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

img.html « gallery « sections « partials « layouts - github.com/kdevo/osprey-delight.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2adc500bf1c4c99cc500d4fa4afefe37bd4cb37f (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{{ $scratch := newScratch }}
{{ $imgSize := default "500x" .Site.Params.Image.Gallery.resize }}
{{ $lqipSize := default "6x" .Site.Params.Image.Gallery.resizeLQIP }}
{{ $useLQIP := default true .Site.Params.Image.Gallery.useLQIP }}
{{ $resizeOptions := default "MitchellNetravali q85" .Site.Params.Image.Gallery.resizeOptions }}
{{ with .Params.image -}}
    {{ with (resources.Get .) -}}
        {{ $image := .Resize (printf "%s %s" $imgSize $resizeOptions) }}
        {{ $scratch.Set "img" $image.Permalink }}
        {{ $scratch.Set "imgW" $image.Width }}
        {{ $scratch.Set "imgH" $image.Height }}

        {{ if $useLQIP -}}
            {{ $lqip := $image }}
            {{ $lqip := $image | images.Filter (images.GaussianBlur 10) }}
            {{ $lqip = $lqip.Resize (printf "%s png" $lqipSize) }}
            {{ $scratch.Set "imgPlaceholderRes" $lqip }}
        {{- end }}
    {{- else -}}
        {{ $scratch.Set "img" (. | absURL) }}
    {{- end }}
{{- else -}}
    {{ with .Params.github.repo -}}
        {{ $scratch.Set "img" ((printf "https://raw.githubusercontent.com/%s/master/.github/logo.png" .) | absURL) }}
    {{ else }}
        {{ warnf "no gallery image set for %s" .File.FileName }}  
    {{- end }}
{{- end }}
{{ if .Site.Params.Feat.useLazySizes }}
<noscript>
    <img
    src="{{ $scratch.Get "img" }}" 
    alt="{{ default .Params.title .Params.alt }}" 
    loading="lazy"
    {{ with $scratch.Get "imgH" -}}
        height="{{ . }}" 
    {{- end }}
    {{ with $scratch.Get "imgW" }}
        width="{{ . }}"
        style="width: {{ . }}px; height: auto;"
    {{ end }}
    >
</noscript>
{{ end }} 
<img 
{{ if .Site.Params.Feat.useLazySizes }}
    {{ with $scratch.Get "imgPlaceholderRes" }}
    {{ $placeholderB64 := .Content | base64Encode }}
        {{ if gt (len $placeholderB64) 3072 -}}
            src="{{ .Permalink }}"
        {{- else -}}
            src="data:image/png;base64,{{ $placeholderB64 }}"
        {{- end }}
    {{- end }}
    data-src="{{ $scratch.Get "img" }}" 
    class="blur-up lazyload"
{{ else }}
    src="{{ $scratch.Get "img" }}"
    loading="lazy"
{{ end }} 
alt="{{ default .Params.title .Params.alt }}" 
{{ with $scratch.Get "imgH" -}} height="{{ . }}" {{- end }}
{{ with $scratch.Get "imgW" }} width="{{ . }}" {{ end }}
{{ with $scratch.Get "imgW" -}}
    {{/* TODO(kdevo): Refactor this in SCSS */}}
    style="width: {{ . }}px; height: auto;"
{{- end }}
>