First commit
This commit is contained in:
parent
c19d6d6328
commit
af709e2662
|
@ -26,11 +26,23 @@ BacklinksIndexer.prototype.rebuild = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
BacklinksIndexer.prototype._getLinks = function(tiddler) {
|
BacklinksIndexer.prototype._getLinks = function(tiddler) {
|
||||||
var parser = this.wiki.parseText(tiddler.fields.type, tiddler.fields.text, {});
|
var parser = this.wiki.parseText(tiddler.fields.type,tiddler.fields.text,{});
|
||||||
if(parser) {
|
parser.tree = [{
|
||||||
return this.wiki.extractLinks(parser.tree);
|
type: "importvariables",
|
||||||
}
|
attributes: {
|
||||||
return [];
|
filter: {
|
||||||
|
name: "filter",
|
||||||
|
type: "string",
|
||||||
|
value: "[[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isBlock: false,
|
||||||
|
children: parser.tree
|
||||||
|
}];
|
||||||
|
var widget = this.wiki.makeWidget(parser,{document: $tw.fakeDocument, parseAsInline: false, variables: {currentTiddler: tiddler.fields.title}});
|
||||||
|
var container = $tw.fakeDocument.createElement("div");
|
||||||
|
widget.render(container,null);
|
||||||
|
return this.wiki.extractLinksFromWidgetTree(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
BacklinksIndexer.prototype.update = function(updateDescriptor) {
|
BacklinksIndexer.prototype.update = function(updateDescriptor) {
|
||||||
|
|
|
@ -22,7 +22,8 @@ Adds the following properties to the wiki object:
|
||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var widget = require("$:/core/modules/widgets/widget.js");
|
var widget = require("$:/core/modules/widgets/widget.js"),
|
||||||
|
LinkWidget = require("$:/core/modules/widgets/link.js").link;
|
||||||
|
|
||||||
var USER_NAME_TITLE = "$:/status/UserName",
|
var USER_NAME_TITLE = "$:/status/UserName",
|
||||||
TIMESTAMP_DISABLE_TITLE = "$:/config/TimestampDisable";
|
TIMESTAMP_DISABLE_TITLE = "$:/config/TimestampDisable";
|
||||||
|
@ -513,6 +514,29 @@ exports.extractLinks = function(parseTreeRoot) {
|
||||||
return links;
|
return links;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Return an array of tiddelr titles that are linked within the given widget tree
|
||||||
|
*/
|
||||||
|
exports.extractLinksFromWidgetTree = function(widget) {
|
||||||
|
// Count up the links
|
||||||
|
var links = [],
|
||||||
|
checkWidget = function(widget) {
|
||||||
|
if(widget instanceof LinkWidget) {
|
||||||
|
var value = widget.to;
|
||||||
|
if(links.indexOf(value) === -1) {
|
||||||
|
links.push(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(widget.children) {
|
||||||
|
$tw.utils.each(widget.children,function(widget) {
|
||||||
|
checkWidget(widget);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
checkWidget(widget);
|
||||||
|
return links;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Return an array of tiddler titles that are directly linked from the specified tiddler
|
Return an array of tiddler titles that are directly linked from the specified tiddler
|
||||||
*/
|
*/
|
||||||
|
@ -521,11 +545,10 @@ exports.getTiddlerLinks = function(title) {
|
||||||
// We'll cache the links so they only get computed if the tiddler changes
|
// We'll cache the links so they only get computed if the tiddler changes
|
||||||
return this.getCacheForTiddler(title,"links",function() {
|
return this.getCacheForTiddler(title,"links",function() {
|
||||||
// Parse the tiddler
|
// Parse the tiddler
|
||||||
var parser = self.parseTiddler(title);
|
var container = $tw.fakeDocument.createElement("div");
|
||||||
if(parser) {
|
var widget = self.makeTranscludeWidget(title,{document: $tw.fakeDocument, parseAsInline: false,variables: {currentTiddler: title},importPageMacros: true});
|
||||||
return self.extractLinks(parser.tree);
|
widget.render(container,null);
|
||||||
}
|
return self.extractLinksFromWidgetTree(widget);
|
||||||
return [];
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue