Skip to content

Commit

Permalink
Avoid hardcoding breakcrumb links, automatically use link to deepest …
Browse files Browse the repository at this point in the history
…page that exists
  • Loading branch information
quincylvania committed Oct 21, 2024
1 parent d2fd551 commit ac9f77a
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions _includes/breadcrumbs.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<div class="breadcrumbs">
{%- if page.categories.first == "News" -%}
{%- assign url = "/news/" -%}
{%- elsif page.categories.first == "Newsletters" -%}
{%- assign url = "/news/newsletter/" -%}
{%- elsif page.categories.first == "Mappy Hours" -%}
{%- assign url = "/events/mappy-hours/" -%}
{%- elsif page.categories.first == "Out & About" -%}
{%- assign url = "/news/appearances/" -%}
{%- else -%}
{%- assign path_parts = page.url | remove: "index" | split: "/" -%}
{%- if path_parts.size > 2 -%}
{% assign prior_index = path_parts.size | minus: 2 %}
{% assign prior_parts_size = path_parts.size | minus: 1 %}
{% assign part = path_parts | slice: prior_index, prior_index | first %}
{% assign url = path_parts | slice: 0, prior_parts_size | join: "/" | append: "/" %}
{%- endif -%}
{%- endif -%}
{%- if url -%}
<a href="{{url | absolute_url}}">
<svg class="iconsvg"><use xlink:href="#arrow-left"></use></svg>
{% assign part_page=site.documents | find: "url", url -%}
{%- if part_page.title -%}
{{part_page.title}}
{%- else -%}
{% assign derived_label=part | replace: "-", " " | url_decode %}
{% assign derived_label_as_num=derived_label | plus: 0 %}
{% if derived_label.size==2 and derived_label_as_num<=12 %}
{{ page.date | date: "%B" }}
{%- assign path_parts = page.url | split: "/" -%}
{%- if path_parts.size > 2 -%}
{%- assign urlsString = "" -%}
{%- assign composite_url = "" -%}
{%- for part in path_parts -%}
{%- assign composite_url = composite_url | append: part | append: "/" -%}
{%- assign urlsString = urlsString | append: composite_url | append: ";" -%}
{%- endfor -%}
{%- assign urls = urlsString | split: ";" | reverse | slice: 1, 100 -%}
{%- for url in urls -%}
{%- assign part_page = site.documents | find: "url", url -%}
{%- unless part_page -%}
{%- continue -%}
{%- endunless -%}
{%- if part_page.layout == "redirect" and part_page.redirect == page.url -%}
{%- continue -%}
{%- endif -%}
<a href="{{url | absolute_url}}">
<svg class="iconsvg"><use xlink:href="#arrow-left"></use></svg>
{% if part_page.title -%}
{{ part_page.title }}
{%- else -%}
{{derived_label}}
{% assign derived_label=part | replace: "-", " " | url_decode %}
{% assign derived_label_as_num=derived_label | plus: 0 %}
{% if derived_label.size==2 and derived_label_as_num<=12 %}
{{ page.date | date: "%B" }}
{%- else -%}
{{ derived_label }}
{%- endif -%}
{%- endif -%}
{%- endif -%}
</a>
</a>
{%- break -%}
{%- endfor -%}
{%- endif -%}
</div>

0 comments on commit ac9f77a

Please sign in to comment.