Created
May 19, 2022 20:41
-
-
Save manuel-rubio/d3f1461d5d16373d4ee33551974821f9 to your computer and use it in GitHub Desktop.
Reading time extension for Lambdapad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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