Get the current file's read time (i.e. "How long to read") #1123
PuppyGirlBelly
started this conversation in
Templates Showcase
Replies: 3 comments 3 replies
-
I made a small Upgrade. The template converts to Hours and Minutes if over 60 Minutes <%*
const WPM = 255
const words = await tp.file.content.trim().replace(/[^\w\s]/g, "").split(/\s+/).filter((x) => x !== "");
const readTime = Math.ceil(words.length / WPM);
const totalHours = (readTime / 60);
const readHours = Math.floor(totalHours);
const totalMinutes = (totalHours - readHours) * 60;
const readMinutes = Math.round(totalMinutes);
if (readHours != 0)
tR += `${readHours} hour${readHours == 1 ? "": "s"} and `
tR += `${readMinutes} minute${readMinutes == 1 ? "": "s"}`
%> |
Beta Was this translation helpful? Give feedback.
0 replies
-
That's super awesome! Thanks for sharing! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Is there a way to auto-update this every time I open the doc? Maybe if this is turned on a file property? Many documents get increased over time and this would be super useful. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I have spent way too much time
procrastinatingworking on this; so I figured I should try and share so somebody else doesn't have to spend this effort.I like to have a part of my frontmatter to list how long a page is; as I use Obsidian to hold documents I want to read offline. So I created a template that should give an approximate estimate of how long a document is. It's not the most accurate as
tp.file.content
still includes frontmatter; but I have filtered out most non-readable characters so it should give a decent ballpark.Version 1.0
Gist of the script
Inline Template
Let me know of any improvements I can make or any additions folks might need!
Beta Was this translation helpful? Give feedback.
All reactions