BuilderLinks
A ruby gem to generate links automatically based on a text, keywords and urls is given. Useful for example to increase dinamically the internal links in your site and improve SEO metrics.
Installation
Add this line to your Gemfile's application:
gem 'builder_links'
And then execute:
$ bundle
Or install it yourself as:
$ gem install builder_links
Configuration
Use an initializer builder_links.rb
# all parameters based on which allow to find keywords and build the links
# builder_links will use anchortext to find text and uri to generate the link
BuilderLinks.setup do |config|
config.patterns = [
{anchortext: 'google', uri: 'http://www.google.com'},
{anchortext: 'builder links', uri: 'https://github.com/jsanroman/builder_links'},
{anchortext: "I wanted to illuminate the whole earth", uri: 'https://es.wikipedia.org/wiki/Nikola_Tesla'},
]
# maximum links generated to each call
config.total_links = 5
# maximum links generated to each pattern given
config.links_per_pattern = 1
end
Usage
Call directly to BuilderLinks.text("", {black_uris: ['google.com']})
We can add multiple uri's for the black_uris
option to not generate these links
BuilderLinks.text("<p>I wanted to illuminate the whole earth. There is enough electricity to become a second sun.</p>")
#<p><a href="https://es.wikipedia.org/wiki/Nikola_Tesla">I wanted to illuminate the whole earth</a>. There is enough electricity to become a second sun.</p>
Or you can add builder_links
to your activerecord model, that will generate a method builder_links(:field)
class Card < ActiveRecord::Base
attr_accessible :text, :user_text
builder_links
end
# Then you can use builder_links method
Card.find(1).builder_links(:text, {black_uris: ['google.com']})
Card.find(1).builder_links(:user_text)
Contributing
- Fork it ( https://github.com/jsanroman/builder_links/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request