What are some good ways to implement breadcrumbs on a Jekyll site?

后端 未结 12 2578
南方客
南方客 2020-12-14 04:47

I\'m aware that there are single-level breadcrumbs in http://raphinou.github.com/jekyll-base/ but I\'m looking for some good ways to have breadcrumbs on a Jekyll sit

12条回答
  •  我在风中等你
    2020-12-14 05:09

    I have improved slightly on the answers given earlier. I have removed the unordered list and seperated the items with a character (forward slash). I have added a filter for 'index.html' and '.html', so urls like 'mysite.com/path/index.html' and 'mysite.com/path/item-name.html' are also supported. Finally I have capitalized the titles. This results in something that looks like this:

    Home / Path / Item name

    {% assign crumbs = page.url | remove:'/index.html' | split: '/' %}
    
    Home
    {% for crumb in crumbs offset: 1 %}
      {% if forloop.last %}
        / {{ crumb | replace:'-',' ' | remove:'.html' | capitalize }}
      {% else %}
        / {{ crumb | replace:'-',' ' | remove:'.html' | capitalize }}
      {% endif %}
    {% endfor %}
    

    PS. I have created an online resource for snippets like this: jekyllcodex.org/without-plugins

提交回复
热议问题