From ed28f5f8438bed6e9c8d0e1e27399927c95a1c0e Mon Sep 17 00:00:00 2001 From: Morgan Gangwere Date: Tue, 26 Dec 2023 01:12:10 -0800 Subject: [PATCH 1/4] Begin fixing landing customization There is a surprising amount of content that depends on `$.Site.Data.landing`. This is bad and should be removed or made to use something default-but-changeable This changeset does exactly that. I've also reworked the way that iamge compare is checked for, which makes it possible to use it in the body content as well later as a shortcode. This also begins the process of making all scripts fingerprintable for SRI. --- data/{landing.yaml => landing_default.yaml} | 0 layouts/_default/baseof.html | 41 +++++++++------------ layouts/index.html | 9 ++++- layouts/partials/landing/feature_grid.html | 2 +- layouts/partials/landing/hero.html | 4 +- layouts/partials/landing/image_compare.html | 9 +++-- layouts/partials/landing/image_text.html | 4 +- 7 files changed, 34 insertions(+), 35 deletions(-) rename data/{landing.yaml => landing_default.yaml} (100%) diff --git a/data/landing.yaml b/data/landing_default.yaml similarity index 100% rename from data/landing.yaml rename to data/landing_default.yaml diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 1f8aa7e2..5e17f43d 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,31 +1,19 @@ -{{ $.Scratch.Delete "social_list" }} +{{ $.Scratch.Delete "social_list" -}} -{{ $social_params := slice "github" "twitter" "instagram" "rss" }} -{{ range $social_params }} +{{- $social_params := slice "github" "twitter" "instagram" "rss" -}} +{{- range $social_params -}} {{ if isset site.Params.social . }} {{ $.Scratch.Add "social_list" (slice .) }} {{ end }} -{{ end }} +{{- end -}} -{{ $ic := newScratch }} -{{ range $value := .Site.Data.landing }} - {{ $template := string (replaceRE `( |-{1,})` "_" $value.template) }} - {{ if eq $template "image_compare" }} - {{ if $value.enable }} - {{ $ic.Add "enabled" (slice $value.enable) }} - {{ range $value.items }} - {{ $ic.Add "config" (slice (.config | jsonify | safeJS)) }} - {{ end }} - {{ end }} - {{- end }} -{{ end }} - -{{ $.Scratch.Set "image_compare_enabled" (in ($ic.Get "enabled") true) }} +{{$.Page.Scratch.Set "image_compare_config" (slice ) }} +{{$.Page.Scratch.Set "image_compare_used" false }} {{- partial "head.html" . -}} @@ -47,16 +35,21 @@ {{- $js := (slice $app) | resources.Concat "/js/bundle.js" }} {{- end }} - - {{ if ($.Scratch.Get "image_compare_enabled") }} + {{ if (default false ($.Scratch.Get "image_compare_used")) }} + {{ $imagecompare := resources.Get "js/image-compare-viewer.min.js" }} + {{- if not .Site.IsServer }} + {{- $js := (slice $imagecompare) | resources.Concat "/js/image-compare.js" | minify | fingerprint "sha384" }} + + {{- else }} + {{- $js := (slice $imagecompare) | resources.Concat "/js/image-compare.js" }} + + {{- end }} + {{ end }} diff --git a/layouts/index.html b/layouts/index.html index 76b71a33..8d843507 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -1,5 +1,8 @@ {{ define "main" }} - {{ $landingData := .Site.Data.landing }} + + {{ $landingData := (default .Site.Data.landing_default .Site.Data.landing) }} + + {{ $map := newScratch }} {{ range $key, $value := $landingData }} @@ -11,14 +14,16 @@ "weight" $weight "template" $template "sectionTitle" $sectionTitle + "data" $value )}} {{ end }} {{ end }} {{ range sort ($map.Get "wgtTpl") ".weight" }} + {{ $.Scratch.Set "sectionTitle" .sectionTitle }} {{ $path := printf "landing/%s.html" .template }} - {{ partial $path $.Page }} + {{ partial $path . }} {{ end }} {{/* printf "%s" (sort ($map.Get "wgtTpl") ".weight" ) */}} {{ end }} \ No newline at end of file diff --git a/layouts/partials/landing/feature_grid.html b/layouts/partials/landing/feature_grid.html index 9449f34f..d037b491 100644 --- a/layouts/partials/landing/feature_grid.html +++ b/layouts/partials/landing/feature_grid.html @@ -1,5 +1,5 @@ {{ $sectionTitle := .Scratch.Get "sectionTitle" }} -{{ with (index .Site.Data.landing $sectionTitle) }} +{{with .data}} {{ if eq .enable true }}
diff --git a/layouts/partials/landing/hero.html b/layouts/partials/landing/hero.html index 5e95f83b..c711fc1a 100644 --- a/layouts/partials/landing/hero.html +++ b/layouts/partials/landing/hero.html @@ -1,5 +1,5 @@ {{ $sectionTitle := .Scratch.Get "sectionTitle" }} -{{ with (index .Site.Data.landing $sectionTitle) }} +{{ with .data }} {{ if eq .enable true }} {{ with .backgroundImage }} @@ -62,7 +62,7 @@

{{ with .ctaButton }} - + {{ with .icon }} {{ . }} {{ end }} diff --git a/layouts/partials/landing/image_compare.html b/layouts/partials/landing/image_compare.html index afbf57b5..874fcbb2 100644 --- a/layouts/partials/landing/image_compare.html +++ b/layouts/partials/landing/image_compare.html @@ -1,6 +1,5 @@ -{{ $sectionTitle := .Scratch.Get "sectionTitle" }} -{{ with (index .Site.Data.landing $sectionTitle) }} -{{ if eq .enable true }} +{{- $sectionTitle := .sectionTitle }}{{ with .data }}{{ if eq .enable true }} +{{- page.Scratch.Set "image_compare_used" true -}} {{- page.Scratch.Add "imageCompareConfig" (slice (.config | jsonify | safeJS)) -}}
@@ -39,6 +38,7 @@

{{ . }}

+ {{ $icc := (default nil .config ) }} {{ $title := .title }} {{ $path := .imagePath | default "images" }} {{ $imageBefore := .imageBefore }} @@ -46,7 +46,7 @@

{{ . }}

{{ $pathBefore := printf "%s/%s" $path $imageBefore }} {{ $pathAfter := printf "%s/%s" $path $imageAfter }} {{ with and $imageBefore $imageAfter }} -
+
{{ with $imageBefore := resources.Get $pathBefore }} {{ $imageBefore }} {{ end }} @@ -64,5 +64,6 @@

{{ . }}

+ {{ end }} {{ end }} \ No newline at end of file diff --git a/layouts/partials/landing/image_text.html b/layouts/partials/landing/image_text.html index d65dd9d6..b04a2356 100644 --- a/layouts/partials/landing/image_text.html +++ b/layouts/partials/landing/image_text.html @@ -1,5 +1,5 @@ -{{ $sectionTitle := .Scratch.Get "sectionTitle" }} -{{ with (index .Site.Data.landing $sectionTitle) }} +{{ $sectionTitle := .sectionTitle }} +{{with .data}} {{ if eq .enable true }}
From f586b8bc2490dc657ae602df27dbddd780becf39 Mon Sep 17 00:00:00 2001 From: Morgan Gangwere Date: Thu, 4 Jan 2024 00:39:42 -0800 Subject: [PATCH 2/4] landing: Don't use scratch to get section title since we include it with context! --- layouts/partials/landing/feature_grid.html | 4 +--- layouts/partials/landing/hero.html | 4 +--- layouts/partials/landing/image_text.html | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/layouts/partials/landing/feature_grid.html b/layouts/partials/landing/feature_grid.html index d037b491..bd06d767 100644 --- a/layouts/partials/landing/feature_grid.html +++ b/layouts/partials/landing/feature_grid.html @@ -1,6 +1,4 @@ -{{ $sectionTitle := .Scratch.Get "sectionTitle" }} -{{with .data}} -{{ if eq .enable true }} +{{- $sectionTitle := .sectionTitle }}{{ with .data }}{{ if eq .enable true }}
diff --git a/layouts/partials/landing/hero.html b/layouts/partials/landing/hero.html index c711fc1a..a208f0e4 100644 --- a/layouts/partials/landing/hero.html +++ b/layouts/partials/landing/hero.html @@ -1,6 +1,4 @@ -{{ $sectionTitle := .Scratch.Get "sectionTitle" }} -{{ with .data }} -{{ if eq .enable true }} +{{- $sectionTitle := .sectionTitle }}{{ with .data }}{{ if eq .enable true }} {{ with .backgroundImage }} {{ $path := .path | default "images" }} diff --git a/layouts/partials/landing/image_text.html b/layouts/partials/landing/image_text.html index b04a2356..75e27ba9 100644 --- a/layouts/partials/landing/image_text.html +++ b/layouts/partials/landing/image_text.html @@ -1,6 +1,4 @@ -{{ $sectionTitle := .sectionTitle }} -{{with .data}} -{{ if eq .enable true }} +{{- $sectionTitle := .sectionTitle }}{{ with .data }}{{ if eq .enable true }}
From 5d73283ebc417673002218588a812bf6f780bf28 Mon Sep 17 00:00:00 2001 From: Morgan Gangwere Date: Mon, 29 Jan 2024 03:09:35 -0800 Subject: [PATCH 3/4] finish moving around JS --- assets/js/app.js | 10 +++++++- layouts/_default/baseof.html | 28 --------------------- layouts/partials/head.html | 17 ++++--------- layouts/partials/landing/image_compare.html | 2 +- 4 files changed, 15 insertions(+), 42 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index f182d2ef..cd885708 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -27,4 +27,12 @@ function toggleMenu() { } else { isOpen.style.display = "block"; } -}; \ No newline at end of file +}; + +window.addEventListener("DOMContentLoaded", (ev) => { + const viewers = document.querySelectorAll(".image-compare"); + viewers.forEach((element, i) => { + let view = new ImageCompare(element, JSON.parse(element.dataset.icConfig) ).mount(); + }); + +}); \ No newline at end of file diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 5e17f43d..c05981f2 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -26,33 +26,5 @@
{{- partial "footer.html" . -}} - - {{ $app := resources.Get "/js/app.js" }} - {{- if not .Site.IsServer }} - {{- $js := (slice $app) | resources.Concat "/js/bundle.js" | minify | fingerprint "sha384" }} - - {{- else }} - {{- $js := (slice $app) | resources.Concat "/js/bundle.js" }} - - {{- end }} - - {{ if (default false ($.Scratch.Get "image_compare_used")) }} - {{ $imagecompare := resources.Get "js/image-compare-viewer.min.js" }} - {{- if not .Site.IsServer }} - {{- $js := (slice $imagecompare) | resources.Concat "/js/image-compare.js" | minify | fingerprint "sha384" }} - - {{- else }} - {{- $js := (slice $imagecompare) | resources.Concat "/js/image-compare.js" }} - - {{- end }} - - - {{ end }} - diff --git a/layouts/partials/head.html b/layouts/partials/head.html index e3fbcf3e..e5bb45b6 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -27,7 +27,10 @@ {{- end -}} - {{ $js := resources.Get "js/bootstrap.js" }} + {{- $imgviewjs := resources.Get "/js/image-compare-viewer.min.js" -}} + {{- $appjs := resources.Get "/js/app.js" -}} + {{- $bsjs := resources.Get "js/bootstrap.js" -}} + {{- $js := slice $bsjs $imgviewjs $appjs | resources.Concat "/js/bundle.js"}} {{ $params := dict }} {{ $sourceMap := cond hugo.IsProduction "" "inline" }} {{ $opts := dict "sourceMap" $sourceMap "minify" hugo.IsProduction "target" "es2018" "params" $params }} @@ -35,18 +38,8 @@ {{ if hugo.IsProduction }} {{ $js = $js | fingerprint "sha384" }} {{ end }} + - - {{ if ($.Scratch.Get "image_compare_enabled") }} - {{ $imagecompare := resources.Get "js/image-compare-viewer.min.js" }} - {{- if not .Site.IsServer }} - {{- $js := (slice $imagecompare) | resources.Concat "/js/image-compare.js" | minify | fingerprint "sha384" }} - - {{- else }} - {{- $js := (slice $imagecompare) | resources.Concat "/js/image-compare.js" }} - - {{- end }} - {{- end }} {{- if not .Site.IsServer }} {{ if and (.Site.Params.plausible.scriptURL) (.Site.Params.plausible.dataDomain) -}} diff --git a/layouts/partials/landing/image_compare.html b/layouts/partials/landing/image_compare.html index 874fcbb2..be379ab8 100644 --- a/layouts/partials/landing/image_compare.html +++ b/layouts/partials/landing/image_compare.html @@ -1,5 +1,5 @@ {{- $sectionTitle := .sectionTitle }}{{ with .data }}{{ if eq .enable true }} -{{- page.Scratch.Set "image_compare_used" true -}} {{- page.Scratch.Add "imageCompareConfig" (slice (.config | jsonify | safeJS)) -}} +{{- page.Scratch.Set "image_compare_used" true -}}
From f090b4dcd5ca3e777112c59308e67ba61717f34f Mon Sep 17 00:00:00 2001 From: Morgan Gangwere Date: Mon, 29 Jan 2024 04:09:43 -0800 Subject: [PATCH 4/4] css: complete adding goat support --- .../docs/scss/custom/structure/_content.scss | 27 +++++++++++++++++++ assets/scss/style.scss | 14 +++------- .../docs/_markup/render-codeblock-goat.html | 18 +++++++++++++ 3 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 layouts/docs/_markup/render-codeblock-goat.html diff --git a/assets/docs/scss/custom/structure/_content.scss b/assets/docs/scss/custom/structure/_content.scss index 6a5b0456..59c000e9 100644 --- a/assets/docs/scss/custom/structure/_content.scss +++ b/assets/docs/scss/custom/structure/_content.scss @@ -257,6 +257,33 @@ i { } } + +// goat diagrams +figure.goat.svg-container { + + padding: 0.1rem; + align-items: center; + width: 100%; + @include media-breakpoint-up(md) { + width: auto; + padding:.5rem; + padding-left: auto; + padding-right: auto; + } + @include media-breakpoint-up(lg) { + padding: 1rem; + } + svg { + width:100%; + @include media-breakpoint-up(lg) { + max-width: 60rem; + } + font-family: var(--bs-font-monospace); + font-size: 0.7rem; + } +} + + // Chroma Highlighter CSS .docs-content .main-content td pre { diff --git a/assets/scss/style.scss b/assets/scss/style.scss index d14f0fda..396bb88f 100644 --- a/assets/scss/style.scss +++ b/assets/scss/style.scss @@ -27,25 +27,17 @@ $font-family-monospace: {{ .Site.Params.mono_font | default "SFMono-Regular, Me // Structure @import "custom/structure/general"; @import "custom/structure/topbar"; -// @import "custom/structure/content"; -// @import "custom/structure/sidebar-layouts"; -// @import "custom/structure/doc-nav"; -// @import "custom/structure/toc-layouts"; @import "custom/structure/footer"; -// // Components +// Components @import "custom/components/buttons"; @import "custom/components/badge"; -@import "custom/components/backgrounds"; -// @import "custom/components/alerts"; -// @import "custom/components/card"; -// // Pages +// Pages // @import "custom/pages/blog"; @import "custom/pages/features"; @import "custom/pages/helper"; @import "custom/pages/hero"; -{{ if ($.Scratch.Get "image_compare_enabled") }}@import "custom/pages/image-compare-viewer";{{ end }} +@import "custom/pages/image-compare-viewer"; -// @import "custom/pages/simplebar"; diff --git a/layouts/docs/_markup/render-codeblock-goat.html b/layouts/docs/_markup/render-codeblock-goat.html new file mode 100644 index 00000000..b1107e24 --- /dev/null +++ b/layouts/docs/_markup/render-codeblock-goat.html @@ -0,0 +1,18 @@ +{{ $width := .Attributes.width }} +{{ $height := .Attributes.height }} +{{ $class := .Attributes.class | default "" }} +
+ {{ with diagrams.Goat .Inner }} + + {{ .Inner }} + + {{ end }} +
\ No newline at end of file