Skip to content

Wrong URL for i18 multisite #25

Description

@arbinada-com

When using i18_multisite plugin the generation of search.toml uses wrong URLs.

For example

[[input.files]]
path = "pages/about_fr.html"
url = "/pages/about_fr.html"

should be

[[input.files]]
path = "pages/about_fr.html"
url = "/fr/pages/about_fr.html"

To solve:

  • add SEARCH_I18_SUBSITE parameter to generator
  • in site configuration add as follows
I18N_SUBSITES = {
    "fr": {
        "SITENAME": "Mon beau site",
        "SEARCH_I18_SUBSITE": "fr"
    }
}

The patch for search.py:

--- ./search.py.bak	2023-02-20 17:00:10.379008769 +0100
+++ ./search.py	2023-02-20 17:19:26.119005800 +0100
@@ -30,6 +30,7 @@
         self.tpages = settings.get("TEMPLATE_PAGES")
         self.search_mode = settings.get("SEARCH_MODE", "output")
         self.html_selector = settings.get("SEARCH_HTML_SELECTOR", "main")
+        self.i18_subsite = settings.get("SEARCH_I18_SUBSITE", None)
 
     def build_search_index(self, search_settings_path):
         if not which("stork"):
@@ -62,6 +63,7 @@
             pages += article.translations
 
         input_files = ""
+        url_i18_prefix = self.i18_subsite + "/" if self.i18_subsite is not None else ""
 
         # Generate list of articles and pages to index
         for page in pages:
@@ -72,7 +74,7 @@
             input_file = f"""
                 [[input.files]]
                 path = "{page_to_index}"
-                url = "/{page.url}"
+                url = "/{url_i18_prefix}{page.url}"
                 title = {dumps(striptags(page.title))}
             """
             input_files = "".join([input_files, input_file])
@@ -86,7 +88,7 @@
             input_file = f"""
                 [[input.files]]
                 path = "{tpage_to_index}"
-                url = "{self.tpages[tpage]}"
+                url = "{url_i18_prefix}{self.tpages[tpage]}"
                 title = ""
             """
             input_files = "".join([input_files, input_file])

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions