diff --git a/app/app.php b/app/app.php index 9542152..9a0bf2b 100644 --- a/app/app.php +++ b/app/app.php @@ -27,6 +27,18 @@ $app['twig'] = $app->share($app->extend('twig', function($twig) { return $twig; })); +$app['twig'] = $app->share($app->extend('twig', function($twig) { + $twig->addFilter(new Twig_SimpleFilter('getReadingTime', function ($text) { + $word = str_word_count(strip_tags($text)); + $minutes = floor($word / 200); + $seconds = floor($word % 200 / (200 / 60)); + $time = array('minutes' => $minutes, 'seconds' => $seconds); + + return $minutes; + })); + return $twig; +})); + $app->register(new ConsoleServiceProvider(), [ 'console.name' => 'Poche console', 'console.version' => '0.1', diff --git a/app/views/_entry.twig b/app/views/_entry.twig index 9f54da7..fe32d4b 100644 --- a/app/views/_entry.twig +++ b/app/views/_entry.twig @@ -6,5 +6,6 @@
  • {% if entry.bookmark == 1 %}{{ 'unstar'|trans }}{% else %}{{ 'star'|trans }}{% endif %}
  • {{ 'delete'|trans }}
  • {{ entry.url | getDomain }}
  • +
  • {{ entry.content | getReadingTime }} {{'min read'|trans}}
  • \ No newline at end of file