Two different sites sharing similar content

Hello,

I find Hugo an excellent platform, and would like to sincerely express my gratitude for the existence of this software. Thank you.

I have a question about running two distinct websites (on different domain name, too) that share some content. It may be easier to illustrate this with two basic examples.

  1. Imagine I have my personal website A and a company website B. Both of them have contents/announcements to keep a section with posts about announcements. Some announcements would be common between the two, and would like not to have to re-write for both sites.
  2. Imagine I have my personal website A and a company website B. Both of them have contents/projects where I maintain a list of projects and pages for individual projects. All the content in projects is shared between the two.

For (2) it is trivial to separate the contents/projects directory to an individual git repo and then use git submodules in each Hugo project that will inherit from that single repo. It’s not as straightforward for (1). Is there any idiomatic way to handle the case where you have 2 sites sharing some content or all content and you want to keep them distinct?

Depending on your operating system, using links (soft or hard) might be possible.

I am on macOS and Linux! That’s not a bad idea! Thank you.

We removed soft link support in v0.123.0.

I would handle #1 and #2 with Hugo modules instead of Git submodules. Here’s an example with a description of how to use it.

One of the many advantages of a Hugo module is that its component directories (e.g., content, assets, layouts, etc.) are merged with the project’s component directories. So, for case #2, maintain non-shared content in their respective project directories, and maintain shared content in a module.

EDIT: Thinking about this, the component directories of a Git submodule are also merged with the project’s component directories, so Hugo modules are not better in this area. Still, I’d use Hugo modules instead.

4 Likes

Thank you. I imagine Hugo modules are capable to handle “private” repositories via SSH authentication with GitHub?