Skip to content

Commit

Permalink
feat: add option to change the crop box anchor in img shortcode (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys authored Dec 2, 2023
1 parent e75703c commit 45398ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions exampleSite/content/posts/post-with-images/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ If you need more flexibility for your embedded images, you could use the `img` s

## Attributes

| Name | Description | default |
| ---- | ------------------------------------------------------------ | ----------------- |
| name | name of the image resource defined in your front matter | empty |
| alt | description for displayed image | resource `.Title` |
| size | Thumbnail size (origin\|profile\|tiny\|small\|medium\|large) | empty |
| lazy | enable or disable image lazy loading | true |
| Name | Description | default |
| ------ | -------------------------------------------------------------------------------- | ----------------- |
| name | name of the image resource defined in your front matter | empty |
| alt | description for displayed image | resource `.Title` |
| size | Thumbnail size (origin\|profile\|tiny\|small\|medium\|large) | empty |
| lazy | enable or disable image lazy loading | true |
| anchor | anchor to determine the placement of the crop box (only used for `profile` size) | smart |

## Usage

Expand Down
3 changes: 2 additions & 1 deletion layouts/shortcodes/img.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{- $source := ($.Page.Resources.ByType "image").GetMatch (printf "%s" (.Get "name")) }}
{{- $customAlt := .Get "alt" }}
{{- $customSize := .Get "size" | lower }}
{{- $customAnchor := default "smart" (.Get "anchor") | title }}
{{- $lazyLoad := default (default true $.Site.Params.geekblogImageLazyLoading) (.Get "lazy") }}
{{- $data := newScratch }}

Expand All @@ -16,7 +17,7 @@
{{- $data.SetInMap "size" "medium" "1200" }}
{{- $data.SetInMap "size" "large" "1800" }}
{{- else }}
{{- $data.SetInMap "size" "profile" (.Fill "180x180 Smart").Permalink }}
{{- $data.SetInMap "size" "profile" (.Fill (printf "180x180 %s" $customAnchor)).Permalink }}
{{- $data.SetInMap "size" "tiny" (.Resize "320x").Permalink }}
{{- $data.SetInMap "size" "small" (.Resize "600x").Permalink }}
{{- $data.SetInMap "size" "medium" (.Resize "1200x").Permalink }}
Expand Down

0 comments on commit 45398ae

Please sign in to comment.