Skip to content

Commit

Permalink
add timeline year dropdown auto gen, clean up unique year routine
Browse files Browse the repository at this point in the history
  • Loading branch information
evanwill committed Dec 2, 2018
1 parent 4a882c1 commit 3b312f5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
4 changes: 4 additions & 0 deletions _data/theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ subjectcolor: blue # Leave blank if you just want the link color for bootstrap;
subject-min: 3 # min size for subject cloud, too many terms = slow load time!
stopwords: # need to figure out

# timeline
year-navigation: #"1900;1905;1910;1915;1920" # set years to appear in dropdown nav
year-nav-increment: 5 # set increments when auto gen nav years

# Theme Options
# navbar text color
# Choose from "navbar-light" for use with light background colors, or "navbar-dark" for dark background colors
Expand Down
41 changes: 23 additions & 18 deletions _layouts/timeline.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
---
layout: page
---
{%- if page.year-navigation -%}
{%- assign navYears = "1900;1905;1910;1915;1920;1925;1930;1935;1940;1945;1950;1955;1960" | split: ";" -%}
<ul class="nav nav-pills float-right" id="year-nav">
<li class="nav-item dropdown ">
<a class="nav-link active dropdown-toggle btn btn-pride-gold" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Year</a>
<div class="dropdown-menu">
{% for y in navYears %}
<a class="dropdown-item" href="#{{ y }}">{{ y }}</a>{% endfor %}
</div>
</li>
</ul>
<style>#timeline .img-thumbnail { height: 110px;}</style>
{%- assign items = site.data[site.data.theme.metadata] -%}
{%- assign raw-dates = site.data[site.data.theme.metadata] | map: 'date' | compact | uniq -%}
{%- capture clean-years -%}{% for date in raw-dates %}{% if date contains "-" %}{{ date | strip | split: "-" | first }}{% elsif date contains "/" %}{{ date | strip | split: "/" | last }}{% else %}{{ date | strip }}{% endif %}{% unless forloop.last %};{% endunless %}{%- endfor -%}{%- endcapture -%}
{%- assign uniqueYears = clean-years | split: ";" | uniq | sort -%}

{%- if site.data.theme.year-navigation -%}
{%- assign navYears = site.data.theme.year-navigation | split: ";" -%}
{%- else -%}
{%- capture navYears -%}
{%- for i in uniqueYears -%}{%- assign t = i | modulo: site.data.theme.year-nav-increment -%}
{%- if t == 0 -%}{{ i }}{% unless forloop.last %};{% endunless %}{% endif %}{% endfor %}{%- endcapture -%}
{%- assign navYears = navYears | split: ";" -%}
{%- endif -%}
<div class="dropdown float-right" id="year-nav">
<button class="btn btn-primary dropdown-toggle" type="button" id="yearButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Year
</button>
<div class="dropdown-menu" aria-labelledby="yearButton">
{% for y in navYears %}
<a class="dropdown-item" href="#{{ y }}">{{ y }}</a>{% endfor %}
</div>
</div>

{{ content }}

{% assign items = site.data[site.data.theme.metadata] %}
{% assign raw-dates = site.data[site.data.theme.metadata] | map: 'date' | compact%}
{% capture clean-years %}{% for date in raw-dates %}{% if date contains "-" %}{{date | split: "-" | first }}{% elsif date contains "/" %}{{ date | split: "/" | last }}{% else %}{{ date }}{% endif %}{% unless forloop.last %};{% endunless %}{%- endfor -%}{% endcapture %}
{%- assign years = clean-years | split: ";" | sort -%}
{%- assign uniqueYears = years | uniq | sort -%}

<h3><a href="#{{ years | first }}">{{ years | first }}</a> to <a href="#{{ years | last }}">{{ years | last }}</a></h3>
<h3><a href="#{{ uniqueYears | first }}">{{ uniqueYears | first }}</a> to <a href="#{{ uniqueYears | last }}">{{ uniqueYears | last }}</a></h3>

<table id="timeline" class="table table-striped">
{% for year in uniqueYears %}
Expand Down
1 change: 0 additions & 1 deletion pages/timeline.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Timeline
layout: timeline
year-navigation: "1900;1905;1910;1915;1920"
permalink: /timeline.html
---

Expand Down

0 comments on commit 3b312f5

Please sign in to comment.