Is it Possible to Merge two Hugo Sites after Building each Seprately?

Is it possible to merge two Hugo sites AFTER building each separately?

  • Each site shares the same theme
  • Each site has different sections, but everything else will remain the same.
    For example, site 1 has a /blog section and site 2 has a /portfolio section.

can I do something like

 cd site-1 && hugo && cd --
 cd site-2 && hugo && cd --
 rsync -r site-2 site-1

Yes, but many things will be broken (home page, taxonomy pages, sitemap, RSS, etc.).

Why not build one site, but pull in some of the content as a Hugo module?

1 Like

Yes, merging two or more sites at build time using modules or mounting them from local file system
did cross my mind.

The Problem

The project I am working on is structured using micro-service architecture.
Changes to some section of the website triggers unnecessary CI workload that involves
fetching and re-processing all sorts of data. I wanted to avoid that.

Solution: Break Site into Multiple Standalone Sites

Break the single site into multiple sub-sites( a site per service).
This approach works and minimal(only required) data is moved
during build.

Issue: Resource Duplication

Shared resources, such as CSS, image, and, JS files, are duplicated across
each sites. This is no issue on the server side. However, it does result in a bunch of
unnecessary network requests for clients.

Possible Solutions

So far thee are all I can think of:

  • Merging the sites at build time,which you pointed out won’t work without breaking stuff.
  • Overriding BaseURL: the other approach I was thinking of was overriding the BaseURL only for resources under the themes directory. I know Hugo site config is hierarchical and settings merge, but is overriding BaseURL of a theme without overriding the BaseURL for the rest of the site possible? That is, can I do this:
 |_ config.toml # BaseURL=htttps://
 |_ themes/shared-theme/
    |_ config.toml # BaseURL= (Does this work?)
  • Environment Variables If overriding BaseURL for only theme specific resources files is not possible maybe it is possible to get around it by defining base URL externally. Something like
  env RES_URL=''  hugo

And then use RES_URL to reference resource files like this:

  {{ $base_url := (os.Getenv "RES_URL") }}
  <link rel="stylesheet" href="{{$base_url}}/site.css">

Not as described.

Yes. Or store in a param in site config.

Okay, using params in site config works. Thank you again.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.