aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/_default/_markup
diff options
context:
space:
mode:
Diffstat (limited to 'themes/default/layouts/_default/_markup')
-rw-r--r--themes/default/layouts/_default/_markup/render-codeblock-mathml.html18
-rw-r--r--themes/default/layouts/_default/_markup/render-codeblock.html28
-rw-r--r--themes/default/layouts/_default/_markup/render-heading.html11
-rw-r--r--themes/default/layouts/_default/_markup/render-image.html145
-rw-r--r--themes/default/layouts/_default/_markup/render-link.html38
5 files changed, 147 insertions, 93 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 f5c0e13..ab9a786 100644
--- a/themes/default/layouts/_default/_markup/render-codeblock.html
+++ b/themes/default/layouts/_default/_markup/render-codeblock.html
@@ -1,19 +1,25 @@
-{{ $options := .Attributes.options | default "default=1" }}
-{{ $caption := .Attributes.caption }}
+{{- $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 {{ if in (lower $options) "linenos" }}data-lines{{ end }}>
+<code-block id="{{ $id }}" {{ if in (lower $options) "linenos" }}data-lines=""{{ end }}>
<header>
<language-label>
- {{ .Type }}
+ <a href="#{{ $id }}">{{ $type }}</a>
</language-label>
- <button>
- {{ safeHTML (readFile (print (partial "function-paths-static.html") "/icons/feather/copy.svg")) }}
- <span>Copy</span>
- </button>
</header>
- {{ highlight .Inner .Type (print $options ",lineAnchors=" "code-" (truncate 7 "" (md5 .Inner))) }}
+ <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 0cf1d5a..04bf931 100644
--- a/themes/default/layouts/_default/_markup/render-image.html
+++ b/themes/default/layouts/_default/_markup/render-image.html
@@ -1,93 +1,110 @@
-{{- $source := $.Destination | safeURL -}}
-{{- $public := print "public/" $source -}}
-{{- $local := "" -}}
-{{- $cache := "" -}}
-{{- $exists := "" -}}
-{{- $width := "" -}}
-{{- $height := "" -}}
-{{- $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-media.html") "/" $author "/" $immutable -}}
+{{- $cache := "" -}}
+{{- $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 "") -}}
+{{- $storage := print $author "/media/" $immutable -}}
+{{- $cached := fileExists (print "public/" $storage ".webp") -}}
-{{- if not (or (fileExists (print "public/" $fileCache ".webp")) (fileExists (print "public/" $fileCache (path.Ext $source)))) -}}
- {{- with $remote := resources.GetRemote $source -}}
+{{- $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 $fetch) -}}
{{- with .Err -}}
{{- if fileExists $public -}}
- {{- $local = resources.Get $public -}}
- {{- with $local -}}
- {{- $local = .Content | resources.FromString (print (partial "function-paths-media.html") "/" $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.RelPermalink -}}
{{- end -}}
{{- else -}}
- {{- $cache = .Content | resources.FromString (print (partial "function-paths-media.html") "/" $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-media.html") "/" $author "/" (path.Base $exists)) -}}
+ {{- 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 -}}
+ {{- range $extension := $fallbacks -}}
+ {{- with resources.Get (print "public/" $storage $extension) -}}
+ {{- $cache = print ("" | absURL) "/" $storage $extension -}}
+ {{- break -}}
+ {{- end -}}
+ {{- end -}}
+{{- end -}}
+
+{{- if lt $width $height -}}
+ {{- $orientation = "portrait" -}}
+{{- end -}}
+
+{{- with $caption := $.Title -}}
+ {{- $figcaption = $caption | markdownify -}}
{{ end }}
{{- /* This comment removes trailing newlines and white spaces. */ -}}
<figure>
- <a href="{{ $source }}">
+ <a data-orientation="{{ $orientation }}" href="{{ $source }}">
<picture>
- {{- with $local }}
- {{- $local = .Fit (print $dimensions " webp") }}
- {{- $local = $local | resources.Copy (print (partial "function-paths-media.html") "/" $author "/" $immutable ".webp") }}
- <source srcset="{{- $local.RelPermalink -}}" type="image/webp" />
- {{- $local = .Fit $dimensions }}
- {{- $local = $local | resources.Copy (print (partial "function-paths-media.html") "/" $author "/" $immutable (path.Ext $local)) }}
- {{- $width = $local.Width -}}
- {{- $height = $local.Height -}}
- {{- $writeToFile := $local.Permalink }}
+ {{- with $srcset }}
+ <source srcset="{{ $srcset }}" type="{{ or $type "image/webp" }}" />
{{- end }}
- {{- with $cache }}
- {{- $cache = .Fit (print $dimensions " webp") }}
- {{- $cache = $cache | resources.Copy (print $author "/media/" $immutable ".webp") }}
- <source srcset="{{- $cache.RelPermalink -}}" type="image/webp" />
- {{- $cache = .Fit $dimensions }}
- {{- $cache = $cache | resources.Copy (print (partial "function-paths-media.html") "/" $author "/" $immutable (path.Ext $cache)) }}
- {{- $width = $cache.Width -}}
- {{- $height = $cache.Height -}}
- {{- $cache = $cache.RelPermalink }}
- {{- end -}}
- {{- with $exists }}
- {{- if fileExists (print "public/" $fileCache ".webp") -}}
- <source srcset="/{{- print $fileCache ".webp" -}}" type="image/webp" />
- {{- end -}}
- {{- if fileExists (print "public/" $author "/media/" $immutable ".webp") -}}
- <source srcset="/{{- print $author "/media/" $immutable ".webp" -}}" type="image/webp" />
- {{- end -}}
- {{- $width = .Width -}}
- {{- $height = .Height -}}
- {{- $cache = .RelPermalink }}
- {{- end -}}
- <img loading="lazy"
+ <img
+ loading="lazy"
src="{{ or $cache $source }}"
alt="{{ $.Text | htmlUnescape }}"
title="{{ $.Text | htmlUnescape }}"
width="{{ $width }}"
height="{{ $height }}"
+ {{ printf `style="` | safeHTMLAttr -}}
+ {{- partial "image-gradient.css.html" $colors | safeHTMLAttr -}}
+ {{- printf `"` | safeHTMLAttr }}
/>
</picture>
</a>
<figcaption>
- {{ with $.Title -}}
- {{ . | markdownify }}
- {{ else -}}
- Image/Picture
- {{ end -}}
- <br>
- Index: {{ with $cache }} {{ print "[Cache](" . ")" | markdownify }} &middot; {{ end }}
+ {{ $figcaption }}
+ <br />
+ Index: {{ with $cache }} {{ print "[Cache](" $cache ")" | markdownify }} &middot; {{ end }}
{{ print "[Source](" $source ")" | markdownify }}
</figcaption>
</figure>
diff --git a/themes/default/layouts/_default/_markup/render-link.html b/themes/default/layouts/_default/_markup/render-link.html
index 17a6f2c..ccfbc06 100644
--- a/themes/default/layouts/_default/_markup/render-link.html
+++ b/themes/default/layouts/_default/_markup/render-link.html
@@ -1,21 +1,31 @@
{{- $link := .Destination -}}
-{{ $isRemote := strings.HasPrefix $link "http" }}
-{{- if not $isRemote -}}
-{{ $url := urls.Parse .Destination }}
-{{- if $url.Path -}}
-{{ $fragment := "" }}
-{{- with $url.Fragment }}{{ $fragment = printf "#%s" . }}{{ end -}}
-{{- with .Page.GetPage $url.Path }}{{ $link = printf "%s%s" .Permalink $fragment }}{{ end }}{{ end -}}
+{{- $url := urls.Parse $link -}}
+{{- $site := urls.Parse .Page.Site.BaseURL -}}
+{{- $local := or (eq $url.Host $site.Host) (strings.HasPrefix $link "/") -}}
+{{- $remote := not $local -}}
+
+{{- if and $local $url.Path -}}
+
+{{- $fragment := "" -}}
+
+ {{- with $url.Fragment -}}
+ {{- $fragment = printf "#%s" . -}}
+ {{- end -}}
+
+ {{- with .Page.GetPage $url.Path -}}
+ {{- $link = printf "%s%s" .Permalink $fragment -}}
+ {{- end -}}
+
{{- end -}}
+
<a
+ {{- if $remote }}
+ rel="noopener no-referrer"
+ {{- else }}
+ data-internal=""
+ {{- end }}
href="{{ $link | safeURL }}"
{{ with or .Title ($link | safeURL) -}}
title="{{ . }}"
- {{ end }}
- {{- if $isRemote -}}
- target="_blank"
- rel="noopener no-referrer"
- {{ end }}>
- {{- .Text | safeHTML -}}
-</a>
+ {{ end }}>{{ .Text | safeHTML }}</a>
{{- /* This comment removes trailing newlines and white spaces. */ -}}