Skip to content

Google Search with Multiple languages only returns default language #2299

@johnhansarickWallaroo

Description

@johnhansarickWallaroo

Environment

  • Version of Docsy you are using: v0.12.0
  • How are you using Docsy? As a:
    • Hugo module
    • NPM module
    • Git submodule
    • Other:
  • Version of Hugo you are using (output of hugo version): hugo v0.148.2+extended
  • OS:
    • Linux
    • macOS
    • Windows
    • Other:

Problem

The following is in the Docsy search documentation: https://www.docsy.dev/docs/adding-content/search/ regarding Google Search:

Add your Google Custom Search Engine ID to the site params in hugo.toml/hugo.yaml/hugo.json. You can add different values per language if needed.

Based on this, we have:

contentDir = "content"
defaultContentLanguage = "en"
defaultContentLanguageInSubdir = false

[languages]
  [languages.en]
     [languages.en.params]
        gcs_engine_id="abc123"
  [languages.fr]
     [languages.fr.params]
        gcs_engine_id="zyx987"

So if you go to:

sample.site - enter a search, returns sample.site/search?q=blahdeblah
sample.site/fr - enter a search, returns sample.site/search?q=blahdeblah

In either case, the site it returning the default language as the search parameter. Using the defaultContentLanguageInSubdir = true option just breaks Google search entirely (as related in another ticket).

I've tried playing about with the /assets/js/search.js to tweak the var searchPage = '{{ "search/" | absURL }}?q=' + query; line with absLangURL, but that doesn't make it any happier.

Any recommendations or tips from people who have been through this and found a solution? My only guess is the layouts/_partials/search-input.html used will always default to the default language, but I'm not educated enough to see why.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions