polyglot icon indicating copy to clipboard operation
polyglot copied to clipboard

jekyll build produces a different result than jekyll server for a language switcher

Open thebravoman opened this issue 1 year ago • 1 comments

This is the language switcher

       {% for tongue in site.languages %}
          <a {% if tongue == site.active_lang %}style="font-weight: bold;"{% endif %} {% static_href %}href="{% if tongue == site.default_lang %}{{page.url}}{% else %}{{site.baseurl}}/{{ tongue }}{{page.url}}{% endif %}"{% endstatic_href %} >{{ tongue }}
          </a>
          {%- if forloop.last == false -%}
            {{"/"}}{{ site.langsep }}
          {%- endif -%}
        {% endfor %}

This is the config

title: My
email: [email protected]
description: >- # this means to ignore newlines until "baseurl:"
  Write an awesome description for your new site here. You can edit this
  line in _config.yml. It will appear in your document head meta (for
  Google search results) and in your feed.xml site description.
baseurl: "" # the subpath of your site, e.g. /blog
url: "" # the base hostname & protocol for your site, e.g. http://example.com

# Build settings
plugins:
  - jekyll-feed
  - jekyll-polyglot

languages: ["en", "bg"]
default_lang: "en"
exclude_from_localization: ["assets"]
parallel_localization: true

Running jekyll serve produces _site/bg/index.html

    <a  href="/" >en
          </a>/
          <a style="font-weight: bold;" href="/bg/" >bg
          </a>

Running jekyll build produces _site/bg/index.html

    <a  href="/bg/" >en
          </a>/
          <a style="font-weight: bold;" href="/bg/" >bg
          </a>

Is this the expected behaviour or am I missing something? You see how the href in the first case is / and in the second it is bg

thebravoman avatar Jun 03 '24 07:06 thebravoman

From what I can tell, there is something in jekyll build/ployglot that sees href= and prepends the language directory to {{page.url}} no matter what. Remove the href= and it gives the correct path (which obviously breaks the HTML).

gilgongo avatar Sep 10 '24 09:09 gilgongo

I know it's way belated, but @george-gca identified that not setting the jekyll configuration url causes different builds with jekyll serve (which automatically sets this to localhost) and jekyll build . A functioning site language switcher requires this to be set, or else all links become implicitly relative.

The polyglot readme has been updated to reflect this. I hope this helps!

untra avatar Jan 10 '25 04:01 untra