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, 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:
site
|_ config.toml # BaseURL=htttps://example.com
.
.
.
|_ themes/shared-theme/
|_ config.toml # BaseURL=https://assets.example.com (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='https://assets.example.com' hugo
And then use RES_URL to reference resource files like this: