@rathnasgala/theme 0.0.20 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import '../assets/theme-mode.js';
2
+ import '../assets/preferences.js';
3
+ import '../assets/interactions.js';
4
+ import '../assets/search.js';
5
+ import '../assets/engagement-comments.js';
@@ -31,6 +31,7 @@ export default class ValidatedPostPages {
31
31
  postTableOfContents: ({ post }) => post?.publicationState === 'published'
32
32
  ? renderedDocument(post).tableOfContents
33
33
  : [],
34
+ readingMinutes: ({ post }) => readingMinutes(post?.body),
34
35
  seo: ({ post, site }) => post?.publicationState === 'published'
35
36
  ? postSeo({ post, site, renderedHtml: renderedDocument(post).html })
36
37
  : null
@@ -46,6 +47,11 @@ export default class ValidatedPostPages {
46
47
  }
47
48
  }
48
49
 
50
+ function readingMinutes(markdown) {
51
+ const words = String(markdown ?? '').trim().match(/[\p{L}\p{N}]+(?:['’_-][\p{L}\p{N}]+)*/gu)?.length ?? 0;
52
+ return Math.max(1, Math.ceil(words / 225));
53
+ }
54
+
49
55
  const renderedDocuments = new WeakMap();
50
56
 
51
57
  function renderedDocument(post) {