You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Maxim Lebedev 7ceca4ca46
🚚 Moved modules from GitLab to Gitea
3 months ago
..
layouts/partials Added new functions module 1 year ago
README.md Added new functions module 1 year ago
config.yaml Added new functions module 1 year ago
go.mod 🚚 Moved modules from GitLab to Gitea 3 months ago

README.md

Functions

Various useful utilities for Hugo static generated site.

Install

Config

Import module in your site
configuration:

imports:
  - path: gitlab.com/toby3d/hugo/functions

Usage

srcset

Generates the srcset attribute for adaptive image resources. Takes an image resource as an argument and returns an attribute with references to alternate sizes of that resource. If no alternate resources can be generated based on the settings, an empty string will be returned.

Config

Add the following parameters to the site configuration. The example below shows the default values:

params:
  imaging:
    min: 50 # Minimum width for generated images
    max: 1000 # Maximum width for generated images
    count: 20 # Maximum number of generated images

Usage

{{- $image := resources.GetMatch "sample" -}}
<img src="{{ $image.Permalink }}" {{ partial "functions/srcset" $image | safeHTMLAttr }} loading="lazy" />

Result

<img src="https://example.com/images/image.jpg" srcset="https://example.com/images/image_hu163a76a9d5551ae508ac1b34fee2c6dc_611848_960x0_resize_box_2.png 960w, https://example.com/images/image_hu163a76a9d5551ae508ac1b34fee2c6dc_611848_480x0_resize_box_2.png 480w, https://example.com/images/image_hu163a76a9d5551ae508ac1b34fee2c6dc_611848_240x0_resize_box_2.png 240w" />

wbr

Renders long URLs with hyphenation tags. See «Better Line Breaks for Long URLs».

Usage

{{ partial "functions/wbr" $.Page.Permalink | safeHTML }}

Result

http:<wbr>//<wbr>www<wbr>.<wbr>example<wbr>.com<wbr>/<wbr>s/<wbr>ref<wbr>=<wbr>sr<wbr>_<wbr>nr<wbr>_<wbr>i<wbr>_o<wbr>