Hello,
My site is using following code to display breadcrumbs:
{% assign crumbs = page.url | remove:'/index.html' | split: '/' %}
<a href="/">Home</a>
{% if page.path contains '_posts' %}
/ <a href="/press">Berry Empire Press</a>
/ {{ page.title }}
{% else %}
{% for crumb in crumbs offset: 1 %}
{% if forloop.last %}
/ {{ page.title }}
{% else %}
/
{% if crumbpath + "index.md" in site.static.files %}
<a href="{% assign crumb_limit = forloop.index | plus: 1 %}{% for crumb in crumbs limit: crumb_limit %}{{ crumb | append: '/' | replace:'without-plugin/','without-plugins/' }}{% endfor %}">{{ crumb | replace:'-',' ' | remove:'.html' | capitalize }}</a>
{% else %}
<span>{{ crumb | replace:'-',' ' | remove:'.html' | capitalize }}</span>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
It works well, but it makes each (except the last) crumb clickable, even if there’s no index.md (or index.html) and therefore it can lead users to the 404 page.
Is there a way to check whether each crumb can lead to an actual page, and if not, make it not clickable?
My (unsuccessful) attempt:
{% assign crumbs = page.url | remove:'/index.html' | split: '/' %}
<a href="/">Home</a>
{% if page.path contains '_posts' %}
/ <a href="/press">Berry Empire Press</a>
/ {{ page.title }}
{% else %}
{% for crumb in crumbs offset: 1 %}
{% if forloop.last %}
/ {{ page.title }}
{% else %}
/
{% if crumbpath + "index.md" in site.static_files %}
<a href="{% assign crumb_limit = forloop.index | plus: 1 %}{% for crumb in crumbs limit: crumb_limit %}{{ crumb | append: '/' | replace:'without-plugin/','without-plugins/' }}{% endfor %}">{{ crumb | replace:'-',' ' | remove:'.html' | capitalize }}</a>
{% else %}
<span>{{ crumb | replace:'-',' ' | remove:'.html' | capitalize }}</span>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
Thank you!