|
| 1 | +--- |
| 2 | +layout: blog-default |
| 3 | +title: All Posts |
| 4 | +--- |
| 5 | +<div class="main"> |
| 6 | + <section class="m-all"> |
| 7 | + <h1 class="page-heading">All Posts</h1> |
| 8 | + <div class="tag-wrapper"> |
| 9 | + {% include blog/tags.html %} |
| 10 | + </div> |
| 11 | + |
| 12 | + <!--group by year: http://stackoverflow.com/questions/19086284/jekyll-liquid-templating-how-to-group-blog-posts-by-year--> |
| 13 | + <section class="year-wrapper"> |
| 14 | + {% for post in site.posts %} |
| 15 | + {% assign currentdate = post.date | date: "%Y" %} |
| 16 | + {% if currentdate != date %} |
| 17 | + {% unless forloop.first %}</ul></section>{% endunless %} |
| 18 | + <section id="{{ post.date | date: "%Y" }}"> |
| 19 | + <h1 class="yaer-title" id="year-{{ post.date | date: "%Y" }}">{{ currentdate }}</h1> |
| 20 | + <ul class="post-list"> |
| 21 | + {% assign date = currentdate %} |
| 22 | + {% endif %} |
| 23 | + <li class="post-block {% for tag in post.tags %} tag-{{ tag }} {% endfor %}"> |
| 24 | + <span class="post-date">{{ post.date | date:"%b %d" }}</span><a class="post-link" href="{{ post.url | prepend: site.base_path | replace: '//', '/' }}">{{ post.title }}</a> |
| 25 | + </li> |
| 26 | + {% if forloop.last %}</ul></section>{% endif %} |
| 27 | + {% endfor %} |
| 28 | + </section> |
| 29 | + </section> |
| 30 | +</div> |
| 31 | + |
| 32 | +<script type="text/javascript"> |
| 33 | + // function queryString is copied from |
| 34 | + // http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter#answer-979995 |
| 35 | + function queryString() { |
| 36 | + // This function is anonymous, is executed immediately and |
| 37 | + // the return value is assigned to QueryString! |
| 38 | + var query_string = {}; |
| 39 | + var query = window.location.search.substring(1); |
| 40 | + var vars = query.split("&"); |
| 41 | + for (var i=0;i<vars.length;i++) { |
| 42 | + var pair = vars[i].split("="); |
| 43 | + // If first entry with this name |
| 44 | + if (typeof query_string[pair[0]] === "undefined") { |
| 45 | + query_string[pair[0]] = pair[1]; |
| 46 | + // If second entry with this name |
| 47 | + } else if (typeof query_string[pair[0]] === "string") { |
| 48 | + var arr = [ query_string[pair[0]], pair[1] ]; |
| 49 | + query_string[pair[0]] = arr; |
| 50 | + // If third or later entry with this name |
| 51 | + } else { |
| 52 | + query_string[pair[0]].push(pair[1]); |
| 53 | + } |
| 54 | + } |
| 55 | + return query_string; |
| 56 | + } |
| 57 | + |
| 58 | + function tagSelect(tag) { |
| 59 | + if (tag === undefined || tag === '') { |
| 60 | + $('.page-heading').text('All Posts'); |
| 61 | + $('.article-tag.tag-show-all').focus(); |
| 62 | + $('.post-block').show(); |
| 63 | + } else { |
| 64 | + $('.page-heading').text('Tag: ' + tag); |
| 65 | + $('.post-block').not('.tag-' + tag).hide(); |
| 66 | + $('.article-tag').filter('.tag-' + tag).focus(); |
| 67 | + $('.post-block').filter('.tag-' + tag).show(); |
| 68 | + } |
| 69 | + $('.year-wrapper section').each(function() { |
| 70 | + var li_all_show = false; |
| 71 | + var li_lists = $(this).find('li'); |
| 72 | + for (var i = 0; i < li_lists.length; i++) { |
| 73 | + if($(li_lists[i]).css('display') !== 'none') { |
| 74 | + li_all_show = true; |
| 75 | + break; |
| 76 | + } |
| 77 | + } |
| 78 | + if (li_all_show === false) { |
| 79 | + $(this).hide(); |
| 80 | + } else { |
| 81 | + $(this).show(); |
| 82 | + } |
| 83 | + }); |
| 84 | + tag === undefined || window.history.replaceState(null, '', '{{ "/all.html?tag=" | prepend: site.blog.baseurl }}' + tag); |
| 85 | + } |
| 86 | + |
| 87 | + $(function() { |
| 88 | + var query = queryString(); |
| 89 | + var tag = undefined; |
| 90 | + query.tag === undefined || (tag = decodeURI(query.tag)); |
| 91 | + tagSelect(tag); |
| 92 | + }); |
| 93 | +</script> |
0 commit comments