Skip to content

Instantly share code, notes, and snippets.

@offboarded-x233534
Created March 14, 2016 09:57
Show Gist options
  • Save offboarded-x233534/8f7beef9858c1b8625d6 to your computer and use it in GitHub Desktop.
Save offboarded-x233534/8f7beef9858c1b8625d6 to your computer and use it in GitHub Desktop.
automatic jekyll breadcrumb
<ol class="breadcrumb">
<li><a href="{{ site.baseurl }}/">Home</a></li>
{% capture page_url_without_index_html %}{{ page.url | remove: "/index.html" }}{% endcapture %}
{% assign splitted_url_parts = page_url_without_index_html | split: '/' %}
{% capture forLoopMaxInt %}{{ splitted_url_parts.size | minus:1 }}{% endcapture %}
{% for i in (1..forLoopMaxInt) %}
{% capture current_breadcrumb_url %}{{next_prepender}}/{{ splitted_url_parts[i] }}/index.html{% endcapture %}
{% capture current_breadcrumb_md_url %}{{next_prepender}}/{{ splitted_url_parts[i] }}/{% endcapture %}
{% capture next_prepender %}{{next_prepender}}/{{ splitted_url_parts[i] }}{% endcapture %}
{% for breadcrumb_page in site.pages %}
{% if current_breadcrumb_url == breadcrumb_page.url or current_breadcrumb_md_url == breadcrumb_page.url %}
{% assign j = forLoopMaxInt | plus: 0 %}
<li {% if i == j %}class="active"{% endif %}>
{% capture breadcrumb_page_page_url_without_index_html %}{{ breadcrumb_page.url | remove: "index.html" }}{% endcapture %}
<a href="{{ site.baseurl }}{{breadcrumb_page_page_url_without_index_html}}">{{breadcrumb_page.breadcrumb}}</a>
</li>
{% endif %}
{% endfor %}
{% endfor %}
</ol>
@Potherca
Copy link

It might be worth noting the license for this gist. Based on the source repository :

https://github.com/comsysto/jekyll-breadcrumb-for-github-pages

License

The code is licensed under the CC0 1.0 - Public Domain License. Author is comSysto GmbH.

@dhhepting
Copy link

dhhepting commented May 17, 2018

Thanks for this gist.
For Bootstrap 4.1.1 breadcrumbs, the markup has changed a bit, and the active item doesn't need link. I've made these changes in my fork of this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment