Rather than trying to retrofit my existing TiddlyTools/Templates/Size code, here’s some code that gives you the totals for the text
field of all the tiddlerx matching a specified filter:
<$let tids="[prefix<currentTiddler>]"
count={{{ [subfilter<tids>count[]] }}}
bytes={{{ [subfilter<tids>] :map[{!!text}length[]] +[sum[]] }}}
lines={{{ [subfilter<tids>] :map[{!!text}splitregexp[\n]count[]] +[sum[]] }}}
words={{{ [subfilter<tids>] :map[{!!text}splitregexp[\n]splitregexp[\s+]count[]] +[sum[]] }}}>
<<count>> tiddlers, <<bytes>> bytes, <<words>> words, <<lines>> lines
Notes:
-
tids
is the filter syntax for selecting the tiddlers you want to total. In the above example, I’ve used [prefix<currentTiddler>]
on the assumption that “child” tiddlers are named by using the “parent” tiddler title as a prefix. If this is not how your child tiddlers are named, you will need to adjust the filter accordingly.
-
count
is the number of tiddlers being summarized
-
bytes
gets the length of each tiddler’s text field and then sums them to get the total
-
lines
gets the number of lines of text in each tiddler by splitting on the newlines
-
words
gets the number of words of text in each tiddler by splitting on the newlines and then splitting on whitespace in each line
To have this code invoked in each tiddler, place it in a separate tiddler (e.g.,MyTiddlerStats
), and tag it with $:/tags/EditTemplate
.
enjoy,
-e