[TW5] - Tiddler Size

471 views
Skip to first unread message

RichShumaker

unread,
Dec 1, 2014, 10:56:35 PM12/1/14
to tiddl...@googlegroups.com
Is there a tool in TW5 to tell you the sizes of each Tiddler, I checked the Tiddler [Info] but I didn't see it.
Or is there a way to build a list based on size.
I am at 15MB right now and want to resize any images that might be too large.

So far things have been good and I have about 250 images in my TW5 file.

Thanks everyone.

Rich Shumaker

Richard Smith

unread,
Dec 2, 2014, 2:06:31 AM12/2/14
to tiddl...@googlegroups.com
Hi Rich,

One way to do it is to import your wiki to a node.js (TW) instance. Then you can browse the tiddlers in your filesystem.

Regards,
Richard

Danielo Rodríguez

unread,
Dec 2, 2014, 2:52:10 AM12/2/14
to tiddl...@googlegroups.com
Hello Rich,

Regarding images you can right click and then download it to see how big it is.

PMario

unread,
Dec 2, 2014, 5:12:03 AM12/2/14
to tiddl...@googlegroups.com
I think this would be a valid "feature request" for TW. ...

If you have a github account you can create a ticket.
If you don't, we can do it :)

have fun!
mario

Tobias Beer

unread,
Dec 2, 2014, 5:36:36 AM12/2/14
to tiddl...@googlegroups.com
You can try this...


I figured out how to add a tiddler with the stats but almost an hour I couldn't figure out the command to open it, argh...

@Jeremy,

What is the equivalent of story.displayTiddler() for tw5?

I think the dev documentation should be a lot more task oriented, i.e....
  • How to filter and enumerate tiddlers?
  • How to display a tiddler?
  • How to set tiddler fields?
  • How to tag a tiddler or remove a tag?
  • Etc...
Best wishes, Tobias.

Jeremy Ruston

unread,
Dec 2, 2014, 10:37:32 AM12/2/14
to TiddlyWiki
Hi Tobias

> 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.

Best wishes

Jeremy.




--
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.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Stephan Hradek

unread,
Dec 2, 2014, 1:16:41 PM12/2/14
to tiddl...@googlegroups.com


Am Dienstag, 2. Dezember 2014 04:56:35 UTC+1 schrieb RichShumaker:
Is there a tool in TW5 to tell you the sizes of each Tiddler

Try this macro:

