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

page.url variable pointing to wrong page (post) #187

Closed
yonz2 opened this issue Dec 19, 2023 · 7 comments
Closed

page.url variable pointing to wrong page (post) #187

yonz2 opened this issue Dec 19, 2023 · 7 comments

Comments

@yonz2
Copy link

yonz2 commented Dec 19, 2023

Hi all,

I'm trying to put up a multi-lingual website (initially, bilingual: English and German).
i installed jekyll-polyglot, created content pages in both languages, e.g. home-en.md, home-de.md, about-en.md and about-de.md all with front matter set like: (note: I am using the Minimal Mistakes theme

---
layout: single
title: Über uns
permalink: /about/ # the home-xx.md has "/" as permalink
lang: de
---

I also created a couple of test posts, each with front matter similar to:

---
layout: single
title:  "Welcome to Jekyll!"
date:   2023-12-18 00:08:32 +0000
categories: jekyll update
lang: de
---

Then I copied a simple language switcher from github:

{% for lang in site.languages %}
    {% assign lang_name = site.data[lang].l10n.lang_name %}
    {% if lang == site.active_lang %}
        <i>{{ lang_name }}</i>
    {% else %}
        {% if lang == site.default_lang %}
            <a href=" {{ page.url }}">{{ lang_name }}</a>
        {% else %}
            <a href="/{{ lang }}{{ page.url }}">{{ lang_name }}</a>
        {% endif %}
    {% endif %}
{% endfor %}

placed it in the lang-switcher.html inside the _include directory and included that file in the masthead.html file in the same directory.

        <div class="lang-switcher">
          {%- include lang-switcher.html -%}
       </div>

This is where the "fun" starts:

When I render my site using bundle exec jekyll build the page.url variable returns a value pointing to one of the posts. For example this is what's rendered in the German about file at _site/de/about/index.html:

        <div class="lang-switcher">
               <a href=" /test/2023/12/18/test-post-de/">English</a>
               <i>Deutsch</i>
        </div>

Expected Results:

        <div class="lang-switcher">
               <a href=" /about/">English</a>
               <i>Deutsch</i>
        </div>

So here's my question. What can i do to get the correct url in my language switcher?

My Environment:

jekyll (4.3.2)
    Authors: Tom Preston-Werner, Parker Moore, Matt Rogers
    Homepage: https://jekyllrb.com
    License: MIT
    Installed at: /usr/local/rvm/gems/ruby-3.2.2

    A simple, blog aware, static site generator.
jekyll-polyglot (1.7.0)
    Author: Samuel Volin
    Homepage: https://polyglot.untra.io/
    License: MIT
    Installed at: /usr/local/rvm/gems/ruby-3.2.2

    I18n plugin for Jekyll Blogs
minimal-mistakes-jekyll (4.24.0)
    Author: Michael Rose
    Homepage: https://github.com/mmistakes/minimal-mistakes
    License: MIT
    Installed at: /usr/local/rvm/gems/ruby-3.2.2

    A flexible two-column Jekyll theme.
    
Server: Linux codespaces-ac7cc6 6.2.0-1018-azure #18~22.04.1-Ubuntu SMP Tue Nov 21 19:25:02 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

@yonz2
Copy link
Author

yonz2 commented Dec 21, 2023

I added some debug code to try to find out what's happening. The page.url variable is always set to the url of the first post and the page.permalink variable is always empty.

      <br/><span>Page-url: {{ page.url }} # Page-Permalink: {{ page.permalink }} # </span>

results in:

<span>Page-url: /ai/2023/11/15/ai-itsm-en.html # Page-Permalink:  # </span>

@untra
Copy link
Owner

untra commented Dec 21, 2023

Hey there @yonz2 👋
does the /ai/2023/11/15/ai-itsm-en.md post have a defined url or permalink?

Jekyll uses a default url format based on the post's date and title:

  • Format: /:year/:month/:day/:title.html
  • Example: /2023/12/21/my-post-title.html

when a permalink is not defined, the url gets inferred like that. that looks like what's happening here.

I cannot help you debug markdown specific problems further without access to your repo though. care to share?

@yonz2
Copy link
Author

yonz2 commented Jan 2, 2024

Happy New Year!

The repo https://github.com/yonz2/netinnovate is public.

This seems to be a general issue with all page variables.

Here is another debug code: (See: lang-switcher.html)

  <select id="language-switcher-select" autocompletion="off" onchange="window.location.href = this.value;">
    {% for lang in site.languages %}
      <option value="{{ lang }}" {% if lang==page.lang %}selected{% endif %}>{{ site.data[lang].l10n.lang_name }}</option>
      <!--  {{ lang }} , {{ page.lang }}, {{ site.default_lang }}, {{ page.title }} -->
    {% endfor %}
  </select>

Results:

  <select id="language-switcher-select" autocompletion="off" onchange="window.location.href = this.value;">
    
      <option value="en" selected>English</option>
      <!--  en , en, en, Revolutionizing ITSM with AI: Automating Issue Classification and Resolution -->
    
      <option value="de" >Deutsch</option>
      <!--  de , en, en, Revolutionizing ITSM with AI: Automating Issue Classification and Resolution -->
    
  </select>

The page.title output, is the title from the first blog post, NOT from the current page being processed

(BTW: I changed the way I'm dealing with the language switcher, but the problem with the page variables remains

Any help will be much appreciated
Yonz

@untra
Copy link
Owner

untra commented Jan 2, 2024

The page.title output, is the title from the first blog post, NOT from the current page being processed

So... you're saying you always see Revolutionizing ITSM with AI: Automating Issue Classification and Resolution displayed for the title of every page? jekyll page variables like page.title are fairly high level, this shouldn't be affected by polyglot at all.

Otherwise the lang-switcher.html behavior and <!-- outputs look right if rendered for this page. I do notice however it specifies in the frontmatter layout: single and I don't see that single.html layout specified in the repo includes? That smells to me.

@yonz2
Copy link
Author

yonz2 commented Jan 2, 2024

Hi,

the file single.html is a layout from the Minimal Mistakes theme usually located at: /usr/local/rvm/gems/ruby-3.2.2/gems/minimal-mistakes-jekyll-4.24.0/_layouts/single.html. I've now copied the default.html and single.html files to the repo.

The output is from _site/de/about/index.html the corresponding markdown file about-de.md has the following frontmatter:

---
layout: single
title: Über uns
permalink: /about/
page-id: about
header:
  overlay_image: /assets/images/NetInnovate_TitleImage.png
lang: de
toc: false
---

So you can see that both page.lang and page.title are output incorrectly (I've added the ./_site folder to the repo)

@yonz2
Copy link
Author

yonz2 commented Jan 3, 2024

Hi,
I opened an issue on the jekyll repo as well (jekyll/jekyll#9519)

@untra
Copy link
Owner

untra commented Jan 10, 2024

I'm not sure I can help ya here, sorry.

@untra untra closed this as completed Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants