gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.86k stars 7.54k forks source link

Multisite support within Hugo #11931

Closed Fethbita closed 9 months ago

Fethbita commented 9 months ago

There are a couple of pages explaining how multisite support currently works with Hugo:

and I have tried all of these within my environment. My use case is as follows: I have a domain, https://example.com, and I want to generate a blog using Hugo and have it under https://blog.example.com and I want to generate a single "about" page and have that under https://example.com, have that as the landing page so to say. The styles and some static files will be used in both pages. My first instinct was to follow the discussion here and have a folder structure like the following:

hugo-dir
└── archetypes
└── assets
└── data
└── sites
│   └── blog
│   │   └── blog.toml
│   │   └── content
│   │   │   └── blog-post-1
│   │   │   │   └── index.md
│   │   │   │   └── images
│   │   │   │   │   └── image1.jpg
│   │   │   └── blog-post-2
│   │   │   │   └── index.md
│   │   │   └── blog-post-3
│   │   │   │   └── index.md
│   │   │   │   └── images
│   └── landing
│   │   └── landing.toml
│   │   └── content
│   │   │   └── _index.md
│   │   │   └── images
│   │   │   │   └── image1.jpg
│   │   │   │   └── image2.jpg
└── static
│   └── images
│   │   └── shared-image1.jpg
└── themes
│   └── default
│   │   └── assets
│   │   │   └── sass
│   │   │   └── ts
│   │   └── data
│   │   └── layouts
│   │   │   └── _default
│   │   │   └── partials
│   │   │   │   └── _funcs
│   │   │   │   └── head
│   │   │   │   └── templates
│   │   │   └── shortcodes

and I have config files (sites/blog/blog.toml, sites/landing/landing.toml) similar to the following (shortened):

baseURL = 'https://example.com'
title = "Landing Page"
theme = 'default'
uglyurls = true
publishdir = "public/landing"
contentDir = "sites/landing"

and

baseURL = 'https://blog.example.com'
title = "Blog Page"
theme = 'default'
uglyurls = true
[permalinks]
  [permalinks.page]
    '/' = '/:year/:month/:day/:slug'
publishdir = "public/blog"
contentDir = "sites/blog"

When I build my pages, I do it with the following two Hugo commands:

$ hugo --config="sites/blog/blog.toml"
$ hugo --config="sites/blog/landing.toml"

Then I can upload "public/landing" as my landing page and "public/blog" as my blog page.


I also tried moving the config files into config directories within "sites/blog" and "sites/landing" and build the sites with the following commands"

$ hugo --source='sites/blog'
$ hugo --source='sites/blog'

but that one required a bunch of mounts and the theme path looked similar to "../../../themes/default" which is quite ugly.


Lastly I arrived at using languages for building both sites at once. I generated a single hugo.toml and separated the different sites to different languages:

defaultContentLanguageInSubdir = false
theme = 'default'
uglyurls = true
[languages]
  [languages.en]
    baseURL = 'https://blog.example.com'
    title = "Blog Page"
    contentDir = 'sites/blog'
    weight = 10
    [languages.en.permalinks]
      [languages.en.permalinks.page]
        '/' = '/:year/:month/:day/:slug'
  [languages.fr]
    baseURL = 'https://example.com'
    title = "Landing Page"
    contentDir = 'sites/landing'
    weight = 20

and generated the site using the following single command:

$ hugo --config=langtest.toml

and had both of the sides as public/en and public/fr. There are no translations or different languages but I found this to be the cleanest way to generate multiple related websites. I tried entering an unsupported language code:

# ...
[languages]
  [languages.blog]
# ...
  [languages.landing]
# ...

but that didn't work.

My proposal is to copy the language functionality and rename it to something else, such as sites, so multiple sites can be generated with Hugo at once, just like how languages can be generated.

bep commented 9 months ago

I suspect you're overcomplicating the problem. We have been thinking of adding additional build "dimensions" (e.g. role/rbac), but for that to be worth while, there needs to be a strong relation (e.g. translations) between them. In your case, that link is very week and can easily be maintained manually (e.g. a link from the landing page to the blog).

What I think you need is:

Fethbita commented 9 months ago

I see, yeah that makes sense. That’s what I am doing now, have different configs that use the same theme. I will close the issue. This issue might nevertheless be helpful for those who want a similar approach in the future.

github-actions[bot] commented 8 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.