diff --git a/exampleSite/config.yml b/exampleSite/config.yml index 977ff39..da4ca73 100644 --- a/exampleSite/config.yml +++ b/exampleSite/config.yml @@ -81,3 +81,5 @@ params: geekblogLegalNotice: https://thegeeklab.de/legal-notice/#contact-information geekblogPrivacyPolicy: https://thegeeklab.de/legal-notice/#privacy-policy + + geekblogImageLazyLoading: true diff --git a/exampleSite/content/posts/getting-started.md b/exampleSite/content/posts/getting-started.md index 92c8bad..99d1f5f 100644 --- a/exampleSite/content/posts/getting-started.md +++ b/exampleSite/content/posts/getting-started.md @@ -245,6 +245,10 @@ enableGitInfo = true # (Optional, default posts) Set the name of the default content section. geekblogContentSection = "my-pages" + # (Optional, default true) Enable or disable image lazy loading for images rendered + # by the 'img' shortcode. + geekblogImageLazyLoading = true + # (Optional, default none) Adds a "Hosted on " line to the footer. # Could be used if you want to give credits to your hosting provider. [params.geekblogHostedOn] @@ -355,6 +359,10 @@ params: # (Optional, default posts) Set the name of the default content section. geekblogContentSection: "my-pages" + # (Optional, default true) Enable or disable image lazy loading for images rendered + # by the 'img' shortcode. + geekblogImageLazyLoading: true + # (Optional, default none) Adds a "Hosted on " line to the footer. # Could be used if you want to give credits to your hosting provider. geekblogHostedOn: diff --git a/exampleSite/content/posts/post-with-images/index.md b/exampleSite/content/posts/post-with-images/index.md index 64c0ef5..df3f383 100644 --- a/exampleSite/content/posts/post-with-images/index.md +++ b/exampleSite/content/posts/post-with-images/index.md @@ -19,8 +19,37 @@ resources: credits: "[David Pennington](https://unsplash.com/@dtpennington) on [Unsplash](https://unsplash.com/s/photos/test)" --- -Amalia id per in minimum facility, quid facet modifier ea ma. Ill um select ma ad, en ferric patine sentient vim. Per expendable foreordained interpretations cu, maxim sole pertinacity in ram. Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture. Ornateness bland it ex enc, est yeti am bongo detract re. Pro ad prompts feud gait, quid exercise emeritus bis e. In pro quints consequent, denim fastidious copious quo ad. Stet probates in duo. +If you need more flexibility for your embedded images, you could use the `img` shortcode. It is using Hugo's +[page resources](https://gohugo.io/content-management/page-resources/) and supports lazy loading of your images. -{{< img name="testimage" size="small" >}} +**Attributes:** -Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture. Ornateness bland it ex enc, est yeti am bongo detract re. Pro ad prompts feud gait, quid exercise emeritus bis e. In pro quints consequent, denim fastidious copious quo ad. Stet probates in duo. +| Name | Usage | default | +| ------------- | -------------------------------------------------------------------------------------------------------------- | ----------------- | +| name (string) | Name of the image resource defined in your front matter. | empty | +| alt (string) | Description for displayed image. | resource `.Title` | +| size (string) | Thumbnail size (tiny\|small\|medium\|large). | empty | +| lazy (bool) | Enable or disable image lazy loading. Can be controlled globally by site parameter `geekblogImageLazyLoading`. | true | + +**Example:** + +Define your resources in the page front matter, custom parameter `params.credits` is optional. + + + +```md +--- +resources: + - name: testimage + src: "images/testimage.jpg" + title: This is a test image + params: + credits: "[David Pennington](https://unsplash.com/@dtpennington) on [Unsplash](https://unsplash.com/s/photos/test)" +--- + +{{}} +``` + + + +{{< img name="testimage" size="small" lazy=true >}} diff --git a/layouts/shortcodes/img.html b/layouts/shortcodes/img.html index 5976c37..a0a45ea 100644 --- a/layouts/shortcodes/img.html +++ b/layouts/shortcodes/img.html @@ -1,6 +1,7 @@ {{ $source := ($.Page.Resources.ByType "image").GetMatch (printf "*%s*" (.Get "name")) }} {{ $customAlt := .Get "alt" }} {{ $customSize := .Get "size" }} +{{ $lazyLoad := default (default true $.Site.Params.GeekblogImageLazyLoading) (.Get "lazy") }} {{ with $source }} {{ $caption := default .Title $customAlt }} @@ -16,6 +17,7 @@