Skip to content

Commit

Permalink
feat: use frontmatter params
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokaiser committed Nov 23, 2024
1 parent bc33088 commit 991f99c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A very simple and opinionated photo gallery theme for Hugo.

## Installation

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

### As a Hugo Module

Expand Down Expand Up @@ -60,15 +60,15 @@ content/
│ ├── cats/
│ | ├── index.md
│ | ├── cat1.jpg
│ | └── feature.jpg <-- album thumbnail
│ | └── feature.jpg <-- album cover
│ ├── dogs/
│ | ├── index.md
│ | ├── dog1.jpg <-- album thumbnail
│ | ├── dog1.jpg <-- album cover
│ | └── dog2.jpg
│ └── feature.jpg
├── bridge.jpg <-- site thumbnail (OpenGraph, etc.)
└── nature/
├── index.md <-- contains `featured_image: tree.jpg`
├── index.md <-- contains `cover: true` for `tree.jpg`
├── nature1.jpg
├── nature2.jpg
└── tree.jpg <-- album thumbnail
Expand All @@ -85,22 +85,25 @@ content/
- `title` -- title of the album, shown in the album list and on the album page.
- `date` -- album date, used for sorting (newest first).
- `description` -- description shown on the album page. Rendered as markdown to enable adding links and some formatting.
- `featured_image` -- name of the image file used for the album thumbnail. If not set, the first image which contains `feature` in its filename is used, otherwise the first image in the album.
- `weight` -- can be used to adjust sort order.
- `private` -- if set to `true`, this album is not shown in the album overview and is excluded from RSS feeds.
- `featured` -- if set to `true`, this album is featured on the homepage (even if private).
- `sort_by` -- property used for sorting images in an album. Default is `Name` (filename), but can also be `Date`.
- `sort_order` -- sort order. Default is `asc`.
- `params.featured_image` -- name of the image file used for the album thumbnail. If not set, the first image which contains `feature` in its filename is used, otherwise the first image in the album.
- `params.private` -- if set to `true`, this album is not shown in the album overview and is excluded from RSS feeds.
- `params.featured` -- if set to `true`, this album is featured on the homepage (even if private).
- `params.sort_by` -- property used for sorting images in an album. Default is `Name` (filename), but can also be `Date`.
- `params.sort_order` -- sort order. Default is `asc`.
- `params.theme` -- color theme for this page. Defaults to `defaultTheme` from configuration.

### Album Cover / Featured Image
### Album Cover

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:
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 `cover` resource parameter in the front matter:

```plain
---
featured_image: img_1234.jpg
title: Cats
title: Nature
resources:
- src: tree.jpg
params:
cover: true
---
```

Expand Down Expand Up @@ -140,9 +143,12 @@ content/dogs/index.md:
```plain
---
date: 2023-01-12
featured_image: dogs-title-image.jpg
title: Dogs
categories: ["animals", "nature"]
resources:
- src: dogs-title-image.jpg
params:
cover: true
---
```

Expand All @@ -161,7 +167,7 @@ description: This is the description text of the "animals" category.

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.
Then, `/categories` displays a list of categories, with their cover image.

#### Other Taxonomies

Expand All @@ -174,7 +180,8 @@ Albums (and als taxonomy pages like categories) can be marked as "featured":
```plain
---
title: Featured Album
featured: true
params:
featured: true
---
```

Expand Down
2 changes: 2 additions & 0 deletions exampleSite/content/animals/cats/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ date: 2023-04-01
title: Cats
sort_by: Name
categories: ["animals", "nature"]
params:
featured_image: manja-vitolic-gKXKBY-C-Dk-unsplash.jpg
resources:
- src: alexander-london-mJaD10XeD7w-unsplash.jpg
title: Brown tabby cat on white stairs by Alexander London
Expand Down
5 changes: 3 additions & 2 deletions exampleSite/content/featured-album/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
date: 2023-01-12
title: Featured Album
featured: true
private: true # do not show in list, only as feature
params:
featured: true
private: true # do not show in list, only as feature
description: This is a featured album. It is private, so it is only shown on the homepage.
resources:
- src: jeremy-bishop-pjszS6Q2g_Y-unsplash.jpg
Expand Down
5 changes: 3 additions & 2 deletions exampleSite/content/nature/index.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
description: Through photography, the beauty of Mother Nature can be frozen in time. This category celebrates the magic of our planet and beyond — from the immensity of the great outdoors, to miraculous moments in your own backyard.
menus: "main"
sort_by: Name # Exif.Date
sort_order: desc
title: Nature
categories: ["nature"]
weight: 3
params:
featured_image: azzedine-rouichi-ZS_XuDZmxpM-unsplash.jpg
theme: dark
sort_order: desc
sort_by: Name # Exif.Date
resources:
- src: azzedine-rouichi-ZS_XuDZmxpM-unsplash.jpg
params:
Expand Down
3 changes: 2 additions & 1 deletion exampleSite/content/private/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
description: A private gallery that is only available by direct link.
private: true # This gallery does not show in lists, RSS, sitemaps, etc. On list pages, use cascade to hide descendants.
title: Private
params:
private: true # This gallery does not show in lists, RSS, sitemaps, etc. On list pages, use cascade to hide descendants.
---
2 changes: 1 addition & 1 deletion theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "A very simple and opinionated photo gallery theme for Hugo"
homepage = "https://github.com/nicokaiser/hugo-theme-gallery"
demosite = "https://nicokaiser.github.io/hugo-theme-gallery/"
tags = ["gallery", "responsive", "minimal", "dark"]
min_version = "0.121.2"
min_version = "0.123.0"

[author]
name = "Nico Kaiser"
Expand Down

0 comments on commit 991f99c

Please sign in to comment.