Giter Club home page Giter Club logo

hugo-shortcode-gallery's Introduction

hugo-shortcode-gallery

This is a theme component for hugo.

This component contains a shortcode to include a gallery in your .md files.

The gallery is rendered using autogenerated thumbnails arranged in a grid. With a click on the images a lightbox is opened an all images can be viewed fullscreen.

Demo

You can see this shortcode-gallery in action on my website.

Installation

Clone this git repository into your themes folder.

git clone https://github.com/mfg92/hugo-shortcode-gallery.git

Next edit your projects config.toml and add this theme component to your themes:

theme = ["your-main-theme", "hugo-shortcode-gallery"]

To read about hugo's theme components and how to use them have a look at https://gohugo.io/themes/theme-components/.

Usage Example

Here is an usage example:

{{< gallery match="images/*" sortOrder="desc" rowHeight="150" margins="5" resizeOptions="600x300 q90 Lanczos" showExif="true" previewType="blur" embedPreview=true >}}

This will generate a gallery containing all images of the folder images. The folder must be next to the .md file where this gallery is used in.

The parameter sortOrder decides whether the images are sorted ascending ("asc") or decending ("desc").

The rowHeight parameter determines the height of the rows that are displayed while the margin parameter defines the gap between the images.

A thumbnail is generated using the resizeOptions parameter, they are handed over to Hugos image processing function using the fit method. In the example above the generated thumbnails have a width of max 300 pixel and a height of max 600, the actual width and heigth depend on the original aspect ratio. The JPEG image quality is 90% and the scaling uses the high quality Lanczos filter.

If previewType is set to "blur" (or "color"), a very low resolution image (or a single pixel image) will be loaded for every image in the gallery first. The hight resolution thumbnail images (see resizeOptions) will only be loaded if they are on the currently visible part of the page (or close to it). This leads to a faster loading page. You can set previewType to "none" to disable this feature and all thumbnails will be directly loaded.

Enable embedPreview to let hugo embed the tiny preview image directly in the page HTML as a base64 strings. This reduces the amount of required network round trip times.

The setting thumbnailHoverEffect configures what should happen when the mouse hovers above a thumbnail in the gallery. It defaults to "none", but it can be set to "enlarge", in that case the image is scaled up (x1.1) in a short smooth animation.

When the users klicks on an image, a lightbox shows up displaying the klicked image in large using the whole available space. If the image contains a title or description there will be a top bar displaying that. If the showExif option is set to "true", some parts of the image's EXIF data will be shown on the bottom bar e.g.: "Canon EOS 80D + EF100-400mm f/4.5-5.6L IS II USM 400mm f/8 1/400sec ISO 2500". The EXIF display will only work if you add following lines to your config.toml:

[imaging.exif]
    includeFields = ".*"

As many websites/themes already include jQuery, this theme component will use the available jQuery lib. If the page does not already use jQuery the parameter loadJQuery=true must be used to instruct the theme component to load the provided jQuery lib.

All settings can be done globally in the site's config.toml, for that the prefix gallery has to be used. E.g. galleryLoadJQuery instead of loadJQuery.

Requirements

This component requires a hugo version >= 0.58.

Dependencies

The component uses (and includes) Justified Gallery to render the images between the text and Swipebox to show them fullscreen.

Troubleshooting

When bigger galleries are processed it can be required to set hugo's timeout property in the config.toml to a higher value:

timeout = 60000 # This is required for larger galleries to be build (60 sec)

hugo-shortcode-gallery's People

Contributors

mfg92 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.