--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.
Is there a tool in TW5 to tell you the sizes of each Tiddler
/*\
title: $:/macros/skeeve/length.js
type: application/javascript
module-type: macro
<<length text>>
Examples:
<<length "sometext">>
<<length tiddler:"tiddlertitle">>
<$macrocall $name="length" text="sometext"/>
<$macrocall $name="length" tiddler={{!!title}}/>
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
This is a macro to get the length of a string/text or a tiddler.
For a tiddler's length the string-length of its JSON representation is used.
*/
exports.name = "length";
exports.params = [
{ name: "text" },
{ name: "tiddler" },
];
/*
Run the macro
*/
exports.run = function(text, tiddler) {
if(!text) {
if(!tiddler) {
return 0;
}
text = $tw.wiki.getTiddlerAsJson(tiddler);
}
return text.length.toString();
};
})();/*\
title: $:/core/modules/filters/lsort.js
type: application/javascript
module-type: filteroperator
Filter operator for sorting
lsort[] : sort by tiddler size
lsort[fieldname] : sort by length of fieldname's value
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.lsort = function(source,operator,options) {
var isDescending = operator.prefix === "!";
var results = [];
if(operator.operand === "") {
source(function(tiddler,title) {
var len = $tw.wiki.getTiddlerAsJson(title).length;
results.push( { "title": title, "len": len } );
});
}
else {
source(function(tiddler,title) {
var tdlr = $tw.wiki.getTiddler(title);
var len = 0;
if(tdlr) {
len = (tdlr.fields[operator.operand] || "").length;
}
results.push( { "title": title, "len": len } );
});
}
results.sort(function(a,b) {
return isDescending ? b.len - a.len : a.len - b.len;
});
for( var i = results.length; i--;) {
results[i] = results[i].title;
}
return results;
};
})();<$list filter="[!lsort[]]">
<$view field="title"/>: <$macrocall $name="length" tiddler={{!!title}}/>
</$list>> What is the equivalent of story.displayTiddler() for tw5?There's no simple equivalent. See this previous discussion on tiddlywikidev:
For convenience, it would be reasonable to add a $tw.story object that represents the default story river and includes a $tw.story.displayTiddler() method.
Hi Stephan,Nice stuff, would be cool if one could run these things from a bookmarklet.
Shouldn't be a problem... Provided you tell me what you expect the bookmarklet should do?
I will try out Stephan Hradek code and see what I can do with it, I am not a coder so I mess that stuff up most times.
So the bookmarklet should output to the console?
javascript:void((function()%7B%0Avar%20filter%20%3D%20prompt('Please%20st%20the%20filter'%2C'%5B!is%5Bshadow%5D!is%5Bsystem%5D%5D')%3B%0A%0Avar%20sizes%20%3D%20%5B%5D%3B%0A%0A%24tw.utils.each(%24tw.wiki.filterTiddlers(filter)%2C%0A%20%20%20%20function(tiddler)%7B%0A%20%20%20%20%20%20%20%20var%20size%20%3D%200%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20t%20%3D%20%24tw.wiki.getTiddler(tiddler)%3B%0A%20%20%20%20%20%20%20%20sizes.push(%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20title%3Atiddler%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20size%3A%24tw.wiki.getTiddlerAsJson(tiddler).length.toString()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20fields%3AObject.keys(t.fields).length%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20type%3At.fields%5B'type'%5D%20%7C%7C%20''%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%7D%0A)%0Asizes.sort(function(a%2C%20b)%20%7B%20return%20b.size%20-%20a.size%3B%7D)%3B%0A%0Avar%20out%20%3D%20''%3B%0A%24tw.utils.each(sizes%2C%0A%20%20%20%20function%20(t)%7B%0A%20%20%20%20%20%20%20%20out%20%2B%3D%20%0A%20%20%20%20%20%20%20%20%20%20%20%20t.size%20%2B%20'%20%5B%5B'%20%2B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20t.title%20%2B%20'%5D%5D%2C%20'%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20t.fields%20%2B%20'%20fields'%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20(t.type%20%3F%20'%2C%20'%20%2B%20t.type%20%3A%20'')%20%2B%20'%5Cn'%3B%0A%20%20%20%20%7D%0A)%0A%0Avar%20story%20%3D%20%22%24%3A%2FStoryList%22%2C%0A%20%20temp%20%3D%20%22%24%3A%2Ftemp%2Ftiddler-sizes%22%2C%0A%20%20list%20%3D%20%24tw.wiki.getTiddlerList(story)%3B%0A%0A%24tw.wiki.addTiddler(%0A%20%20%20%20new%20%24tw.Tiddler(%7B%0A%20%20%20%20%20%20%20%20title%3A%20temp%2C%0A%20%20%20%20%20%20%20%20text%3A%20'%22%22%22%5Cn'%20%2B%20out%20%2B%20'%22%22%22'%0A%20%20%20%20%7D)%0A)%3B%0A%0Aif(list.indexOf(temp)%20%3D%3D%3D%20-1)%20%7B%0A%09list.unshift(temp)%3B%0A%7D%0A%0A%24tw.wiki.addTiddler(new%20%24tw.Tiddler(%0A%09%7Btitle%3A%20story%7D%2C%0A%09%24tw.wiki.getTiddler(story)%2C%0A%09%7Blist%3A%20list%7D%0A))%3B%0A%7D)())%3BHi Stephan,That's cool!
Now, to the interesting bit: What was your workflow to produce it? ^^
You can also leave out step #6 as you can as well paste the javascript code into the location field. The advantage when doing #6 is, that it can be undone and you get a nicely(?) formatted javascript source.
wrap your code in a function call that is immediately executed
function(){ ... })()
(function(){ ... })()
You miss the opening "(":(function(){ ... })()
Am I missing something?
Am I missing something?the (content-)type ;)
|
|||||||||||||||||||||||
under the Info-Fields tab I'm showing two fields:
title lights-diagram3.jpg
type image/jpeg