/*\
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();
};

})();

The serialized form of the tiddler is taken when you call for the length of a tiddler. This is not the real amount of data used when storing the tiddler, but it gives a good esitmate, I think, and should be consistant across all tiddlers.

Stephan Hradek

unread,
Dec 2, 2014, 2:41:04 PM12/2/14
to tiddl...@googlegroups.com
And here is a filter for sorting by size / length:

/*\
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;
};
})();

Example usage to sort by descending tiddler size:

<$list filter="[!lsort[]]">

<$view field="title"/>: <$macrocall $name="length" tiddler={{!!title}}/>

</$list>


Tobias Beer

unread,
Dec 2, 2014, 4:10:23 PM12/2/14
to tiddl...@googlegroups.com, jeremy...@gmail.com
Hi Jeremy,

> What is the equivalent of story.displayTiddler() for tw5?

There's no simple equivalent. See this previous discussion on tiddlywikidev:

asked over there what the required codebits look like
 
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.

indeed

Tobias Beer

unread,
Dec 2, 2014, 8:01:21 PM12/2/14
to tiddl...@googlegroups.com
Hi Stephan,

Nice stuff, would be cool if one could run these things from a bookmarklet.

More of such scripts adding up would be a tad bit too much to carry around for me.

Best wishes, Tobias.

RichShumaker

unread,
Dec 2, 2014, 8:52:32 PM12/2/14
to tiddl...@googlegroups.com
I have a Github and will put a request in the next few days as this request is not a 'need' but a 'want'.
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.

Thanks again everyone for your help.

Rich Shumaker

Stephan Hradek

unread,
Dec 3, 2014, 3:03:17 AM12/3/14
to tiddl...@googlegroups.com


Am Mittwoch, 3. Dezember 2014 02:01:21 UTC+1 schrieb Tobias Beer:
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?
Should it
  • show the sizes of the current story tiddlers in an alert box?
  • spit out a list / table into the currently focused textarea?
  • ... 

Tobias Beer

unread,
Dec 3, 2014, 5:10:49 AM12/3/14
to tiddl...@googlegroups.com
Shouldn't be a problem... Provided you tell me what you expect the bookmarklet should do?

Tobias Beer

unread,
Dec 3, 2014, 5:26:19 AM12/3/14
to tiddl...@googlegroups.com
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.

There's nothing for you to "code", it's only for you to use...


Best wishes, Tobias.

Stephan Hradek

unread,
Dec 3, 2014, 5:56:06 AM12/3/14
to tiddl...@googlegroups.com
So the bookmarklet should output to the console?

Tobias Beer

unread,
Dec 3, 2014, 5:57:09 AM12/3/14
to tiddl...@googlegroups.com
So the bookmarklet should output to the console?

Nope, it is now run from the console but actually creates and opens a tiddler like yours.

Best wishes, Tobias. 

Stephan Hradek

unread,
Dec 3, 2014, 7:12:03 AM12/3/14
to tiddl...@googlegroups.com
I should really have run that ;)

This is the bookmarklet location to use:

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)())%3B

It's mainly your code with just one prompt for the filter added.

Create a new bookmark, paste the code above into the location and you have your bookmarklet.

Tobias Beer

unread,
Dec 3, 2014, 8:03:02 AM12/3/14
to tiddl...@googlegroups.com
Hi Stephan,

That's cool!
Now, to the interesting bit: What was your workflow to produce it? ^^

Best wishes, Tobias. 

Stephan Hradek

unread,
Dec 3, 2014, 8:52:37 AM12/3/14
to tiddl...@googlegroups.com


Am Mittwoch, 3. Dezember 2014 14:03:02 UTC+1 schrieb Tobias Beer:
Hi Stephan,

That's cool!

Now, to the interesting bit: What was your workflow to produce it? ^^

Leaving out the testings done:
  1. copied your code into my jEdit
  2. added the prompt
  3. prepended "javascript:void((function(){"
  4. appended  "})());"
  5. selected from "void" to the end
  6. called my macro "URI Encode"
  7. selected everything and pasted here

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.

RichShumaker

unread,
Dec 3, 2014, 3:35:25 PM12/3/14
to tiddl...@googlegroups.com
Thanks again everyone.
I will be trying this stuff out today.

I added a GitHub Issue, 'Have the Tiddler Size listed in the Tiddler.'
Jeremy has already replied over there.
So that is on the 'books' in the proper place now.

Rich Shumaker

Tobias Beer

unread,
Dec 3, 2014, 5:27:38 PM12/3/14
to tiddl...@googlegroups.com
Hi Stephan,

Thanks a lot for sharing! I might just be playing more with that in the future.


Best wishes, Tobias.
Message has been deleted

Stephan Hradek

unread,
Dec 4, 2014, 1:27:46 AM12/4/14
to tiddl...@googlegroups.com
Hi Tobi!

There is a mistake

wrap your code in a function call that is immediately executed
  • function(){ ... })()
 
You miss the opening "(":

(function(){ ... })()

Tobias Beer

unread,
Dec 4, 2014, 3:03:31 AM12/4/14
to tiddl...@googlegroups.com
Hi Stephan,
 
Yes, of course... 

 You miss the opening "(":

(function(){ ... })()

Oversight from dissecting the javascript:void() from the function wrapper.
Thanks for pointing out!

Best wishes, Tobias.

Stephen Kimmel

unread,
Dec 4, 2014, 12:27:45 PM12/4/14
to tiddl...@googlegroups.com
Tobias,

Your routine seems to be listing the size, tiddler name, number of fields and sometimes type. My question is on the number of fields. Every entry I've checked seems to have one more Field listed than I count when I open the tiddler. For example:

74557 lights-diagram3.jpg, 3 fields, image/jpeg
68046 tylenol_heat.jpg, 3 fields, image/jpeg
54112 GE_Cabling.jpg, 3 fields, image/jpeg

but when I check the Info for each one, I only see two fields.

Am I missing something?

Tobias Beer

unread,
Dec 4, 2014, 12:31:34 PM12/4/14
to tiddl...@googlegroups.com
Am I missing something?

the (content-)type ;) 

Stephen Kimmel

unread,
Dec 4, 2014, 1:45:41 PM12/4/14
to tiddl...@googlegroups.com
Am I missing something?

the (content-)type ;) 

For my picture tiddler lights-diagram3.jpg, I get the listing:


74557 lights-diagram3.jpg, 3 fields, image/jpeg

under the Info-Fields tab I'm showing two fields:

title lights-diagram3.jpg
type image/jpeg

So it seems to me I have two fields, title and type, rather than three.

For my tiddler Daily.Journal I get the listing:

627 Daily.Journal, 12 fields, text/vnd.tiddlywiki

changecount 5
created 20140324130500000
creator Stephen
modified 20140825173718835
modifier Stephen
server.host file:///F:/personal.html
server.page.revision 201404072107
server.type file
tags task [[To Do]]
title Daily.Journal
type text/vnd.tiddlywiki






















So for that tiddler, the routine appears to have one extra field besides the "type" field. Or double counted one field.

Does the routine double count the type field if one is explicitly listed?


Tobias Beer

unread,
Dec 4, 2014, 7:26:54 PM12/4/14
to tiddl...@googlegroups.com
Hi Stephen,
 
under the Info-Fields tab I'm showing two fields:

title lights-diagram3.jpg
type image/jpeg

Then it's the text, I presume :)

Best wishes, Tobias.
Reply all
Reply to author
Forward
0 new messages