Compare commits

...

7 Commits

Author SHA1 Message Date
renovate[bot] 7d1f9ee37f
chore(deps): update dependency eslint to v9 2024-04-15 05:21:33 +00:00
renovate[bot] f577da14ed chore(deps): update devdeps non-major 2024-04-15 05:21:05 +00:00
renovate[bot] fa1ce16050 chore(deps): update dependency sass to v1.74.1 2024-04-08 05:08:41 +00:00
Robert Kaussow 8d4af80fe6
re-enable link check 2024-04-07 22:45:58 +02:00
Robert Kaussow eb58e99158
skip link check 2024-04-07 22:31:50 +02:00
Robert Kaussow 6eb576575e
refactor: move profile size from img to degicated avatar shortcode (#817)
BREAKING CHANGE: The `size=profile` option was removed from the `img` shortcode. To create avatar images the new `avatar` shortcode can be used.
2024-04-07 21:54:12 +02:00
Robert Kaussow 7b52c98f17
fix: skip image processing if size is origin (#815) 2024-04-07 20:15:01 +02:00
8 changed files with 161 additions and 46 deletions

View File

@ -0,0 +1,46 @@
---
title: Avatar
resources:
- name: avatar
src: "avatar.jpg"
title: "Avatar"
---
The avatar shortcode is another custom image shortcode.
<!--more-->
## Usage
Define a resource in the page front matter.
<!-- spellchecker-disable -->
```md
---
resources:
- name: avatar
src: "images/avatar.jpg"
title: "Avatar"
---
{{</* avatar name="avatar" */>}}
```
<!-- spellchecker-enable -->
## Attributes
<!-- prettier-ignore-start -->
<!-- spellchecker-disable -->
{{< propertylist name=shortcode-avatar sort=name order=asc >}}
<!-- spellchecker-enable -->
<!-- prettier-ignore-end -->
## Example
<!-- spellchecker-disable -->
{{< avatar name=avatar size="small" >}}
<!-- spellchecker-enable -->

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -0,0 +1,18 @@
---
properties:
- name: name
type: string
description: Name of the image resource defined in page front matter.
required: true
- name: alt
type: string
description: Description text for the image.
required: false
- name: size
type: string
description: Thumbnail size. Supported values are `origin|tiny|small|medium|large`.
required: false
- name: anchor
type: string
description: "[Anchor](https://gohugo.io/content-management/image-processing/#anchor) to determine the placement of the crop box."
required: false

View File

@ -2,7 +2,7 @@
properties:
- name: name
type: string
description: Mame of the image resource defined in page front matter.
description: Name of the image resource defined in page front matter.
required: true
- name: alt
type: string
@ -10,7 +10,7 @@ properties:
required: false
- name: size
type: string
description: Thumbnail size. Supported values are `origin|profile|tiny|small|medium|large`.
description: Thumbnail size. Supported values are `origin|tiny|small|medium|large`.
required: false
- name: lazy
type: bool

View File

@ -0,0 +1,57 @@
{{- $source := ($.Page.Resources.ByType "image").GetMatch (printf "%s" (.Get "name")) }}
{{- $customAlt := .Get "alt" }}
{{- $customSize := .Get "size" | lower }}
{{- $customAnchor := default "smart" (.Get "anchor") | title }}
{{- $data := newScratch }}
{{- with $source }}
{{- $caption := default .Title $customAlt }}
{{- $isSVG := (eq .MediaType.SubType "svg") }}
{{- $origin := . -}}
{{- if $isSVG }}
{{- $data.SetInMap "size" "tiny" "160" }}
{{- $data.SetInMap "size" "small" "300" }}
{{- $data.SetInMap "size" "medium" "600" }}
{{- $data.SetInMap "size" "large" "900" }}
{{- else }}
{{- $data.SetInMap "size" "tiny" (printf "160x160 %s" $customAnchor) }}
{{- $data.SetInMap "size" "small" (printf "300x300 %s" $customAnchor) }}
{{- $data.SetInMap "size" "medium" (printf "600x600 %s" $customAnchor) }}
{{- $data.SetInMap "size" "large" (printf "900x900 %s" $customAnchor) }}
{{- end -}}
<div class="flex justify-center">
<figure
class="gdoc-markdown__figure gdoc-markdown__figure--round">
<a class="gdoc-markdown__link--raw" href="{{ .Permalink }}">
<picture>
{{- $size := $data.Get "size" }}
{{- if not $isSVG }}
{{- if ne $customSize "origin" }}
<source
{{- if $customSize }}
srcset="{{ ($origin.Fill (index $size $customSize)).Permalink }}"
{{- else }}
srcset="{{ ($origin.Fill (index $size "small")).Permalink }} 600w, {{ ($origin.Fill (index $size "medium")).Permalink }} 1200w" sizes="100vw"
{{- end }}
/>
{{- end }}
{{- end }}
<img
{{- if $isSVG }}
src="{{ $origin.Permalink }}" width="{{ index $size (default "medium" $customSize) }}"
{{- else }}
{{- if eq $customSize "origin" }}
src="{{ $origin.Permalink }}"
{{- else }}
src="{{ ($origin.Fill (index $size "large")).Permalink }}"
{{- end }}
alt="{{ $caption }}"
{{- end }}
/>
</picture>
</a>
</figure>
</div>
{{- end }}

View File

@ -7,64 +7,58 @@
{{- with $source }}
{{- $caption := default .Title $customAlt }}
{{- $isSVG := (eq .MediaType.SubType "svg") }}
{{- $origin := . }}
{{- $origin := .Permalink }}
{{- if $isSVG }}
{{- $data.SetInMap "size" "profile" "180" }}
{{- $data.SetInMap "size" "tiny" "320" }}
{{- $data.SetInMap "size" "small" "600" }}
{{- $data.SetInMap "size" "medium" "1200" }}
{{- $data.SetInMap "size" "large" "1800" }}
{{- else }}
{{- $data.SetInMap "size" "profile" (.Fill "180x180 Center").Permalink }}
{{- $data.SetInMap "size" "tiny" (.Resize "320x").Permalink }}
{{- $data.SetInMap "size" "small" (.Resize "600x").Permalink }}
{{- $data.SetInMap "size" "medium" (.Resize "1200x").Permalink }}
{{- $data.SetInMap "size" "large" (.Resize "1800x").Permalink }}
{{- end }}
{{- $data.SetInMap "size" "tiny" "320x"}}
{{- $data.SetInMap "size" "small" "600x" }}
{{- $data.SetInMap "size" "medium" "1200x" }}
{{- $data.SetInMap "size" "large" "1800x" }}
{{- end -}}
<div class="flex justify-center">
<figure
class="gdoc-markdown__figure
{{- if eq $customSize "profile" }}{{ print " gdoc-post__figure--round" }}{{ end }}"
>
<figure class="gdoc-markdown__figure">
<a class="gdoc-markdown__link--raw" href="{{ .Permalink }}">
<picture>
{{- $size := $data.Get "size" }}
{{- if not $isSVG }}
{{- if ne $customSize "origin" }}
<source
{{- with $customSize }}
srcset="{{ index $size $customSize }}"
{{- if $customSize }}
srcset="{{ ($origin.Resize (index $size $customSize)).Permalink }}"
{{- else }}
srcset="{{ $size.small }} 600w, {{ $size.medium }} 1200w" sizes="100vw"
srcset="{{ ($origin.Resize (index $size "small")).Permalink }} 600w, {{ ($origin.Resize (index $size "medium")).Permalink }} 1200w" sizes="100vw"
{{- end }}
/>
{{- end }}
{{- end }}
<img
{{- if $isSVG }}
src="{{ $origin }}" width="{{ index $size (default "medium" $customSize) }}"
src="{{ $origin.Permalink }}" width="{{ index $size (default "medium" $customSize) }}"
{{- else }}
{{- if $lazyLoad }}{{ print " loading=\"lazy\"" | safeHTMLAttr }}{{- end }}
{{- if eq $customSize "origin" }}
src="{{ $origin }}"
src="{{ $origin.Permalink }}"
{{- else }}
src="{{ $size.large }}"
src="{{ ($origin.Resize (index $size "large")).Permalink }}"
{{- end }}
alt="{{ $caption }}"
{{- end }}
/>
</picture>
</a>
{{- if not (eq $customSize "profile") }}
{{- with $caption }}
<figcaption>
{{ . }}
{{- with $source.Params.credits }}
{{ printf " (%s)" . | $.Page.RenderString }}
{{- end }}
</figcaption>
{{- end }}
{{- with $caption }}
<figcaption>
{{ . }}
{{- with $source.Params.credits }}
{{ printf " (%s)" . | $.Page.RenderString }}
{{- end }}
</figcaption>
{{- end }}
</figure>
</div>

24
package-lock.json generated
View File

@ -23,7 +23,7 @@
"@eloquent/git-version-webpack-plugin": "5.0.1",
"autoprefixer": "10.4.19",
"copy-webpack-plugin": "12.0.2",
"css-loader": "7.0.0",
"css-loader": "7.1.1",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
@ -33,8 +33,8 @@
"npm-run-all2": "6.1.2",
"postcss-loader": "8.1.1",
"prettier": "3.2.5",
"sass": "1.72.0",
"sass-loader": "14.1.1",
"sass": "1.75.0",
"sass-loader": "14.2.0",
"shx": "0.3.4",
"svg-sprite": "2.0.4",
"svgtofont": "4.2.0",
@ -3514,9 +3514,9 @@
}
},
"node_modules/css-loader": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/css-loader/-/css-loader-7.0.0.tgz",
"integrity": "sha512-WrO4FVoamxt5zY9CauZjoJgXRi/LZKIk+Ta7YvpSGr5r/eMYPNp5/T9ODlMe4/1rF5DYlycG1avhV4g3A/tiAw==",
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/css-loader/-/css-loader-7.1.1.tgz",
"integrity": "sha512-OxIR5P2mjO1PSXk44bWuQ8XtMK4dpEqpIyERCx3ewOo3I8EmbcxMPUc5ScLtQfgXtOojoMv57So4V/C02HQLsw==",
"dev": true,
"dependencies": {
"icss-utils": "^5.1.0",
@ -9154,9 +9154,9 @@
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"node_modules/sass": {
"version": "1.72.0",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.72.0.tgz",
"integrity": "sha512-Gpczt3WA56Ly0Mn8Sl21Vj94s1axi9hDIzDFn9Ph9x3C3p4nNyvsqJoQyVXKou6cBlfFWEgRW4rT8Tb4i3XnVA==",
"version": "1.75.0",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.75.0.tgz",
"integrity": "sha512-ShMYi3WkrDWxExyxSZPst4/okE9ts46xZmJDSawJQrnte7M1V9fScVB+uNXOVKRBt0PggHOwoZcn8mYX4trnBw==",
"dev": true,
"dependencies": {
"chokidar": ">=3.0.0 <4.0.0",
@ -9171,9 +9171,9 @@
}
},
"node_modules/sass-loader": {
"version": "14.1.1",
"resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-14.1.1.tgz",
"integrity": "sha512-QX8AasDg75monlybel38BZ49JP5Z+uSKfKwF2rO7S74BywaRmGQMUBw9dtkS+ekyM/QnP+NOrRYq8ABMZ9G8jw==",
"version": "14.2.0",
"resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-14.2.0.tgz",
"integrity": "sha512-jxmjDXD9OYNDb2bp9JvopdE6QjecQY9beTWik/6sEHrsMxyo90Gyc471A4NUz60NLs4WsAh6yVtIvhLwEZcXeg==",
"dev": true,
"dependencies": {
"neo-async": "^2.6.2"

View File

@ -47,8 +47,8 @@
"@eloquent/git-version-webpack-plugin": "5.0.1",
"autoprefixer": "10.4.19",
"copy-webpack-plugin": "12.0.2",
"css-loader": "7.0.0",
"eslint": "8.57.0",
"css-loader": "7.1.1",
"eslint": "9.0.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"favicons": "7.2.0",
@ -57,8 +57,8 @@
"npm-run-all2": "6.1.2",
"postcss-loader": "8.1.1",
"prettier": "3.2.5",
"sass": "1.72.0",
"sass-loader": "14.1.1",
"sass": "1.75.0",
"sass-loader": "14.2.0",
"shx": "0.3.4",
"svg-sprite": "2.0.4",
"svgtofont": "4.2.0",