Git Product home page Git Product logo

jekyll-tagging-related_posts's Introduction

jekyll-tagging-related_posts

Test Gem Version Test Coverage Code Climate

Jekyll related_posts function based on tags (works on Jekyll3). It replaces original Jekyll's related_posts function to use tags to calculate relationships.

The calculation algorithm is based on related_posts-jekyll_plugin by @LawrenceWoodman.

Installation

Add this line to your application's Gemfile:

gem 'jekyll-tagging-related_posts'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jekyll-tagging-related_posts

Usage

Edit _config.yml to use the plug-in:

gems:
  - jekyll-tagging-related_posts

Then, add site.related_posts in your post layout page. For example:

{% if site.related_posts.size >= 1 %}
<div>
  <h3>Related Posts</h3>
  <ul>
  {% for related_post in site.related_posts limit: 5 %}
    <li><a href="{{ related_post.url }}">{{ related_post.title }}</a></li>
  {% endfor %}
  </ul>
</div>
{% endif %}

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/toshimaru/jekyll-tagging-related_posts/issues. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

jekyll-tagging-related_posts's People

Contributors

dependabot[bot] avatar elstudio avatar toshimaru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jekyll-tagging-related_posts's Issues

Request to change how relevance is calculated

Please, consider the following example:

tags count match score %
my-post cat dog 2
post-1 ant bee cat cow 4 1 0,1250 12,5%
post-2 ant bee cat cow dog eel fox goat 8 2 0,2500 25,0%
post-3 cat 1 1 0,5000 50,0%
post-4 dog 1 1 0,5000 50,0%
post-5 bee fox 2 0 0,0000 0,0%
post-6 cat dog 2 2 1,0000 100,0%
post-7 0 0 0,0000 0,0%
post-8 cat cow 2 1 0,2500 25,0%
post-9 ant cat dog 3 2 0,6667 66,7%
post-10 ant bee cat cow eel fox goat 7 1 0,0714 7,1%
post-11 ant bee cat dog eel fox goat 7 2 0,2857 28,6%
post-12 cow 1 0 0,0000 0,0%

I want to calculate relevance (score) for my-post with 2 tags: cat dog

So, what I can get very easily and what your plugin is already doing is:

post.count = number of tags for that post
post.match = number of matching tags with my-post (that is your current score, if I'm not mistaking)

I would like to make score more relevant by adding some basic calculation to increase relevance accuracy. At the moment you're using simply number of matching tags, which might not be as accurate and relevant if the fraction of matching tags is much lower than the total number of tags for that post.

Consider post-10 and post-3 from the table above. By using only number of matching tags both those examples are equally relevant with the same number of matching tags. However in practice that is not true. post-3 is much more relevant as it has exactly 1 matching tag with my-post. While post-10 has 7 tags and only 1 tag matches my-post. So obviously that post should be less relevant.

With my calculation post-3 has a score of 50% or 0.5 which is higher and more relevant than post-10 with a score of 7.1% or 0.0714.

The calculation is very simple:

if my-post.count is 0    // avoid division by 0
     there are no relevant posts so set all scores to 0 and exit
endif

for each post do
    if post.count is 0   // avoid division by 0
        score = 0
    else 
        score = ( post.match / post.count ) * ( post.match / my-post.count )
    endif
endfor

What you get is a score which should be type float and between 0 and 1, with 0 no relevance and 1 exact match and most relevant. To change score to percentage just multiply it by 100.

Please consider modifying your excellent plugin as I would really like to have more relevant tags for my project. I would fork and modify your plugin but I don't "speak" ruby, so I have no idea how to implement this myself. Thanks.

Post image?

Hello,

Is it possible to retrieve the post image (as set as image: in the post YAML?

{{ related_post.image }}

And what about other YAML attributes? Is there a way to map them so they are part of the related_post object?

Thanks!

Development mode different from Production Mode

Hello,

When I run my blog on Development Mode, the related posts are as expected. Only the posts with the same tags are shown.

But when I push it to Production Mode, it doesn't work. The Related Posts section show the last posts instead of the related posts.

I installed the jekyll-tagging-related-posts with gem.

My _config.yml:

plugins:
  - jekyll/tagging
  - jekyll-tagging-related_posts

And my HTML:

  {% if site.related_posts.size >= 1 %}
  <div>
    <h3>Related Posts</h3>
    <ul>
      {% for related_post in site.related_posts limit: 5 %}
      <li><a href="{{ related_post.url }}">{{ related_post.title }}</a></li>
      {% endfor %}
    </ul>
  </div>
  {% endif %}

And My Post Header:

---
layout: post
title: My Post Title
category: Category A
tags: [aaa, bbb, ccc]
---

What am I missing here? Can anybody help me, please?

dose it work on gh-pages?

Hello toshimaru

I'm using plugin in my laptop environment and it works well.
But i push my code on github, it doesn't work.
It shows the lasted post.Here is my _config.yml

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.