Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8997871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:56:51+00:00 2026-06-15T23:56:51+00:00

I have been using Jekyll for a month or two now, I am also

  • 0

I have been using Jekyll for a month or two now, I am also new to Ruby so learning every day.

In my site I want to add the reading time of blog posts, I have found this ruby gem which will let me do it

https://github.com/garethrees/readingtime

I install it in the normal way into my sites root and add the code needed and nothing happens. This isn’t a shock because I have no actually link to it in my sites root?

So it my site looks like this html wise

---
layout: default
---

 <div class="twelve columns">
        <h3>{{ page.title }}</h3>
        <span class="date">Wrote by Josh Hornby</span> 
 <span class="date">Estimated reading time – <%= @article.body.reading_time %> </span>
        <br /> <br />
         <%= @article.body %>
        {{ content }}
         </article>

        <a href="https://twitter.com/intent/tweet?text=Check out this blog by @joshua_hornby - www.joshhornby.co.uk"> <div class="twitter_button"> <img src="/images/twitter.png" alt="twitter-logo" width="50" height="50" /> </div> </a> 
  </div>

    <div class="four columns">
        <h3>Recent Posts</h3>
        <p>Find out what else I've been talking about:</p>
           {% for post in site.related_posts limit: 10 %}
        <ul class="square">
            <li><a class="title" style="text-decoration:none;" href="{{post.url}}"><strong>{{ post.title }}</strong></a>
            {% endfor %}
        </ul>
    </div>

Now I’m not shocked that its not working but my question is how to a install the gem so I can access it in my Jekyll file? Do I need to create a _plugin directory and call it from there? Or won’t it work as its not a jekyll plugin? In that case I may have a little project writing my own Ruby Jekyll plugin.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:56:52+00:00Added an answer on June 15, 2026 at 11:56 pm

    As you have surmised, you cannot call arbitrary ruby commands in your html using <%. Instead, you want to write a plugin which defines a Liquid filter. In your html above, you would use the liquid tag to grab the content of the page. You might want to brush up on liquid-for-designers and liquid-for-programmers as well as the Jekyll notes on writing liquid extensions before we dive in, but I’ll try to explain.

    First, we need to use a Jekyll filter to grab the content of the page, which we will pass to our plugin for analysis. Above you have an @article.body which probably means something to a ruby on rails site, but doesn’t mean anything to Jekyll. As you see in the center of your layout file, the content for the page is simply called content. It is pulled in through a Liquid output, indicated by the {{ }}.

    In place of the line

    <span class="date">Estimated reading time – <%= @article.body.reading_time %> </span>
    

    We want a line that grabs the content and passes it to our plugin:

    <span class="date">Estimated reading time – {{ content | readingtime }} </span>
    

    The vertical bar is a filter, meaning pipe content to the function readingtime and include the output. Now we need to write the plugin itself. In the _plugins directory, we create a ruby script following the standard template for a Liquid filter:

    require 'readingtime'
    module TextFilter
      def readingtime(input)
        input.reading_time
      end
    end
    Liquid::Template.register_filter(TextFilter)
    

    And save the above as something like readingtime.rb in _plugins. It’s kinda self explanatory, but you see this tells ruby to load the gem, and define a filter that takes its input and applies the reading_time function to that string.

    A little note: content will pull in the HTML version of the content, not a plain text string. I don’t know if the readingtime gem needs a plain text string, but you can of course convert between them using a little extra ruby code. If necessary, that’s left as an exercise to the reader (though this might help).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using these files all day... And then suddenly this is now
I have been using TabActivity and I want the tab to display on every
I have been using CI just fine using the MySQL driver. I want to
I've been using Jekyll for a static site (so that its easy to maintain),
We have been using SVN at my workplace for a few years now and
I have been using JIRA for the past 15 months, and now I find
I have been using a class to play sounds using AVAudioPlayer. Since I want
I have a site hosted by GitHub Pages that uses Jekyll, and I've been
I have been using json.NET successfully in projects for some time now without any
I have been using Alaxos CakePHP ACLplugin for my site, which is great. However,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.