Skip to content

Instantly share code, notes, and snippets.

@dhhepting
Forked from offboarded-x233534/header_breadcrumb.html
Last active August 13, 2018 20:39
Show Gist options
  • Save dhhepting/877cd31b7f9ead5c0eb88bcb1a982adf to your computer and use it in GitHub Desktop.
Save dhhepting/877cd31b7f9ead5c0eb88bcb1a982adf to your computer and use it in GitHub Desktop.
automatic jekyll breadcrumb
{%- comment -%}
Updated for boostrap 4
-- https://getbootstrap.com/docs/4.0/components/breadcrumb/ --
and does not create a link for the last (active) item
{%- endcomment -%}
{%- assign url_parts = page.url | split: '/' -%}
{%- capture loop_max -%}{{ url_parts.size | minus: 1 }}{%- endcapture -%}
{%- assign j = loop_max | plus: 0 -%}
{%- assign bc_path = "/" -%}
{%- comment -%}
the result of following assignment (if successful) will be an array,
so bc_page[0] is used to get the page corresponding to the path
{%- endcomment -%}
{%- assign bc_page = site.pages | where: "url", bc_path -%}
<div class="card-header">
<nav aria-label="breadcrumb">
<ol class="breadcrumb card-header lightcthru">
<li class="breadcrumb-item">
<a href="{{ bc_path | relative_url }}">
{{ bc_page[0].breadcrumb }}
</a>
</li>
{%- for i in (1..loop_max) -%}
{%- capture bc_path -%}{{bc_path}}{{url_parts[i]}}{%- endcapture -%}
{%- unless bc_path contains ".html" -%}
{%- capture bc_path -%}{{bc_path}}/{%- endcapture -%}
{%- endunless -%}
{%- comment -%}
the result of following assignment (if successful) will be an array,
so bc_page[0] is used to get the page corresponding to the path
{%- endcomment -%}
{%- assign bc_page = site.pages | where: "url", bc_path -%}
{% if bc_page and i < j %}
<li class="breadcrumb-item">
<a href="{{ bc_path | relative_url }}">
{{ bc_page[0].breadcrumb }}
</a>
</li>
{% elsif bc_page and i == j %}
<li class="breadcrumb-item active">
{{ bc_page[0].breadcrumb }}
</li>
{% endif %}
{%- endfor -%}
</ol>
</nav>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment