0

I have this jekyll code but it's not ideal. Currently, if you visit a page with a structure of example.com/careers/job-postings/ it comes out fine, as Home / Careers / Job Postings. But if you go back to careers, it's Home / Careers / Careers. Each one has the last child as non-linked. How can I get rid of the redundancy or generally improve this logic? (I grabbed most of this code from elsewhere.)

<div class="breadcrumbs">
  <div class="wrap">
      {% capture url_parts %} {{ page.url | remove: "/index.html" | replace:'/'," " }}{%     endcapture %}
    {% capture num_parts %}{{ url_parts | number_of_words | minus: 0 }}{% endcapture %}
    {% assign previous="" %}
    <ol>
    {% if num_parts == "0" or num_parts == "-1" %}
        <li><a href="/">home</a> &nbsp; </li>
    {% else %}
    <li><a href="/">home</a></li>

    {% for unused in page.content limit:num_parts %}
        {% capture first_word %}{{ url_parts | truncatewords:1 | remove:"..."}}{% endcapture %}
        {% capture previous %}{{ previous }}/{{ first_word }}{% endcapture %}

        <li><a href="{{previous}}">{{ first_word }}</a></li>

        {% capture url_parts %}{{ url_parts | remove_first:first_word }}{% endcapture %}
        {% endfor %}
    {% endif %}

    {% unless page.title == first_word %}

        <li>{{ page.title }}</li>

    {% endunless %}

    </ol>
</div>

2
  • Off-Topic; try CodeReview.StackOverflow instead.
    – TylerH
    May 12, 2014 at 18:01
  • If you want to improve your code, you really should ask on Code Review as TylerH suggested. May 15, 2014 at 19:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.