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
Let breadcrumbs trail deal with ambiguity #1368
Conversation
In addition to detecting the case, it would be useful to provide a way of indicating how to break ties (for example by allowing an item attribute with the name of the correct parent item) so that a site with such an ambiguity can be made to work again. |
Hmm, maybe a # pick random parent (probably not great)
breadcrumbs_trail(tiebreaker: -> (candidates) { candidates.sample })
# pick first parent (probably not great either)
breadcrumbs_trail(tiebreaker: -> (candidates) { candidates.first })
# use .md files as identifier
# (if none are found, raise an exception)
breadcrumbs_trail(tiebreaker: -> (candidates) { candidates.find { |c| c.identifier =~ '**/*.md' }}) What do you think? |
If you want to define breadcrumbs around the sequence of components you get from splitting an item's path, that looks like a good solution for most people. Looking at my own use site, though, I'm not sure if I would use that mechanism, and just rely on it to flag errors. This may be a bit of a digression, but my own breadcrumbs issues (in my personal site, not other work) are more complex because of some history which means that the breadcrumb list for an item isn't always directly related to the series of components you get when splitting an item's path: sometimes there's an extra item that needs to be inserted out of hierarchy and some items just have completely different requirements because they live at paths that are entirely unrelated to So the breadcrumbs system on my personal site uses a couple of attributes to:
Sometimes I think that a breadcrumbs implementation that was based entirely on iteratively finding a "crumb parent" for the current item using a strategy function might be better: in my case, the strategy function would use Digression ends. |
FYI, this is what I put as a note to myself in the
|
dfc721c
to
c2af7ef
Compare
c2af7ef
to
4277d9e
Compare
@iay I like the idea of being able to customise the way the breadcrumb chid-parent relationship is set up. I’ll play around with a I’ve added a I’m unsure what the default behavior of ambiguous parent items should be. I’m a fan of error-by-default, but that might make this a non-backwards-compatible change. I say “might” rather than “would,” because the current behavior is undefined, and I believe that changing undefined behavior is backwards-compatible. A better option is likely to log a warning along these lines:
|
Documentation: nanoc/nanoc.app/pull/228 |
This makes
#breadcrumbs_trail
able to deal with ambiguity.Detailed description
Given e.g. the items
When requesting the breadcrumbs trail for /foo/stuff.md, the second item in the breadcrumbs trail might be /foo.md.erb, or /foo.md, or /foo.erb — and
#breadcrumbs_trail
cannot know which one is the one to be used.At the moment, the breadcrumbs trail will contain a random one of them. This isn’t great, because it’s nondeterministic, and this case is probably erroneous.
By default,
#breadcrumbs_trail
will now print a warning:The new
:tiebreaker
option can be used to pick the desired item:The
:tiebreaker
option can also be given the:error
value, which will raise an error:To do
Related issues
n/a