diff options
Diffstat (limited to 'themes/default/layouts/_default/_markup')
4 files changed, 92 insertions, 73 deletions
diff --git a/themes/default/layouts/_default/_markup/render-codeblock-mathml.html b/themes/default/layouts/_default/_markup/render-codeblock-mathml.html new file mode 100644 index 0000000..f6e5b61 --- /dev/null +++ b/themes/default/layouts/_default/_markup/render-codeblock-mathml.html @@ -0,0 +1,18 @@ +{{- $caption := default "Math Render" .Attributes.caption -}} +{{- $ordinal := add .Ordinal 1 -}} +{{- $hash := print (truncate 3 "" (sha256 .Inner)) (truncate 3 "" (sha256 .Page.RelPermalink)) "-" $ordinal -}} +{{- $id := print "math:" $hash | safeURL -}} + +<math-ml> + <figure id="{{ $id }}"> + <figure> + {{- with $math := .Inner -}} + {{- $math | safeHTML -}} + {{- end -}} + </figure> + <figcaption> + <a href="#{{ $id }}">({{ $ordinal }})</a> + {{ $caption | markdownify }} + </figcaption> + </figure> +</math-ml> diff --git a/themes/default/layouts/_default/_markup/render-codeblock.html b/themes/default/layouts/_default/_markup/render-codeblock.html index f18f0d3..ab9a786 100644 --- a/themes/default/layouts/_default/_markup/render-codeblock.html +++ b/themes/default/layouts/_default/_markup/render-codeblock.html @@ -1,22 +1,25 @@ -{{- $caption := .Attributes.caption -}} -{{- $type := .Type | default "text" -}} -{{- $options := .Attributes.options | default "default=1" -}} -{{- $hash := print (truncate 8 "" (sha256 .Inner)) .Ordinal -}} -{{- $id := print "code-block-" $hash -}} +{{- $caption := .Attributes.caption -}} +{{- $type := .Type | default "text" -}} +{{- $options := .Attributes.options | default "default=1" -}} +{{- $hash := print (truncate 3 "" (sha256 .Inner)) (truncate 3 "" (sha256 .Page.RelPermalink)) .Ordinal -}} +{{- $id := print "code-block:" $hash | safeURL -}} +{{- $highlight := highlight .Inner $type (print $options ",lineAnchors=" "code-line:" $hash) -}} <code-block id="{{ $id }}" {{ if in (lower $options) "linenos" }}data-lines=""{{ end }}> <header> <language-label> <a href="#{{ $id }}">{{ $type }}</a> </language-label> - <button hidden=""> - {{ safeHTML (readFile (print (partial "function-paths.html").static "/icons/feather/copy.svg")) }} - <span>Copy</span> - </button> </header> - {{ highlight .Inner $type (print $options ",lineAnchors=" "code-line-" $hash) }} + <code-content contenteditable="true" spellcheck="false"> + {{- replace $highlight + `class="lnlinks"` + `contenteditable="false" class="lnlinks"` + | safeHTML + -}} + </code-content> </code-block> -{{ with $caption }} +{{- with $caption -}} <footer>{{ . | markdownify }}</footer> -{{ end }} +{{- end -}} diff --git a/themes/default/layouts/_default/_markup/render-heading.html b/themes/default/layouts/_default/_markup/render-heading.html index 37eddb2..86b8e35 100644 --- a/themes/default/layouts/_default/_markup/render-heading.html +++ b/themes/default/layouts/_default/_markup/render-heading.html @@ -1,6 +1,9 @@ -<h{{ .Level }} id="{{ .Anchor | safeURL }}"> - <a - title="{{ .Text | safeHTML }}" - href="#{{ .Anchor | safeURL }}">{{ .Text | safeHTML }} +{{- $text := .Text -}} +{{- $hash := print (truncate 2 "" (sha256 .Page.RelPermalink)) (truncate 2 "" (sha256 $text)) -}} +{{- $id := print "heading:" $hash ":" .Anchor -}} + +<h{{ .Level }} id="{{ $id | safeURL }}"> + <a title="{{ $text | safeHTML }}" href="#{{ $id | safeURL }}"> + {{ $text | safeHTML }} </a> </h{{ .Level }}> diff --git a/themes/default/layouts/_default/_markup/render-image.html b/themes/default/layouts/_default/_markup/render-image.html index b98efdf..04bf931 100644 --- a/themes/default/layouts/_default/_markup/render-image.html +++ b/themes/default/layouts/_default/_markup/render-image.html @@ -1,97 +1,92 @@ -{{- $source := $.Destination | safeURL -}} -{{- $public := print "public/" $source -}} -{{- $local := "" -}} {{- $cache := "" -}} -{{- $exists := "" -}} {{- $width := "" -}} {{- $height := "" -}} {{- $srcset := "" -}} {{- $colors := "" -}} +{{- $type := "" -}} +{{- $source := $.Destination | safeURL -}} +{{- $public := print "public/" $source -}} +{{- $fetch := print (urls.Parse $source).Scheme "://" (urls.Parse $source).Host (urls.Parse $source).RequestURI -}} {{- $figcaption := "Image/Picture" -}} {{- $orientation := "landscape" -}} {{- $dimensions := "600x360" -}} {{- $author := .Page.Section -}} {{- $relURL := strings.TrimPrefix .Page.Site.BaseURL .Page.Permalink -}} {{- $immutable := print ($relURL | humanize | urlize) "-" ($source | sha256 | truncate 8 "") -}} -{{- $fileCache := print (partial "function-paths.html").media "/" $author "/" $immutable -}} -{{- $cached := and (fileExists (print "public/" $fileCache ".webp")) (fileExists (print "public/" $fileCache (path.Ext $source))) -}} +{{- $storage := print $author "/media/" $immutable -}} +{{- $cached := fileExists (print "public/" $storage ".webp") -}} + +{{- $moderns := slice ".webp" ".avif" -}} +{{- $fallbacks := slice ".png" ".jpg" ".gif" ".jpeg" ".svg" ".apng" ".jfif" ".pjpeg" ".pjp" -}} +{{- $mimes := slice "image/avif" "image/webp" "image/apng" "image/gif" "image/jpeg" "image/png" "image/svg+xml" -}} {{- if not $cached -}} - {{- with $remote := cond (default true $.Page.Site.Params.site.offline) false (resources.GetRemote $source) -}} + {{- with $remote := cond (default true $.Page.Site.Params.site.offline) false (resources.GetRemote $fetch) -}} {{- with .Err -}} {{- if fileExists $public -}} - {{- $local = resources.Get $public -}} - {{- with $local -}} - {{- $local = .Content | resources.FromString (print (partial "function-paths.html").media "/" $author "/" (path.Base .)) -}} + {{- with $local := resources.Get $public -}} + {{- $local = .Content | resources.FromString (print $storage (path.Base .)) -}} + {{- $local = .Fit (print $dimensions " webp") -}} + {{- $local = $local | resources.Copy (print $storage ".webp") -}} + {{- $srcset = $local.Permalink -}} + {{- $local = .Fit $dimensions -}} + {{- $local = $local | resources.Copy (print $storage (path.Ext $local)) -}} + {{- $width = $local.Width -}} + {{- $height = $local.Height -}} + {{- $colors = $local.Colors -}} + {{- $cache = $local.Permalink -}} {{- end -}} {{- $source = print ("" | absURL) $source -}} {{- else -}} - {{- $404image := resources.Get "data/media/404.png" -}} - {{- with $404image -}} - {{- $width = .Width -}} - {{- $height = .Height -}} + {{- with $404image := resources.Get "data/media/404.png" -}} + {{- $width = $404image.Width -}} + {{- $height = $404image.Height -}} + {{- $source = $404image.Permalink -}} {{- end -}} - {{- $source = $404image.Permalink -}} {{- end -}} {{- else -}} - {{- $cache = .Content | resources.FromString (print (partial "function-paths.html").media "/" $author "/" (path.Base .)) -}} + {{- with $cache = $remote.Content | resources.FromString (print $storage (path.Base $remote)) -}} + {{- $cache = .Fit (print $dimensions " webp") -}} + {{- $cache = $cache | resources.Copy (print $storage ".webp") -}} + {{- $srcset = $cache.Permalink -}} + {{- $cache = .Fit $dimensions -}} + {{- $cache = $cache | resources.Copy (print $storage (path.Ext $cache)) -}} + {{- $width = $cache.Width -}} + {{- $height = $cache.Height -}} + {{- $colors = $cache.Colors -}} + {{- $cache = $cache.Permalink -}} + {{- end -}} {{- end -}} {{- end -}} {{- else -}} - {{- $exists = resources.Get (print "public/" $fileCache (path.Ext $source)) -}} - {{- $exists = $exists.Content | resources.FromString (print (partial "function-paths.html").media "/" $author "/" (path.Base $exists)) -}} -{{- end -}} - -{{- with $local }} - {{- $local = .Fit (print $dimensions " webp") }} - {{- $local = $local | resources.Copy (print (partial "function-paths.html").media "/" $author "/" $immutable ".webp") }} - {{- $srcset = $local.Permalink -}} - {{- $local = .Fit $dimensions }} - {{- $local = $local | resources.Copy (print (partial "function-paths.html").media "/" $author "/" $immutable (path.Ext $local)) }} - {{- $width = $local.Width -}} - {{- $height = $local.Height -}} - {{- $colors = $local.Colors -}} - {{- $writeToFile := $local.Permalink }} -{{- end }} - -{{- with $cache }} - {{- $cache = .Fit (print $dimensions " webp") }} - {{- $cache = $cache | resources.Copy (print $author "/media/" $immutable ".webp") }} - {{- $srcset = $cache.Permalink -}} - {{- $cache = .Fit $dimensions }} - {{- $cache = $cache | resources.Copy (print (partial "function-paths.html").media "/" $author "/" $immutable (path.Ext $cache)) }} - {{- $width = $cache.Width -}} - {{- $height = $cache.Height -}} - {{- $colors = $cache.Colors -}} - {{- $cache = $cache.Permalink }} -{{- end -}} - -{{- with $exists }} - {{- if fileExists (print "public/" $fileCache ".webp") -}} - {{- $srcset = print "/" $fileCache ".webp" -}} + {{- with $cache = resources.Get (print "public/" $storage ".webp") -}} + {{- $width = $cache.Width -}} + {{- $height = $cache.Height -}} + {{- $colors = $cache.Colors -}} + {{- $type = $cache.MediaType -}} + {{- $srcset = print ("" | absURL) "/" $storage ".webp" -}} {{- end -}} - {{- if fileExists (print "public/" $author "/media/" $immutable ".webp") -}} - {{- $srcset = print "/" $author "/media/" $immutable ".webp" -}} + {{- range $extension := $fallbacks -}} + {{- with resources.Get (print "public/" $storage $extension) -}} + {{- $cache = print ("" | absURL) "/" $storage $extension -}} + {{- break -}} + {{- end -}} {{- end -}} - {{- $width = .Width -}} - {{- $height = .Height -}} - {{- $colors = .Colors -}} - {{- $cache = .Permalink }} {{- end -}} {{- if lt $width $height -}} {{- $orientation = "portrait" -}} {{- end -}} -{{- with $.Title -}} - {{- $figcaption = . | markdownify -}} +{{- with $caption := $.Title -}} + {{- $figcaption = $caption | markdownify -}} {{ end }} {{- /* This comment removes trailing newlines and white spaces. */ -}} <figure> <a data-orientation="{{ $orientation }}" href="{{ $source }}"> <picture> {{- with $srcset }} - <source srcset="{{ $srcset }}" type="image/webp" /> + <source srcset="{{ $srcset }}" type="{{ or $type "image/webp" }}" /> {{- end }} <img loading="lazy" @@ -101,7 +96,7 @@ width="{{ $width }}" height="{{ $height }}" {{ printf `style="` | safeHTMLAttr -}} - {{- partial "styles-image-gradient.html" $colors | safeHTMLAttr -}} + {{- partial "image-gradient.css.html" $colors | safeHTMLAttr -}} {{- printf `"` | safeHTMLAttr }} /> </picture> |