Problem with .Site.GetPage and module mounts?

I’ve got a shortcode - xref - which does the job of ref but uses the title of the target page as the link text.

It works for local pages, and for pages mounted in a module.

However, when I make my site multilingual, and mount my module content using:

module:
  imports:
  - path: github.com/theNewDynamic/gohugo-theme-ananke/v2
  - path: github.com/honzik20/hugo-module-test
    mounts:
    - source: content/en/
      target: content/
      lang: en
    - source: content/fr/
      target: content/
      lang: fr

Hugo can’t find the xref target pages mounted in the module.

I’ve created two Github repos to reproduce the problem:

Run Hugo-testbed and the module xref works fine. In hugo.yml I’ve added comments how to reproduce the bug.

Would be grateful if someone could help me figure this out.

your module is not available link is github link broken and the module cannot be mounted

short hint without test: if you want to use content from your site, too. you must mount the content folder,too. see default mounts

your xref shortcode looks a little strange.

  • In a multilinual site {{ $xrefPage := .Site.GetPage $xrefPath -}} is a lookup in the current language.
  • the range loops of ALL pages in ALL languages and ignores other but current. looks like site.Pages should be enough here.
  • how about duplicate names in different folders?

p.s. such transformation could be done with a render hook fe [target]()Target

1 Like

Thanks for looking. For some reason, my module repo was Private - it’s Public now. I’ve also removed the multilingual nonsense from the shortcode.

hugo mod vendor

Errror: cannot vendor module “GitHub - honzik20/hugo-module-test”, need at least one mount

Your config file is trying to mount the module’s en and fr directories, but they don’t exist. I’m not sure what you’re trying to do with these mounts.

The intent of the cascade is also unclear:

cascade:
 - _target:
    path: /fr/**
    lang: fr
 - _target:
    path: /en/**
    lang: en

And this content seems to be orphaned (i.e., doesn’t belong to any language):

  • content/snippets/
  • content/test-shortcode.md
  • content/_index.md

let’s remove config “nonsense” mentioned and get some promising result

  • defaultContentLanguage ← always a good idea

  • defaultContentLanguageInSubDir ← cleaner, comparable folder structure

  • two module imports

  • two languages
    these language ContentDirs result in mounts for the project (no extra mount necessary)

  • you also had (commented) mounts below import, imho that’s not valid.
    In general the module tells us what it wants to share. In the project restrict that using Merge configuration settings. I’m not an expert on these.

hugo.yaml

baseURL: https://example.org/
languageCode: en-us
defaultContentLanguage: en
defaultContentLanguageInSubDir: true

title: My New Hugo Site
module:
  imports:
  - path: github.com/theNewDynamic/gohugo-theme-ananke/v2
  - path: github.com/honzik20/hugo-module-test

languages:
  en:
    title: Help
    languageName: English
    weight: 1
    contentDir: "content/en"
  fr:
    title: Aide en ligne
    languageName: French
    weight: 1
    contentDir: "content/fr"

The module content is single language, so lets export it for both languages

hugo-module-test/hugo.yaml

module:
  mounts:
    - source: content/
      target: content/
      lang: en
    - source: content/
      target: content/
      lang: fr

Thanks both. @irkode , I had no idea that you placed the mounts in the donor module, not the receiver.