-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move profile size from img to degicated avatar shortcode (#525
) BREAKING CHANGE: The `size=profile` option was removed from the `img` shortcode. To create avatar images the new `avatar` shortcode can be used.
- Loading branch information
Showing
12 changed files
with
211 additions
and
53 deletions.
There are no files selected for viewing
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: Avatar Images | ||
date: 2024-04-27T21:00:00+02:00 | ||
authors: | ||
- john-doe | ||
tags: | ||
- Documentation | ||
- Shortcodes | ||
resources: | ||
- name: avatar | ||
src: "images/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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
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: lazy | ||
type: bool | ||
description: Enable/disable lazy loading for the image. | ||
required: false | ||
defaultValue: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
properties: | ||
- name: file | ||
type: string | ||
description: Path of the file (relative to the Hugo root) to include. | ||
required: true | ||
- name: language | ||
type: string | ||
description: Language for [syntax highlighting](https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages). | ||
required: false | ||
- name: type | ||
type: string | ||
description: Special include type. Supported values are `html|page`. If not set the included file is rendered as markdown. | ||
required: false | ||
- name: options | ||
type: bool | ||
description: highlighting [options](https://gohugo.io/content-management/syntax-highlighting/#highlight-shortcode). | ||
required: false | ||
defaultValue: linenos=table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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="gblog-post__figure gblog-post__figure--round"> | ||
<a class="gblog-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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters