Skip to content

Instantly share code, notes, and snippets.

@offboarded-x233534
Last active August 29, 2015 14:19
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 offboarded-x233534/47ccb85f667bd2e4cdfe to your computer and use it in GitHub Desktop.
Save offboarded-x233534/47ccb85f667bd2e4cdfe to your computer and use it in GitHub Desktop.
Breadcrumb for Jekyll on GitHub Pages
<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 %}
<li {% if i == forLoopMaxInt %}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>
Copy link

ghost commented May 5, 2015

+1

@offboarded-x233534
Copy link
Author

UPDATE: now works with /page/index.md as well

You can see a full demo project here: https://github.com/comsysto/jekyll-breadcrumb-for-github-pages/

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