Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong URL for i18 multisite #25

Open
arbinada-com opened this issue Feb 20, 2023 · 0 comments
Open

Wrong URL for i18 multisite #25

arbinada-com opened this issue Feb 20, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@arbinada-com
Copy link

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])
@arbinada-com arbinada-com added the bug Something isn't working label Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant