From 45e970953c790e71857ae6ef02fc5c3020a9adc7 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Sun, 29 Jan 2023 14:22:31 +0100 Subject: [PATCH] Add icon-inline component, update render-heading.html.example and add render-image.html.example. --- assets/sass/_zen.scss | 28 ------- .../components/icon-inline/_icon-inline.scss | 27 +++++++ assets/sass/styles.scss | 1 + .../_markup/render-heading.html.example | 10 +-- .../_markup/render-image.html.example | 78 +++++++++++++++++++ 5 files changed, 111 insertions(+), 33 deletions(-) create mode 100644 assets/sass/components/icon-inline/_icon-inline.scss create mode 100644 layouts/_default/_markup/render-image.html.example diff --git a/assets/sass/_zen.scss b/assets/sass/_zen.scss index 35016e9..87366c6 100644 --- a/assets/sass/_zen.scss +++ b/assets/sass/_zen.scss @@ -292,31 +292,3 @@ figure { } } } - -// Icons. - -.icon { - // Reset set SVG to block but icons are normally inline. - display: inline; -} - -// Header anchor links - -.anchor-link { - opacity: 0; - transition: all 130ms ease-in; -} - -.anchor-header { - &:focus, - &:hover { - .anchor-link { - opacity: .3; - - &:focus, - &:hover { - opacity: 1; - } - } - } -} diff --git a/assets/sass/components/icon-inline/_icon-inline.scss b/assets/sass/components/icon-inline/_icon-inline.scss new file mode 100644 index 0000000..8897cd3 --- /dev/null +++ b/assets/sass/components/icon-inline/_icon-inline.scss @@ -0,0 +1,27 @@ +// Inline icons. + +.icon-inline, +%icon-inline { + .icon-link { + opacity: 0; + transition: all 130ms ease-in; + text-decoration: none; + } + + &:focus, + &:hover { + .icon-link { + opacity: .3; + + &:focus, + &:hover { + opacity: 1; + } + } + } + + svg { + display: inline; + vertical-align: middle; + } +} diff --git a/assets/sass/styles.scss b/assets/sass/styles.scss index 5c46dd3..dda7e2d 100644 --- a/assets/sass/styles.scss +++ b/assets/sass/styles.scss @@ -40,6 +40,7 @@ @import 'components/header/header'; @import 'components/hidden/hidden'; @import 'components/highlight-mark/highlight-mark'; +@import 'components/icon-inline/icon-inline'; @import 'components/language-selector/language-selector'; @import 'components/list-straight-left/list-straight-left'; @import 'components/messages/messages'; diff --git a/layouts/_default/_markup/render-heading.html.example b/layouts/_default/_markup/render-heading.html.example index 026379c..415fd42 100644 --- a/layouts/_default/_markup/render-heading.html.example +++ b/layouts/_default/_markup/render-heading.html.example @@ -1,7 +1,7 @@ -{{ .Text | safeHTML }} - - + +{{- .Text | safeHTML -}} + + diff --git a/layouts/_default/_markup/render-image.html.example b/layouts/_default/_markup/render-image.html.example new file mode 100644 index 0000000..e4ee30b --- /dev/null +++ b/layouts/_default/_markup/render-image.html.example @@ -0,0 +1,78 @@ +{{/* Control how the image is rendered with these variables. */}} +{{ $class := "" -}} +{{ $size := "" -}} +{{ $srcset := "" -}} +{{ $width := "" -}} + +{{/* Only change the below code if you know what you are doing. */}} +{{ $height := "" -}} +{{ $maxwidth := site.Params.imageMaxWidth -}} +{{ $realwidth := 0 -}} +{{ $realheight := 0 -}} +{{ $resource := false -}} +{{ $src := .Destination -}} +{{ $srcsetw := (slice) }} +{{ $static := false -}} + +{{ if and $src (fileExists (path.Join "/static" $src)) -}} + {{ with (imageConfig (path.Join "/static" $src)) -}} + {{ $realwidth = .Width -}} + {{ $realheight = .Height -}} + {{ end -}} + {{ $static = true -}} + {{ $src = relURL $src -}} +{{ else if $src -}} + {{ $src = strings.TrimLeft "/" $src -}} + {{ with resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} + {{ with .Page.Resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} +{{ end -}} + +{{ if $resource -}} + {{ if $size -}} + {{ $image := $resource.Resize $size -}} + {{ $src = $image.RelPermalink -}} + {{ $width = $image.Width -}} + {{ $height = $image.Height -}} + {{ else -}} + {{ $src = $resource.RelPermalink -}} + {{ $realwidth = $resource.Width -}} + {{ $realheight = $resource.Height -}} + {{ end -}} + {{ if $srcset -}} + {{ range $set := split $srcset " " -}} + {{ $image := $resource.Resize (printf "%sx" $set) -}} + {{ $srcsetw = $srcsetw | append (printf "%s %sw" $image.RelPermalink $set) }} + {{ end }} + {{ $width = "" -}} + {{ $height = "" -}} + {{ end -}} +{{ end -}} + +{{ if and $width $height -}} + {{ $width = int $width -}} + {{ $height = int $height -}} +{{ else if $width -}} + {{ $width = int $width -}} + {{ $height = $realheight -}} + {{ if and ($realwidth) (lt ($width) ($realwidth)) -}} + {{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}} + {{ $height = (math.Round $height) -}} + {{ end -}} +{{ else if $height -}} + {{ $width = $realwidth -}} + {{ $height = int $height -}} + {{ if and ($realheight) (lt ($height) ($realheight)) -}} + {{ $width = (mul ($realwidth) (div (add ($height) 0.0) ($realheight))) -}} + {{ $width = (math.Round $width) -}} + {{ end -}} +{{ else if and ($maxwidth) (lt ($maxwidth) ($realwidth)) -}} + {{ $width = ($maxwidth) -}} + {{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}} + {{ $height = (math.Round $height) -}} +{{ end -}} + +{{ .Text }}