Kotsu icon indicating copy to clipboard operation
Kotsu copied to clipboard

Rethink `page.breadcrumb` and `page.url`

Open ArmorDarks opened this issue 7 years ago • 0 comments

This is just a quick note about weird thing.

After getting Gray Matter and hydrating it with some additional data, it gets current page's breadcrumb in form of Array, and url, as a String.

In most cases literally they means same thing, except few tricky cases, like for / url.

Breadcrumb later re-defined in Nunjucks, by setting it from page.props to page. This is done, so that you could override breadcrumb of any page, for tricky cases, when your page positioned in one place, but you want actually to make it think like it is part of another url (so that appropriate Nav items get active state).

Breadcrumb used for many things, among which are getting of current page props (Gray Matter) and determination should Link be active (if it matches current route) or no.

Unfortunately, all this causes quite weird relation to page.url. They seems to be very similar. Besides, if you redefine page.breadcrumb manually, it will not affect page.url (which is, maybe, expected behavior).

In same time, page.url is quite crucial too, because sometimes it is the only way to get url to certain page. Like when you loop over children of page and outputting links to them.

What we want to have in most cases is to have accurate representation of current route.

I'm getting feeling that one of them is duplicate and should be removed. Not sure though. Need to think about it better.

ArmorDarks avatar Mar 14 '17 15:03 ArmorDarks