|
1 | 1 | --- |
2 | | -layout: filter |
| 2 | +layout: none |
3 | 3 | title: Filter Posts |
4 | 4 | permalink: /filter.html |
5 | 5 | exclude: true |
6 | 6 | sitemap: false |
7 | 7 | --- |
| 8 | +<!DOCTYPE html> |
| 9 | +<html lang="en"> |
| 10 | +<head> |
| 11 | + <title>{{ site.name }} - {{ page.title }}</title> |
| 12 | + <meta name="author" content='{{ site.author }} | {{ site.email }}'> |
| 13 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 14 | + <link href="{{ site.url }}/css/{{ site.bootstrap.css }}" rel="stylesheet" media="screen"> |
| 15 | + <link href="{{ site.url }}/css/gh-pages-blog.css" rel="stylesheet" media="screen"> |
| 16 | + <link href="{{ site.url }}/css/newsletter.css" rel="stylesheet" media="screen"> |
| 17 | + {% if site.bootstrap.responsive.enabled %} |
| 18 | + <link href="{{ site.url }}/css/{{ site.bootstrap.responsive.css }}" rel="stylesheet"> |
| 19 | + {% endif %} |
| 20 | + {% if site.font_awesome.enabled %} |
| 21 | + <link rel="stylesheet" href="{{ site.url }}/css/{{ site.font_awesome.css }}"> |
| 22 | + {% endif %} |
| 23 | + {% if site.syntax_highlighting.enabled %} |
| 24 | + <link rel="stylesheet" href="{{ site.url }}/css/{{ site.syntax_highlighting.css }}"> |
| 25 | + {% endif %} |
| 26 | + {% if site.rss.enabled %} |
| 27 | + <link rel="alternate" type="application/rss+xml" title="RSS" href="{{ site.url }}/rss.xml" /> |
| 28 | + {% endif %} |
| 29 | + {% if site.favicon.enabled and site.favicon.local.enabled %} |
| 30 | + <link rel="icon" type="image/{{ site.favicon.local.type }}" href="{{ site.url }}{{ site.favicon.local.partial_url }}" /> |
| 31 | + {% elsif site.favicon.enabled and site.favicon.remote.enabled %} |
| 32 | + <link rel="icon" type="image/{{ site.favicon.remote.type }}" href="{{ site.favicon.remote.full_url }}" /> |
| 33 | + {% endif %} |
| 34 | + <script src="{{ site.url }}/js/grafana-faro.js"></script> |
| 35 | +</head> |
| 36 | +<body> |
| 37 | + <!-- Navbar --> |
| 38 | + {% include body/sections/navbar.html %} |
| 39 | + |
| 40 | + <!-- Alerts --> |
| 41 | + {% include body/sections/alerts_and_notices/site.html %} |
| 42 | + |
| 43 | + <div class="container"> |
| 44 | + <div class="row"> |
| 45 | + <div class="span8"> |
| 46 | + <!-- Page Header --> |
| 47 | + <div class="page-header"> |
| 48 | + <h1 id="filter-title">{{ page.title }}</h1> |
| 49 | + </div> |
| 50 | + |
| 51 | + <!-- Alerts --> |
| 52 | + {% include body/sections/alerts_and_notices/page.html %} |
| 53 | + |
| 54 | + <!-- Filter Results --> |
| 55 | + <div id="filter-body"></div> |
| 56 | + </div> |
| 57 | + |
| 58 | + <div class="span3 offset1"> |
| 59 | + <!-- Sidebar --> |
| 60 | + {% include body/sections/brief-bio.html %} |
| 61 | + {% include body/sections/navlists.html %} |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + |
| 65 | + <!-- Newsletter --> |
| 66 | + {% include body/sections/newsletter.html %} |
| 67 | + |
| 68 | + <!-- Footer --> |
| 69 | + {% include body/sections/footer.html %} |
| 70 | + </div> |
| 71 | + |
| 72 | + <!-- JavaScript --> |
| 73 | + {% include body/sections/javascript.html %} |
| 74 | + |
| 75 | + <!-- Filter JavaScript --> |
| 76 | + <script type="text/javascript"> |
| 77 | + var posts = [ |
| 78 | + {% for post in site.posts %} |
| 79 | + { |
| 80 | + "title": {{ post.title | jsonify }}, |
| 81 | + "subtitle": {{ post.subtitle | default: "" | jsonify }}, |
| 82 | + "author": {{ post.author | default: site.author | jsonify }}, |
| 83 | + "description": {{ post.description | default: "" | jsonify }}, |
| 84 | + "url": "{{ site.url }}{{ post.url }}", |
| 85 | + "date": {{ post.date | date_to_long_string | jsonify }}, |
| 86 | + "category": "{{ post.category | default: '' | replace: ' ', '___' | capitalize }}", |
| 87 | + "image": "{% if post.image %}{{ site.url }}{{ post.image }}{% endif %}", |
| 88 | + "tags": [{% for tag in post.tags %}"{{ tag | replace: ' ', '___' | downcase }}"{% unless forloop.last %},{% endunless %}{% endfor %}] |
| 89 | + }{% unless forloop.last %},{% endunless %} |
| 90 | + {% endfor %} |
| 91 | + ]; |
| 92 | + |
| 93 | + var create_post_div = function(post) { |
| 94 | + var post_div = '<div class="ghpb-post"><div class="well ghpb-well-outline">'; |
| 95 | + |
| 96 | + // Add SEO image if available |
| 97 | + if (post.image && post.image.length > 0) { |
| 98 | + post_div = post_div + '<div class="row"><div class="span2"><img src="' + post.image + '" class="img-rounded" style="width: 100%; max-width: 150px; height: auto;"></div><div class="span6">'; |
| 99 | + post_div = post_div + '<h2><a href="' + post.url + '">' + post.title + '</a></h2>'; |
| 100 | + } else { |
| 101 | + post_div = post_div + '<h2><a href="' + post.url + '">' + post.title + '</a></h2>'; |
| 102 | + } |
| 103 | + |
| 104 | + if (post.subtitle !== null && post.subtitle.length > 0) { |
| 105 | + post_div = post_div + '<p>' + post.subtitle + '</p>'; |
| 106 | + } |
| 107 | + |
| 108 | + if (post.description !== null && post.description.length > 0) { |
| 109 | + post_div = post_div + '<p> </p><p>' + post.description + '</p>'; |
| 110 | + } |
| 111 | + |
| 112 | + // Close image column div if image was added |
| 113 | + if (post.image && post.image.length > 0) { |
| 114 | + post_div = post_div + '</div></div>'; |
| 115 | + } |
| 116 | + |
| 117 | + post_div = post_div + '<br><div class="row">'; |
| 118 | + post_div = post_div + '<small><div class="span3 offset1">'; |
| 119 | + |
| 120 | + {% if site.font_awesome.enabled %} |
| 121 | + post_div = post_div + '<i class="fas fa-user"></i> '; |
| 122 | + {% endif %} |
| 123 | + post_div = post_div + 'Authored by ' + post.author + '.<br>'; |
| 124 | + |
| 125 | + {% if site.font_awesome.enabled %} |
| 126 | + post_div = post_div + '<i class="fas fa-pencil"></i> '; |
| 127 | + {% endif %} |
| 128 | + post_div = post_div + 'Published on ' + post.date + '.<br></div><div class="span3">'; |
| 129 | + |
| 130 | + if (post.category !== null && post.category.length > 0) { |
| 131 | + {% if site.font_awesome.enabled %} |
| 132 | + post_div = post_div + '<i class="fas fa-folder-open"></i> '; |
| 133 | + {% endif %} |
| 134 | + post_div = post_div + 'Category: ' + |
| 135 | + '<a href="{{ site.url }}/filter.html?category=' + |
| 136 | + post.category.toLowerCase() + '">' + |
| 137 | + post.category.replace(/___/g, ' ') + |
| 138 | + '</a><br>'; |
| 139 | + } |
| 140 | + |
| 141 | + if (post.tags !== null && post.tags.length > 0) { |
| 142 | + {% if site.font_awesome.enabled %} |
| 143 | + post_div = post_div + '<i class="fas fa-tags"></i> '; |
| 144 | + {% endif %} |
| 145 | + post_div = post_div + 'Tags: '; |
| 146 | + var prev_tag = ''; |
| 147 | + var first_tag = true; |
| 148 | + for (var k = 0; k < post.tags.length; k++) { |
| 149 | + if (prev_tag !== post.tags[k]) { |
| 150 | + prev_tag = post.tags[k]; |
| 151 | + if (first_tag === true) { |
| 152 | + first_tag = false; |
| 153 | + } else { |
| 154 | + post_div = post_div + ', '; |
| 155 | + } |
| 156 | + post_div = post_div + |
| 157 | + '<a href="{{ site.url }}/filter.html?tag=' + |
| 158 | + post.tags[k] + '">'+ |
| 159 | + post.tags[k].replace(/___/g, ' ') + |
| 160 | + '</a>'; |
| 161 | + } |
| 162 | + } |
| 163 | + post_div = post_div + '<br>'; |
| 164 | + } |
| 165 | + |
| 166 | + post_div = post_div + '</div><div class="span1"></div></small></div>'; |
| 167 | + post_div = post_div + '</div></div>'; |
| 168 | + |
| 169 | + return post_div; |
| 170 | + }; |
| 171 | + |
| 172 | + // Improved URL parameter parsing |
| 173 | + var getUrlParameter = function(name) { |
| 174 | + name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); |
| 175 | + var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); |
| 176 | + var results = regex.exec(location.search); |
| 177 | + return results === null ? null : decodeURIComponent(results[1].replace(/\+/g, ' ')); |
| 178 | + }; |
| 179 | + |
| 180 | + var requested_tag = getUrlParameter('tag'); |
| 181 | + var requested_category = getUrlParameter('category'); |
| 182 | + |
| 183 | + // Debug logging |
| 184 | + console.log('Posts array length:', posts.length); |
| 185 | + console.log('Requested tag:', requested_tag); |
| 186 | + console.log('Requested category:', requested_category); |
| 187 | + if (posts.length > 0) { |
| 188 | + console.log('Sample post:', posts[0]); |
| 189 | + } |
| 190 | + |
| 191 | + if (requested_tag === null && requested_category === null) { |
| 192 | + $('#filter-title').html('No category or tag supplied'); |
| 193 | + $('#filter-body').html('<p>A category or a tag must be supplied as a parameter in order to get a filtered list of posts.</p>'); |
| 194 | + } else if (requested_tag !== null) { |
| 195 | + $('#filter-title').html('Posts with tag "' + requested_tag.replace(/___/g, ' ') + '"'); |
| 196 | + var matching_posts = 0; |
| 197 | + for (var i = 0; i < posts.length; i++) { |
| 198 | + if (posts[i].tags !== null) { |
| 199 | + for (var j = 0; j < posts[i].tags.length; j++) { |
| 200 | + if (posts[i].tags[j].toLowerCase() === requested_tag.toLowerCase()) { |
| 201 | + $('#filter-body').append(create_post_div(posts[i])); |
| 202 | + $('#filter-body').append('<br><br>'); |
| 203 | + matching_posts++; |
| 204 | + break; |
| 205 | + } |
| 206 | + } |
| 207 | + } |
| 208 | + } |
| 209 | + if (matching_posts === 0) { |
| 210 | + $('#filter-body').html('<div class="alert alert-info"><strong>No posts found</strong><br>No posts were found with the tag "' + requested_tag.replace(/___/g, ' ') + '". <a href="{{ site.url }}">Browse all posts</a> or try a different filter.</div>'); |
| 211 | + } |
| 212 | + } else { |
| 213 | + $('#filter-title').html('Posts in category "' + requested_category.replace(/___/g, ' ') + '"'); |
| 214 | + var matching_posts = 0; |
| 215 | + for (var i = 0; i < posts.length; i++) { |
| 216 | + if (posts[i].category !== null) { |
| 217 | + if (posts[i].category.toLowerCase() === requested_category.toLowerCase()) { |
| 218 | + $('#filter-body').append(create_post_div(posts[i])); |
| 219 | + $('#filter-body').append('<br><br>'); |
| 220 | + matching_posts++; |
| 221 | + } |
| 222 | + } |
| 223 | + } |
| 224 | + if (matching_posts === 0) { |
| 225 | + $('#filter-body').html('<div class="alert alert-info"><strong>No posts found</strong><br>No posts were found in the category "' + requested_category.replace(/___/g, ' ') + '". <a href="{{ site.url }}">Browse all posts</a> or try a different filter.</div>'); |
| 226 | + } |
| 227 | + } |
| 228 | + </script> |
| 229 | +</body> |
| 230 | +</html> |
0 commit comments