Skip to content

Instantly share code, notes, and snippets.

@manuel-rubio
Created May 19, 2022 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuel-rubio/d3f1461d5d16373d4ee33551974821f9 to your computer and use it in GitHub Desktop.
Save manuel-rubio/d3f1461d5d16373d4ee33551974821f9 to your computer and use it in GitHub Desktop.
Reading time extension for Lambdapad
@doc """
A transformation for items. Analyze the content configuring a new value in the metadata
called `reading_time`.
"""
transform "reading_time" do
set on: :item
set run: fn(post, _config) ->
words_count =
post["content"]
|> String.replace(~r/@|#|\$|%|&|\^|:|_|!|,/u, " ")
|> String.split()
|> length()
Map.put(post, "reading_time", max(1, div(words_count, 200)))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment