Routing with combinations of taxonomies

I was wondering if someone have a tips to make something like below.

Let takes an simplified example:

  • Directors
  • Genre
  • Year

From these terms, Hugo would automatically create pages for each Director, Genre, and Year, with each listing all of the Movies that matched that specific Director, Genre, and Year. — Taxonomies | Hugo

Can Hugo generate the combinations of taxonomies?

/directors/wes-anderson/genre/comedy/ this would list the films directed by Wes Anderson and for which the genre is a comedy, like in this IMDB results page.

I understand it could be a lot of generated pages and routes, but I guess Hugo is fast enough to handle this large amount of data.

What do you think?
Should such filters be handled with JavaScript?

Note about Combinations vs Permutations

Permutations differ from Combinations, which are selections of some members of a set regardless of order.

[EDIT] another example is this selection of wines : http://www.lacavedespapilles.com/produits/c/bourgogne+rouge+75cl+nature

No. You can achieve this with JS though.

There’s trick if you’re willing to create an output format for each genre.

You could add those output format to the “directors” taxonomy.

# content/directors/_index.md
cascade:
  outputs:
  - HTML
  - genre-comedy
  - genre-horror
  - etc...

Then for each directory term page hugo would also create a genre output format, comedy output format at /directors/wes-anderson/genre-comedy.html, /directors/wes-anderson/genre-comedy.html.

Then from the layouts/directors/term.genre-comedy.html template you could restrict the .Pages with the given genre with the proper where clause .

To improve the permalinks, if you’re using netlify you could use their _redirects file to make the rewrites your need. (They even have query params if you want something like /?genre=comedy&director=wes-anderson.

I wrote an article a few years back that included a way to achieve what you want: Enhance Your Hugo JSON API Using Custom Output Formats and Netlify Redirects | Forestry.io

But again, you need to create an output format and template file for each of your genres so this limited.

1 Like

Hugo has features to define any relationships between any kinds/types of pages. It is are exactly what you need.

This post give you cool example of related content.

1 Like