untra / polyglot

:abc: Multilingual and i18n support tool for Jekyll Blogs
https://polyglot.untra.io
MIT License
394 stars 58 forks source link

Bugfix website older and newer page button #175

Closed aturret closed 1 year ago

aturret commented 1 year ago

🔤 Polyglot PR

For browsing the website, the order and newer button don't work correctly when not on the home page.

When translating the website into Simplified Chinese(🤭will make a pull request soon), I found this bug and tested it on my device.

If you click on the order button or newer button on /page2/, you would get a page 404. This is because the href attribute of the page buttons is not written in the correct format.

The code of the buttons is on indexl.html:


<div class="pagination">
  {% if paginator.next_page %}
    <a class="pagination-item older" href="{{ site.baseurl }}page{{paginator.next_page}}">Older</a>
  {% else %}
    <span class="pagination-item older">Older</span>
  {% endif %}
  {% if paginator.previous_page %}
    {% if paginator.page == 2 %}
      <a class="pagination-item newer" href="{{ site.baseurl }}">Newer</a>
    {% else %}
      <a class="pagination-item newer" href="{{ site.baseurl }}page{{paginator.previous_page}}">Newer</a>
    {% endif %}
  {% else %}
    <span class="pagination-item newer">Newer</span>
  {% endif %}
</div>

This causes generating wrong page URLs. For example, if you click on the newer button on page3, the final URL you get by the button would be /page3/page2 but not /page2

image

image

Solution:

Just add a / at the beginning of the href attributes of the a tags:


<div class="pagination">
  {% if paginator.next_page %}
    <a class="pagination-item older" href="/{{ site.baseurl }}page{{paginator.next_page}}">Older</a>
  {% else %}
    <span class="pagination-item older">Older</span>
  {% endif %}
  {% if paginator.previous_page %}
    {% if paginator.page == 2 %}
      <a class="pagination-item newer" href="/{{ site.baseurl }}">Newer</a>
    {% else %}
      <a class="pagination-item newer" href="/{{ site.baseurl }}page{{paginator.previous_page}}">Newer</a>
    {% endif %}
  {% else %}
    <span class="pagination-item newer">Newer</span>
  {% endif %}
</div>

I have tested it on my device, it worked well.

Type of change

Checklists

untra commented 1 year ago

thank you @aturret ! Good find. I'm going to merge this in and redeploy the site shortly.

I'm working on some test writing / CI improvements that can assist with validating #174 for correctness, and I'll prep a 1.6.0 release that can feature the simplified chinese language support, and give you the full credits in a new blogpost there.

I really appreciate the assistance with this project. I'm not a full time ruby dev and this project needs a fresh coat of paint. Your PR and effort is the kick-in-the-pants I need to get some improvements made. Cheers!