TiddlyWiki – incoming Links

There are sit­u­a­tions when you need to have a list of all the tid­dlers that link to some oth­er tid­dlers in your Tid­dly­Wi­ki, e.g. when renam­ing that oth­er tid­dler and hav­ing to update all the ref­er­ences to it. Some plu­g­ins out there give such lists, like the excel­lent Relat­edTid­dler­sPlu­g­in by Eric Shul­man, whose func­tion­al­i­ty far exceeds the sim­ple list of incom­ing links, though. Also, no plu­g­in rec­og­nizes links to par­tic­u­lar sec­tions with­in a tid­dler, as pro­vid­ed by Eric Shulman’s Sec­tion­LinksPlu­g­in in the form of Tiddler##SectionTitle.
To rem­e­dy this sit­u­a­tion, I mod­i­fied the very lean WhatLinksH­ere­Plu­g­in by Tyler Akins, which does a good job of show­ing incom­ing links and noth­ing more, to rec­og­nize sec­tion links.

There’s not much to that, though; the plu­g­in sim­ply removes the ## sec­tion links indi­ca­tor and all text fol­low­ing it pri­or to com­par­ing each link to the title of the cur­rent tid­dler.

If you’d like to always have the list of incom­ing links dis­played beneath the list of tags for the cur­rent tid­dler, edit the ViewTemplate tid­dler and change the line

<div class='tagged' macro='tags'></div>

to

<div class='tagged'>
  <div macro='tags'></div>
  <div macro='whatLinksHere "<br />links: <br /> "'></div>
</div>

To install the plu­g­in, copy and paste every­thing below the divider into a new tid­dler in your Tid­dly­Wi­ki, tag it with systemConfig and reload.


/***
|Name|WhatLinksHerePlugin|
|Source|http://rumkin.com/tools/tiddlywiki/#WhatLinksHerePlugin|
|Version|1.1.0|
|Author|Tyler Akins, Marcus Winter|
|License|Public Domain|
|~CoreVersion|2.1|
|Type|plugin|
|Requires||
|Overrides||
|Description|Displays a list of tiddlers that link to the current tiddler.|

!Usage
{{{
<<whatLinksHere txtIfList txtIfNoList>>
}}}
* txtIfList: String to print at the top of the list if there is at least one result.
* txtIfNoList:  String to print at the top if there are no tiddlers that link to the current tiddler.

!Configuration
Do not list these tiddlers:
{{wideInput{<<option txtWhatLinksHereExclude 40>>}}}

!Examples
This is a live example of what links to this tiddler:
|<<whatLinksHere "List of tiddlers that link to me: <br />" "Sorry, nobody links to me.">>|

!Installation
# Copy/paste the WhatLinksHerePlugin tiddler into your TiddlyWiki and tag it with systemConfig.
# Modify a tiddler or template to use the whatLinksHere macro.

!Revision History
* 1.1.0 (2012-02-24)
** Modified the code to also recognize section links like tiddler##section.
* 1.0.0 (2007-09-30)
** Initial version by Tyler Akins (http://rumkin.com/tools/tiddlywiki/#WhatLinksHerePlugin).

!Code
***/
//{{{
version.extensions.WhatLinksHerePlugin={major: 1, minor: 1, revision: 0, date: new Date(2012,2,24)};

// initialize 'autozoom' and 'exclude' tree options (defaults are not to zoom, and to follow all links)
if (config.options.txtWhatLinksHereExclude===undefined)
	config.options.txtWhatLinksHereExclude='GettingStarted DefaultTiddlers tabTimeline';
if (config.optionsDesc)
	config.optionsDesc.txtWhatLinksHereExclude = "List of tiddlers to not show."

config.macros.whatLinksHere={
	handler: function(place,macroName,params,wikifier,paramString,tiddler) {
		var span = createTiddlyElement(place, "span");
		var excludes = config.options.txtWhatLinksHereExclude.readBracketedList();
		var results = [];
		var tid = story.findContainingTiddler(place);
		var root = "";
		var out = ""
		if (tid) {
			root=tid.getAttribute("tiddler");
		}

		store.forEachTiddler(function(title,tiddler) {
			if (! excludes || ! excludes.contains(title)) {
				var links = tiddler.getLinks();
				for (var i=0; i  links.length; i++) {
					if (links[i].split("##")[0] == root) {
						results.pushUnique(title);
					}
				}
			}
		});
		results.sort();
		out = "[[" + results.join("]]\n[[") + "]]";
		if (results.length && params[0])
			out = params[0] + out;
		if (! results.length && params[1])
			out = params[1] + out;
		out = "{{whatLinksHere{" + out + "}}}";
		wikify(out, place);
	}
}

//}}}


last posts in TiddlyWiki:

3 Comments

  • I didn’t know you were into Tid­dly­Wi­ki!

  • Marcus wrote:

    I’ve been tid­dling for years; I think I start­ed short­ly after get­ting my diplo­ma, main­ly to keep notes regard­ing work. Nowa­days I’ve become too for­get­ful to be able to do with­out…

  • touristtam wrote:

    just installed this and I am babling with javascript.. Just won­der­ing how to cor­rect mod­i­fy your plu­g­in to include a TAG field

Post a Comment

Your email is never shared.