nicokaiser / hugo-theme-gallery

Gallery Theme for Hugo
https://nicokaiser.github.io/hugo-theme-gallery/
MIT License
336 stars 98 forks source link
gallery hugo hugo-theme

Hugo Gallery Theme

A very simple and opinionated photo gallery theme for Hugo.


Screenshot


Features

Installation

This theme requires Hugo Extended >= 0.121.2. Dependencies are bundled, so no Node.js/NPM and PostCSS is needed.

As a Hugo Module

Requires the Go binary installed.

hugo mod init github.com/<your_user>/<your_project>

Then add the theme to your hugo.toml:

[module]
  [[module.imports]]
    path = "github.com/nicokaiser/hugo-theme-gallery/v4"

As Git Submodule

git submodule add --depth=1 https://github.com/nicokaiser/hugo-theme-gallery.git themes/gallery

Usage

Page bundles which contain at least one image are listed as album or gallery:

content/
├── _index.md
├── about.md             <-- not listed in album list
├── animals/
│   ├── _index.md
│   ├── cats/
│   |   ├── index.md
│   |   ├── cat1.jpg
│   |   └── feature.jpg  <-- album thumbnail
│   ├── dogs/
│   |   ├── index.md
│   |   ├── dog1.jpg     <-- album thumbnail
│   |   └── dog2.jpg
│   └── feature.jpg
├── bridge.jpg           <-- site thumbnail (OpenGraph, etc.)
└── nature/
    ├── index.md         <-- contains `featured_image: images/tree.jpg`
    ├── images/
    |   └── tree.jpg     <-- album thumbnail
    ├── nature1.jpg
    └── nature2.jpg

Front matter

Album Cover / Featured Image

By default, the cover image of an album is the first image in its folder. To select a specific image (which must be part of the album), use the featured_image frontmatter:

---
featured_image: img_1234.jpg
title: Cats
---

Image Metadata

Image titles for the lightbox view are either taken from the ImageDescription EXIF tag, or the title in the resource metadata.

EXIF tags can be written using software like Adobe Lightroom or by using command line tools like exiftool:

exiftool -ImageDescription="A closeup of a gray cat's face" cat-4.jpg

Alternatively, the image title can be set in the front matter:

---
date: 2024-02-18T14:12:44+0100
title: Cats
resources:
  - src: cat-1.jpg
    title: Brown tabby cat on white stairs
    params:
      date: 2024-02-18T13:04:30+0100
  - src: cat-4.jpg
    title: A closeup of a gray cat's face
---

Categories

If you use categories in your albums, the homepage displays a list of categories. Make sure term is not included in disabledKinds in the site config.

content/dogs/index.md:

---
date: 2023-01-12
featured_image: dogs-title-image.jpg
title: Dogs
categories: ["animals", "nature"]
---

Categories can also have custom titles and descriptions (by default, the "animals" category will have "Animals" as title and no description). Just create a content/categories/<category>/_index.md:

content/categories/animals/_index.md:

---
title: Cute Animals
description: This is the description text of the "animals" category.
---

List of Categories

To enable a list of categories, each category must at least have an image in the content/categores/<category>/ folder. Also, taxonomy must not be included in the disableKinds in the site config.

Then, /categories displays a list of categories, with their featured image.

Other Taxonomies

You can also use other taxonomies like series. Note that only categories and tags are enabled by Hugo's default settings. Using series as additional taxonomy is left as an exercise for the reader.

Featured Content on the Homepage

Albums (and als taxonomy pages like categories) can be marked as "featured":

---
title: Featured Album
featured: true
---

When used in combination with private: true this album is only shown as featured album on the homepage, and not in any album list.

Note that also categories or any other taxonomy term can be marked as featured, so you can feature a whole category, series, etc.

By default, the homepage displays

This can easily be adjusted by using a local version of layouts/_default/home.html.

Related Content

If related content is available for your site (e.g. when keywords or tags are used), related albums are shown below each gallery. Read more about this in the Hugo Docs.

Here is an example section in config/_default/hugo.toml to enable related content:

[related]
  includeNewer = true
  threshold = 10
  toLower = false
  [[related.indices]]
    applyFilter = false
    cardinalityThreshold = 0
    name = 'categories'
    pattern = ''
    toLower = false
    type = 'basic'
    weight = 10
  [[related.indices]]
    applyFilter = false
    cardinalityThreshold = 0
    name = 'keywords'
    pattern = ''
    toLower = false
    type = 'basic'
    weight = 50

Social Icons

Use the socialIcons configuration key to add social icons on the bottom of each page:

[params]
  ...
  [params.socialIcons]
    facebook = "https://www.facebook.com/"
    instagram = "https://www.instagram.com/"
    github = "https://github.com/nicokaiser/hugo-theme-gallery/"
    youtube = "https://www.youtube.com/"
    email = "mailto:user@example.com"
    linkedin = "https://linkedin.com/"

Custom CSS

CSS is generated with Hugo Pipes, so you can add additional CSS in assets/css/custom.css (see example in exampleSite).

Author