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

Fix wrong first_page_path because of hard-coded page:num #3778

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

yusanshi
Copy link
Contributor

This is a bug fix.

Summary

In code assign first_page_path = ... | replace: 'page:num', '' | ..., page:num is hard-coded. So if site.paginate_path doesn't ends with page:num/ or page:num, first_page_path will get a wrong value.

The PR tries parsing the last part from site.paginate_path, instead of using a hard-coded page:num.

Context

The same issue with: #2431 (comment)

If :num is used alone (instead of page:num) then the previous code would generate wrong results. I have paginate_path: /blog/:num/ in my config and I expect pages to have URLs like /blog/2/ instead of /blog/page2/, which wasn't available before.

The author of #2413 addressed the issue with Paginate V2. But I'm using GitHub Actions and only V1 is supported so I have to make the fix.


BTW, I'm new to Liquid and "/blog/:num/" | split: "/" returns ["", "blog", ":num"], instead of ["", "blog", ":num", ""] as I expected. Weird... Shopify/liquid#862

@iBug
Copy link
Collaborator

iBug commented Jul 14, 2022

If you're using GitHub Actions, you certainly have the option to use Paginate V2. I suppose you meant "using GitHub Pages", didn't you?

Also, at first glance, your code might break down once Shopify/liquid#862 gets fixed. Correct me if I'm wrong.

It might be a better fix to simply replace :num for your case, which should suffice until someone else comes up with /blog/page-:num, which I don't expect to happen anyways.

@yusanshi
Copy link
Contributor Author

yusanshi commented Jul 15, 2022

Yes I meant "GitHub Pages". Thank you for pointing that out.

I searched with other keywords and finded the same issue #997.

As for Shopify/liquid#862, the split filter in Liquid underlyingly calls split method of Ruby strings:
https://github.com/Shopify/liquid/blob/1fdc577246f400265532c6d9593e7323641ef403/lib/liquid/standardfilters.rb#L252-L261

I have not learned Ruby so I searched on Google and found it should be an expected behavior with Ruby. The split method in Ruby has a second parameter limit and:

If the limit parameter is omitted, trailing null fields are suppressed. If negative, there is no limit to the number of fields returned, and trailing null fields are not suppressed. (From Ruby doc)

Liquid split accept only one parameter and limit is omitted. That's the cause of the weird behavior. See SO.

So I believe if Shopify/liquid#862 is to be fixed, they will add an optional limit parameter, not breaking what it currently is.

@yusanshi
Copy link
Contributor Author

Anyway, changing /page:num/ to /:num/ or /page-:num/ should be a corner case. Closing this PR is OK to me. Someone in need will search, find the PR and get a solution.

@iBug iBug merged commit 495fb29 into mmistakes:master Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants