Objective
Nearby neighbors are a list of tiddlers related to the current tiddler which share some properties. This thread demonstrates a wikitext solution to display the nearby neighbors through a view template at the bottom of each non system tiddler
History
- The original discussion started by @Scott_Sauyet and can be found here Creating a “What’s Nearby” feature - Discussion - Talk TW (tiddlywiki.org)
- A JavaScript solution is created by @Scott_Sauyet which implements a new filter operator
The below is a WikiText solution in the form of a ViewTemplate tiddler.
Terminology / Parameters
The following metrics enter into the calculation of how “close” a neighbor is.
-
parent
: The neighbor is a tag of the current tiddler. -
child
: The neighbor is tagged with the current tiddler. -
spouse
: The neighbor and the current tiddler have at least onechild
tiddler in common. Each commonchild
contributes the defined weight to the total score. -
sibling
: The neighbor and the current tiddler have aparent
tiddler in common. Each commonparent
contributes the defined weight to the total score. -
fielded
: The neighbor appears in thefieldName
field of the current tiddler, or the current tiddler appears in thefieldname
field of the neighbor. Which field to use can be set in thefieldName
definition at the top. The field is a list field, i.e. tiddler titles must be enclosed in [[brackets]] if they contain spaces. -
linked
: The current tiddler contains a hard link to the neighbor. -
backlinked
: The neighbor contains a hard link to the current tiddler.
The weights for each metric can be set individually in the definitions at the top (larger score means closer neighbor). A weight of 0 means that this particular metric is disregarded. Also, the maximum number of tiddlers to show (numberOfTiddlersShown
) and the minimum score required for a neighbor to be listed (minScore
) can be defined.
Finally, the exclusions
variable contains a filter which causes that tiddler to be removed from the neighbors list if the filter returns any result for a particular tiddler (see https://tiddlywiki.com/#filter Operator).
Output
The list is only shown when there is something to show (neighbors with a score > minScore
exist).
The WikiText inside the <li>
tag determines the output formatting. In the example below the total score as well as the contributing metrics are shown. The corresponding lines can easily be removed or replaced by icons if required.
ViewTemplate
You can download the working viewtemplate tiddler here and drop it into any wiki:
neighbors.json (4.3 KB)
Example
To give a try,
- Download the viewtemplate tiddller above and drag and drop into https://tiddlywiki.com
- Look at the bottom of HelloThere it looks like this:
It is probably a good idea to set minScore
to at least 2, in order to remove simple tags from the output (and raise the childWeight
to 2 if you want to keep showing children).
Have a nice day
Yaisog