Multiple Hugo Themes For Different Paths In Same Site

Multiple Hugo Themes For Different Paths In Same Site #

Background #

I decided recently to publish a few of my notes online but wanted to keep it simple and naturally thought of using hugo for it. Now, I could simply setup another subdomain (e.g. notes.shantanugoel.com) but wanted to avoid doing so, and rather use something like shantanugoel.com/notes. This is possible but it’d use the same blog theme that I am using on my main domain shantanugoel.com. So I set out to find a way to use a main blog theme for my site while using a separate notes theme for the /notes path.

Solution #

1. Create a separate folder to hold the content for the notes #

πŸ¦„  ls
archetypes/
config/
content/
data/
layouts/
notes/ <<---I created this folder
public/
resources/
static/
themes/

2. Split the hugo configuration #

The split would have:

  • A default configuration that is used for all parts of the site
  • A configuration used only for the main site (Primarily specifying the theme and any specific theme parameters)
  • A configuration used only for the notes site (Primarily specifying the theme and any specific theme parameters + changing the baseURL, and the directory from where to pick up the content and where to publish it)

This is how it looks like

πŸ¦„  exa -a --tree --level=2 config
config
β”œβ”€β”€ _default
β”‚  └── hugo.toml
β”œβ”€β”€ main
β”‚  └── hugo.toml
└── notes
   └── hugo.toml
πŸ¦„  bat .\config\main\hugo.toml
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────
       β”‚ File: .\config\main\hugo.toml
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   β”‚ [module]
   2   β”‚ [[module.imports]]
   3   β”‚   path = 'github.com/shantanugoel/hugo-theme-terminal/v4'
   4   β”‚
   5   β”‚ theme = "hugo-theme-terminal"
πŸ¦„  bat .\config\notes\hugo.toml
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────
       β”‚ File: .\config\notes\hugo.toml
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   β”‚ title = "Shantanu's Notesverse"
   2   β”‚ contentDir = "notes"
   3   β”‚ publishDir = "public/notes"
   4   β”‚ baseurl = "https://shantanugoel.com/notes"
   5   β”‚
   6   β”‚ [module]
   7   β”‚ [[module.imports]]
   8   β”‚   path = 'github.com/shantanugoel/hugo-book'
   9   β”‚
  10   β”‚ theme = "hugo-book"
  11   β”‚
  12   β”‚ [params]
  13   β”‚   BookComments = false
  14   β”‚   BookSection = "*"
  15   β”‚
  16   β”‚ [menu]
  17   β”‚ [[menu.before]]
  18   β”‚   name = "Blog"
  19   β”‚   url = "https://shantanugoel.com"

3. How to use it #

Now, you can build the different parts of the site using the -e parameter for hugo to specify the environment. E.g. main site can be built using hugo -e main and the notes site can be built using hugo -e notes. Same can be done for any other hugo commands as well.