Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pongstr
Created June 7, 2018 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pongstr/1e4539980a763fb0a564ba48da5d53ca to your computer and use it in GitHub Desktop.
Save pongstr/1e4539980a763fb0a564ba48da5d53ca to your computer and use it in GitHub Desktop.
A simple Jekyll breadcrumb.

Jekyll Breadcrumb

A simple Jekyll breadcrumb without plugin.

{% capture url_tree %}
  {{ page.url | replace: '/', ' ' | strip }}
{% endcapture %}

{% capture url_level %}
  {{ url_tree | number_of_words | minus: 1 }}
{% endcapture %}

{% assign breadcrumb = url_tree | split: ' ' %}

<ol class="breadcrumb">
  <li class="breadcrumb-item">
    <a href="{{ site.baseurl }}">Home</a>
  </li>
{% for item in breadcrumb %}
  {% assign label = item | replace: '-', ' ' | capitalize %}
  {% assign index = forloop.length | minus: forloop.index %}
  {% assign page_url = page.url | split: '/' | pop: index | join: '/' %}
  <li class="breadcrumb-item">
    {% if forloop.last %}
    <span>{{ page.breadcrumb_label | default: label }}</span>
    {% else %}
    <a href="{{ page_url }}/">{{ label }}</a>
    {% endif %}
  </li>
{% endfor %}
</ol>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment