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
breadcrumbs_trail misbehaves if item identifiers have more than one "." #1278
Comments
Changing this: prefixes
.reject { |pr| pr =~ /^\/index\./ }
.map do |pr|
if pr == ''
@items['/index.*']
else
@items[Nanoc::Identifier.new(pr).without_ext + '.*']
end
end to this: prefixes.push(Nanoc::Identifier.new(prefixes.pop).without_ext)
prefixes
.reject { |pr| pr =~ /^\/index\./ }
.map do |pr|
if pr == ''
@items['/index.*']
else
@items[Nanoc::Identifier.new(pr) + '.*']
end
end
end ... appears to fix the problem in my case, by only stripping the extension from the last prefix (representing the current item itself). I doubt that it's idiomatic Ruby, and I can't find any unit tests to run to see if it would break something else. But it's a start. I can set up a PR if you want one. |
Alas, that quick fix does indeed run into an additional problem with the This variant appears to address that: prefixes.push(Nanoc::Identifier.new(prefixes.pop).without_ext)
prefixes
.reject { |pr| pr =~ /^\/index$/ }
.map do |pr|
if pr == ''
@items['/index.*']
else
@items[Nanoc::Identifier.new(pr) + '.*']
end
end |
I believe that the purpose of
|
There is a fix in #1279 with some fancy functional programming ✨ |
Let #breadcrumbs_trail always find closest parent
Items with more than one "." in their identifier (e.g., "1.6.md") can cause
breadcrumbs_trail
to reference the wrong item.Steps to reproduce
Make items like this:
The breadcrumbs for one or other of the
foo.md
items will refer to the wrong parent.Expected behavior
I'd expect the last element of the breadcrumb trail for an item to always be that item's parent.
Actual behavior
Sometimes the last element of the breadcrumb trail for an item can be an item with a similar name.
Details
It looks like the
breadcrumbs_trail
method for full identifiers is stripping extensions for identifier components other than the last: hereFor example, for
/trp/1.6/software.md
:components
becomes["", "/trp", "/trp/1.6", "/trp/1.6/software.md"]
The identifiers used to construct the prefixes array are:
["/index.*", "/trp.*", "/trp/1.*", "/trp/1.6/software.*"]
Note that
"/trp/1.*"
can match either/trp/1.5.md
or/trp/1.6.md
.It seems to me as if stripping the extension isn't required here, as long as you don't add the
.*
on to the end of the last identifier in the list: that one will already be present as an explicit extension if we're working with full identifiers.I could be missing something, though, I am really not a native Ruby programmer (yet).
The text was updated successfully, but these errors were encountered: