From f3bca594ad86dfbf906c5d80c42c36cf59f16b22 Mon Sep 17 00:00:00 2001 From: agusmakmun <summon.agus@gmail.com> Date: Tue, 19 Apr 2016 16:22:55 +0700 Subject: [PATCH] Update related posts --- _layouts/post.html | 29 +++++++++++++++++++ _posts/2013-12-23-ruby-json.markdown | 2 +- ...2013-12-23-welcome-to-simply-grey.markdown | 2 +- ...-19-email-backend-with-smtp-gmail.markdown | 2 +- ...l-files-pyc-with-recrusive-method.markdown | 2 +- _posts/2016-04-19-welcome-to-jekyll.markdown | 2 +- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/_layouts/post.html b/_layouts/post.html index f2231e7..79cb211 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -7,3 +7,32 @@ layout: default <div class="content"> <div class="post">{{ content }}</div> </div> + +{% assign hasSimilar = '' %} +{% for post in site.posts %} + {% assign postHasSimilar = false %} + {% for tag in post.categories %} + {% for thisTag in page.categories %} + {% if postHasSimilar == false and hasSimilar.size < 6 and post != page and tag == thisTag %} + {% if hasSimilar.size == 0 %} + <div class="panel-body"> + <h4>Related Posts</h4> + <ul> + {% endif %} + <li class="relatedPost"> + <a href="{{ site.url }}{{ post.url }}">{{ post.title }} + {% if post.categories %} + (Categories: {{ post.categories | join: ', ' }}) + {% endif %} + </a> + </li> + {% capture hasSimilar %}{{ hasSimilar }}*{% endcapture %} + {% assign postHasSimilar = true %} + {% endif %} + {% endfor %} + {% endfor %} +{% endfor %} +{% if hasSimilar.size > 0 %} + </ul> + </div> +{% endif %} diff --git a/_posts/2013-12-23-ruby-json.markdown b/_posts/2013-12-23-ruby-json.markdown index 9a299bc..f0da76e 100644 --- a/_posts/2013-12-23-ruby-json.markdown +++ b/_posts/2013-12-23-ruby-json.markdown @@ -2,7 +2,7 @@ layout: post title: "Parsing JSON with Ruby" date: 2013-12-23 00:18:23 +0700 -categories: ruby +categories: [ruby] --- Parsing JSON with Ruby is actually extremely easy. All you have to do is have the json gem installed (`gem install json`) and call the `JSON.parse` method on the JSON data to convert it to ruby hashes. If you look at this small program here, you can see how I have implemented parsing JSON in Ruby. diff --git a/_posts/2013-12-23-welcome-to-simply-grey.markdown b/_posts/2013-12-23-welcome-to-simply-grey.markdown index 1e96a0e..1d4ed27 100644 --- a/_posts/2013-12-23-welcome-to-simply-grey.markdown +++ b/_posts/2013-12-23-welcome-to-simply-grey.markdown @@ -2,7 +2,7 @@ layout: post title: "Welcome to Simply Grey" date: 2013-12-23 00:18:23 +0700 -categories: simplygrey +categories: [simplygrey] --- SimplyGrey is a simple, easy to use theme for Jekyll that compromises of mainly grey colours. A lot of people enjoy the simplistic look of grey and also find it easier to read. diff --git a/_posts/2016-04-19-email-backend-with-smtp-gmail.markdown b/_posts/2016-04-19-email-backend-with-smtp-gmail.markdown index 7227fac..62e2118 100644 --- a/_posts/2016-04-19-email-backend-with-smtp-gmail.markdown +++ b/_posts/2016-04-19-email-backend-with-smtp-gmail.markdown @@ -2,7 +2,7 @@ layout: post title: "Email BackEnd with SMTP Gmail" date: 2016-04-19 02:28:15 +0700 -categories: django +categories: [python, django] --- Add this configurations in your `settings.py` diff --git a/_posts/2016-04-19-remove-all-files-pyc-with-recrusive-method.markdown b/_posts/2016-04-19-remove-all-files-pyc-with-recrusive-method.markdown index 44aaf56..6093cbf 100644 --- a/_posts/2016-04-19-remove-all-files-pyc-with-recrusive-method.markdown +++ b/_posts/2016-04-19-remove-all-files-pyc-with-recrusive-method.markdown @@ -2,7 +2,7 @@ layout: post title: "Remove all files .pyc with recrusive method" date: 2016-04-19 14:39:34 +0700 -categories: python bash +categories: [python, bash] --- This method simple but important. Example in your project dir is like this: diff --git a/_posts/2016-04-19-welcome-to-jekyll.markdown b/_posts/2016-04-19-welcome-to-jekyll.markdown index 8ba4187..2e057b4 100644 --- a/_posts/2016-04-19-welcome-to-jekyll.markdown +++ b/_posts/2016-04-19-welcome-to-jekyll.markdown @@ -2,7 +2,7 @@ layout: post title: "Welcome to Jekyll!" date: 2013-02-19 21:28:15 +0700 -categories: jekyll update +categories: [jekyll, update] --- You’ll find this post in your `_posts` directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run `jekyll serve`, which launches a web server and auto-regenerates your site when a file is updated. -- GitLab