Skip to content

rimenes/retim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Retim

Build Status

Estimate the reading time of a text or a text file

Installation

You can donwload retim or you can install it as package, to use it in your projects. You can found it at Hex. Also you can add retim to your list of dependencies in mix.exs:

def deps do
  [{:retim, "~> 0.2.3"}]
end

Supported languages:

  • English: "en"
  • Greek: "gr"
  • Italian: "it"
  • Spanish: "es"
  • Norwegian: "no"
  • German: "ge"
  • Russian: "ru"
  • Portuguese: "pt"

How to use it

Estimate the reading time of a setence:

iex> Retim.count("Hello World")
"1 minute"

You can change the default language:

iex> Retim.count("Hello World", "it")
"1 minuto"

The average reading time per minute is 180 words. If you want to change it you can pass a second argument:

iex> Retim.count("Hello World", "en", 120)
"1 minute"

If you want to change only the reading time, you need to choose the language or leave the second argument blank:

iex> Retim.count("Hello World", "", 150)

Read words from a file:

iex> Retim.count_file("hello.md")
"4 minutes"

Read a file and change the average reading time to 120 words / per minute:

iex> Retim.count_file("hello.md", "en", 120)
"7 minutes"

Use Retim in Phoenix

Add retim on your dependencies:

 defp deps do
    [{:phoenix, "~> 1.2.1"},
      ........
      ........
     {:cowboy, "~> 1.0"},
     {:retim, "~> 0.2.3"}]
  end

Run deps.get on your terminal:

mix deps.get

Example

Generate a post:

mix phoenix.gen.html Post posts title:string body:text

To count the reading time of the body text, add count(@post.body) on your templates(post/show.html.eex):

<%= Retim.count(@post.body) %>

Result

alt tag

To change the language add:

<%= Retim.count(@post.body, "es") %>

Result (with spanish)

alt tag

To-do

  • Add other languages
  • Add new print format (Example: 3 minutes and 10 seconds)

About

Estimate Reading Time

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 100.0%