minimal-mistakes
minimal-mistakes copied to clipboard
Fix wrong `first_page_path` because of hard-coded `page:num`
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: https://github.com/mmistakes/minimal-mistakes/pull/2431#issuecomment-598026992
If
:num
is used alone (instead ofpage:num
) then the previous code would generate wrong results. I havepaginate_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... https://github.com/Shopify/liquid/issues/862
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.
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.
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.