Closed thopanX closed 1 year ago
the content variable outputs html and the length filter does not accept it. You should create a plugin that counts the length of the pure markdown content and then output it in the template.
Alright, thanks.
12.09.2022 09:54:15 trendschau @.***>:
the content variable outputs html and the length filter does not accept it. You should create a plugin that counts the length of the pure markdown content and then output it in the template.
— Reply to this email directly, view it on GitHub[https://github.com/typemill/typemill/issues/359#issuecomment-1243351906], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAN3C4LCSM52ESSIF6VSWNDV53ORTANCNFSM6AAAAAAQJBIQT4]. You are receiving this because you authored the thread.[Verfolgungsbild][https://github.com/notifications/beacon/AAN3C4KN5KBIYBAXDQNGR23V53ORTA5CNFSM6AAAAAAQJBIQT6WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSKDQFWE.gif]
or maybe even better: try a frontend solution with JS, I am sure that there are tons of libraries for that :D
I've decided to learn how to code plugins for Typemill, and am working through the documentation/tutorial. Found a 404:
https://typemill.net/plugin-developers/tutorial/write-the-php-file > You can find a list of all events in the Event Overview in the documentation](https://typemill.net/for-plugin-developers/documentation/event-overview)
. > The correct URL is https://typemill.net/plugin-developers/event-overview
Same 404 in https://typemill.net/plugin-developers/tutorial/add-methods > You can find more details in the [event overview](https://typemill.net/for-plugin-developers/documentation/event-overview).
I have to correct myself: content|length in templates work totally fine for me and it is also possible to strip tags with content|striptags|length
I will close this because there is no issue.
For other users, this is what I've come up with without any plugin work, just using Twig's features:
Auf Deutsch: https://thopan.uber.space/blog/lesezeit-hinzugefuegt
Appr. Reading time: {% set contentLength = content|striptags|length %} {{ contentLength // 1000 }} minutes
{% set contentLength = content|striptags|length %}
– set the variable contentLength
to the page content
's length, stripped of its HTML.{{ contentLength // 1000 }} minutes
– display the variable after dividing it by 1.000 characters which is the approximate reading speed per minute (200 words per minute with a mean length of 5 characters per word).page.twig
, right above {{ content }}.
plus into the file posts.twig
in the partials folder to have the info on the blog article overview.If the content's length is less than 1.000 characters and thus returns “0 minutes“ (the output is floored), you can wrap the stuff with an if-statement and output something like “less than a minute“ in this case.
Hope this helps.
thank you for sharing!
Can somebody give me a hint on how to get the number of characters in the content variable–so I can calculate an approximate reading time? I found twig's length filter, but when I try to output it via
{{content|length}}
the webserver returns an error 500.