middleman-blog-similar
is an extension for middleman-blog that adds method to lookup similar article.
Middleman::Blog::BlogArticle#similar_articles
returns an array of Middleman::Blog::BlogArticle
instances.
h2 Similar Entries
ul
- current_article.similar_articles.first(5).each do|article|
li= link_to article.title, article.url
similar_articles
helper is also available in article pages.
h2 Similar Entries
ul
- similar_articles.first(5).each do|article|
li= link_to article.title, article.url
gem 'middleman-blog-similar'
activate :similar
This extension finds similar articles using those are using tags by default.
You can set taggers using tagger:
option. MeCab and EngTagger adopters are built in this extension.
# Find by tags (default)
activate :similar, tagger: :tags
# Using MeCab / Need to add `gem 'natto'` in Gemfile
activate :similar, tagger: :mecab
# Using EngTagger / Need to add `gem 'entagger'` in Gemfile
activate :similar, tagger: :entagger
You can use lambda as tagger
# Resource is a Middleman::Blog::BlogArticle
activate :similar, tagger: ->(resource) { [resource.data.category] }
You can configure multiple taggers both built-in and lambda taggers.
activate :similar, tagger: {
# key = tagger, value = weight
mecab: 1,
entagger: 1,
tags: 3,
# key = (ignored), value[0] = weight, value[1] = lambda
custom: [5, ->(resource) { resource.data.category ? [resource.data.category] : [] }]
}
This extension uses SQLite3 to calculate similarity between articles.
Database location is ${PROJECT_ROOT}/.similar.db
by default.
You can specify database location using db:
option.
# Expands to ${HOME}/similar.db
activate :similar, db: '~/similar.db'
# Expands to ${PROJECT_ROOT}/tmp/middleman-blog-similar.db
activate :similar, db: 'tmp/middleman-blog-similar.db'
# Stores in memory database
activate :similar, db: ':memory:'
Copyright (c) 2014-2017 Atsushi Nagase. MIT Licensed, see LICENSE for details.