Based on a little preliminary testing on TW-com…
"""
`[[HelloThere]backlinks[]]`
{{{ [[HelloThere]backlinks[]] }}}
`[[HelloThere]backlinks[]count[]]`: {{{ [[HelloThere]backlinks[]count[]] }}}
`[backlinks[]count[]]`: {{{ [backlinks[]count[]] }}}
`[links[]count[]]`: {{{ [links[]count[]] }}}
`[all[tiddlers]count[]]`: {{{ [all[tiddlers]count[]] }}}
`[all[tiddlers]] :filter[backlinks[]] +[count[]]`: {{{ [all[tiddlers]] :filter[backlinks[]] +[count[]] }}}
"""
That last filter is counting only the number of tiddlers that have at least one backlink, and you can see it doesn’t match the results of counting the output of [backlinks[]]
(which takes [all[tiddlers]]
as its input by default). But the backlinks[]
count does seem low… probably because the backlinks
operator dominantly appends its results.
Some filter operators like enlist
and enlist-input
can take the suffix :raw
, which prevents the default deduplication. But links
and backlinks
don’t offer the option, so we’ll have to build some title lists that enlist-input:raw
can work with.
\function backlinks.list() [backlinks[]] +[format:titlelist[]join[ ]]
"""
`[[HelloThere]backlinks.list[]] +[enlist-input:raw[]count[]]`: {{{ [[HelloThere]backlinks.list[]] +[enlist-input:raw[]count[]] }}}
`[all[tiddlers]] :map[backlinks.list[]] +[enlist-input:raw[]count[]]`: {{{ [enlist<tiddlers>] :map[backlinks.list[]] +[enlist-input:raw[]count[]] }}}
"""
Here, I’m using a custom function, backlinks.list()
, which will generate a title list of all the backlinks of each of its input titles. When the set of input tiddlers includes more than one title, we also need to use this function in a separate :map
filter run in order to make a separate list of backlinks for each input title—otherwise, we run into the dedup problem again. So at this stage, we have a list of lists…
Now we can use enlist-input:raw
to return the full list of backlinks without duplicates removed, and finally count
them.
And the results:
A few more notes:
- For brevity, I used the default
[all[tiddlers]]
in all these examples, but you can of course start from [all[tiddlers]!is[system]]
or any other set of tiddlers you’d like to examine.
- The triple quotes
"""
are there purely to preserve whitespace in the screenshots; you don’t need them in your actual code!
- As per the usual restrictions of
links
and backlinks
, this filter will only count hard links in the text field.
- If you have a large and heavily linked wiki, this may be rather slow! My tests on TW-com were pretty snappy, but in my largest wiki (20k tiddlers and a bit over 43k backlinks, per this filter) there was some brief but noticeable lag.