Linking Hugo's websites to each other

Hello,
I have 5 hugo sites linked together (website, blog, news, store, edu) and each site has its own subdomain, and its own Github repository.

The home page should display the latest 5 pages of each site, how can I do that with hugo?

Your main page should also run Hugo and then use Hugo Modules for the content.

For example, this is what I have in my /config/_default/modules.toml file:

[[imports]]
  path = "gitlab.com/youronlyone/content"
  # BGN: /yuki/ content
    [[imports.mounts]]
      source = "yuki/en-ph"
      target = "content"
      lang = "en-ph"
    [[imports.mounts]]
      source = "yuki/ja"
      target = "content"
      lang = "ja"
    [[imports.mounts]]
      source = "yuki/ko"
      target = "content"
      lang = "ko"
  # END: /yuki/ content

  # BGN: /snoworld/ content
    #[[imports.mounts]]
    #  source = "snoworld/en-ph"
    #  target = "content"
    #  lang = "en"
    [[imports.mounts]]
      source = "snoworld/en-ph"
      target = "content"
      lang = "en-ph"
    [[imports.mounts]]
      source = "snoworld/ja"
      target = "content"
      lang = "ja"
    [[imports.mounts]]
      source = "snoworld/ko"
      target = "content"
      lang = "ko"
  # END: /snoworld/ content

  # BGN: /techmagus/ content
    [[imports.mounts]]
      source = "techmagus/en-ph"
      target = "content"
      lang = "en-ph"
    [[imports.mounts]]
      source = "techmagus/ja"
      target = "content"
      lang = "ja"
    [[imports.mounts]]
      source = "techmagus/ko"
      target = "content"
      lang = "ko"
  # END: /techmagus/ content

As you will notice, my /yuki/ blog pulls content from /snoworld/, /techmagus/ (to mention a few), and from itself /yuki/. When it is generated, all posts in these sites appear in /yuki/. You don’t need to create a separate repo for your content (it’s just my personal preference), just change the source parameter accordingly.

You can read more about Hugo Modules here: Hugo Modules

If you want to take a look at my setup see this repo. (By the way, I am using /config/ folder format for my config settings.)

As for displaying only the latest 5 posts from each site … I’m not sure how to do that, I haven’t tried it. When the content are imported, I’m not sure if it’s possible to query which mount source it came from. Maybe there is another way to filter posts that I’m not familiar with.

1 Like

An alternative option: Have each site generate a JSON file which lists the latest content. Then use a remote data file on the home page to download each JSON file from the separate sites on build. Then you can access the content like a regular data file.

2 Likes