File tree 1 file changed +9
-1
lines changed
packages/experiments-realm
1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import { Author } from './author';
22
22
import { formatDatetime , BlogApp as BlogAppCard } from ' ./blog-app' ;
23
23
import { BlogCategory , categoryStyle } from ' ./blog-category' ;
24
24
import { User } from ' ./user' ;
25
+ import { markdownToHtml } from ' @cardstack/runtime-common' ;
25
26
26
27
class EmbeddedTemplate extends Component <typeof BlogPost > {
27
28
<template >
@@ -638,7 +639,14 @@ export class BlogPost extends CardDef {
638
639
});
639
640
@field wordCount = contains (NumberField , {
640
641
computeVia : function (this : BlogPost ) {
641
- return this .body ?.length ;
642
+ if (! this .body ) {
643
+ return 0 ;
644
+ }
645
+ const plainText = markdownToHtml (this .body ).replace (
646
+ / <\/ ? [^ >] + (>| $ )/ g ,
647
+ ' ' ,
648
+ );
649
+ return plainText .trim ().split (/ \s + / ).length ;
642
650
},
643
651
});
644
652
@field editors = linksToMany (User );
You can’t perform that action at this time.
0 commit comments