Collapsible TOC based on first characters of tiddler title

149 views
Skip to first unread message

Damon Pritchett

unread,
Dec 13, 2018, 7:33:55 PM12/13/18
to TiddlyWiki
Tiddlywiki Wizards,

My current Tiddlywiki project currently has over 1800 tiddlers and I have a vertical tabbed TOC for each letter of the alphabet. This works pretty well except for letters that have a lot of tiddlers that start with say, K, that means a lot of scrolling. I would like to have a TOC that contains each letter of the alphabet, but, underneath that, have a further expandable choice based on, say, the first three characters of the title. This should make going through the selections much easier and cleaner. The image below illustrates what I'm talking about. I could do this manually, but that seems like a lot of work. Thanks in advance for any suggestions.

Damon

Capture.JPG

Mark S.

unread,
Dec 13, 2018, 7:54:25 PM12/13/18
to TiddlyWiki
Would those first 3 letters have to be capitalized, as you show in your example?

-- Mark

Damon Pritchett

unread,
Dec 13, 2018, 7:56:01 PM12/13/18
to TiddlyWiki
Not necessarily.

TonyM

unread,
Dec 13, 2018, 8:19:49 PM12/13/18
to TiddlyWiki
A Thought or two.

You can use css to set text to appear as upper case, even if is not. Careful use of sort should list aa Aa AA and aA together.

Perhaps you could set a "max list size" eg 26 items (before collapsing to subfolders)

In each level you test to see if there is more than 20 items using count[] then only subdivide that level if there are more than 20

eg Items beginning A > 20 use structured subfolder

A smart algorithm to compute when to create a subdivision would be nice, eg compute the number of sub-folders needed from the total count of the parent and then set the number needed to trigger a subfolder from being displayed. Who needs a sub-folder for one item?


Regards'
Tony

Mark S.

unread,
Dec 13, 2018, 9:31:24 PM12/13/18
to TiddlyWiki
Here's the pseudo TW code I'm considering (pseudo code means it doesn't actually work)

\define AtoZfilter() ...
\define glue123() ...
<$button> Create alphabetical TOC structure
   
<$list A-Z variable=letr1
   
<$list A-Z variable=letr2
   
<$list A-Z variable=letr3
   
<$list Use regular expression to to match by letr1-letr2-letr3. Use rest[10] to make sure there's at least 10 items
      <$action-setfield create new tiddler with letr1-letr2-letr3 tagged with letr1.
      <$list Use regular expression to match by letr1-letr2-letr3
      <$fieldmangler>
            <$action-sendmessage tm-remove-tag Remove existing letr1 tag from matching items
     </$fieldmangler>
    </$list>
</$list>
</$list>
</$list>
</$list>
</$button>

The idea is to try every combination of A-Z for a span of 3 letters, check if existing tiddlers match (up to a count determined by rest[number], and if so create tiddler ABC (tagged with "A") and then tag all matching tiddlers with ABC, deleting existing superfluous tag A. Hmm. Have to be sure not to delete the tag from the tiddler just created. Oh well.90% complete is pretty good.

I don't think I can get it to a few hours or more, so if someone else can write code (either to this or some other code) that's great -- but please post your intentions so the proverbial wheel isn't reinvented! ;-)

-- Mark

On Thursday, December 13, 2018 at 4:33:55 PM UTC-8, Damon Pritchett wrote:

Mark S.

unread,
Dec 14, 2018, 12:23:33 AM12/14/18
to TiddlyWiki
Ok. Here's code that should be able to do it.

But PLEASE make a backup of your work before trying this!!!! IT'S REALLY IMPORTANT! THIS MACRO MAY CHANGE EVERY TIDDLER IN YOUR TW FILE!!

There are several caveats here.

One is that every eligible tiddler will have it's modification date changed.

Do this on a desktop, not on a tablet or small device!

Another, when you first save the tiddler with the button, there may be a delay. You may be asked if you want to keep waiting. You need to keep waiting.

When you finally press the button, there will be even longer delays while it processes. You will probably be asked several times if you want to wait for the page before the process completes. It typically took 2 to 3 "waits" on tiddlywiki.com, and there's only 1100 tiddlers there!

I strongly recommend that you close out any tabs you don't need. In fact, be sure all your work in all your applications is saved in case the browser hangs the machine.

At the top of the code you can set a value for min-per-group. This is the minimum number of tiddlers you want before creating its own group entry. Paste the code into a tiddler and close the tiddler. Then, if you're sure you want to, press the button.

The reason this code is so inefficient is that it is generating all 17576 possible combinations of 3 letters and checking to see if any of your tiddlers match by title. A much more efficient code could have been written with just a tiny bit of javascript. Oh well.

Be careful!
Have fun -- if you can!

-- Mark

\define min-per-group() 10
\define ABC() A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
\define xABC() A B C D E F
\define regexpABC() (?i)^$(letr1)$$(letr2)$$(letr3)$
\define glueABC() $(letr1)$$(letr2)$$(letr3)$

<$button> Create alphabetical TOC structure
   
<$list filter="[enlist<ABC>]" variable=letr1>
   
<$list filter="[enlist<ABC>]" variable=letr2>
   
<$list filter="[enlist<ABC>]" variable=letr3>
   
<$list filter="[all[tiddlers]!has[draft.of]regexp<regexpABC>rest<min-per-group>limit[1]]" variable="dummy">
   
<$action-setfield $tiddler=<<glueABC>> tags=<<letr1>> />
   <$list filter="[all[tiddlers]regexp<regexpABC>]" >
      <$fieldmangler>
            <$action-sendmessage $message="tm-remove-tag" $param=<<letr1>>/
>
           
<$action-sendmessage $message="tm-add-tag" $param=<<glueABC>>/>
      </
$fieldmangler>

Damon Pritchett

unread,
Dec 14, 2018, 11:16:31 AM12/14/18
to TiddlyWiki
Thanks Mark. I've got some questions before I try this. How much would it complicate things if I only wanted to perform this operation on tiddlers with a specific tag? Also, with the delay that you've mentioned, is this only for the first time it's run or every time I add a new tiddler?

Thanks,

Damon

Mark S.

unread,
Dec 14, 2018, 11:27:46 AM12/14/18
to TiddlyWiki
In the filter that starts "[all[tiddlers]..." you can append your own specific tag operator.

I assume that once you've stamped the 1800 tiddlers that you will do new ones by hand. I guess you could run the whole thing again if you had a lot of new tiddlers you were adding all at once.

I'm kind of hoping someone will pop up with "here's an easy way to get the first 3 letters of a title in uppercase." ;-)

-- Mark

Damon Pritchett

unread,
Dec 14, 2018, 5:28:22 PM12/14/18
to TiddlyWiki
So after looking closely at my titles and considering a bit further, I believe that my original idea of doing this will not really solve my problem. There are a large number of tiddlers whose title is the same for up to 10 or 12 characters. I need to rethink a better way to navigate through all of the choices without creating a lot of clutter or a huge scrolling list. I am very open to suggestions.

Damon

TonyM

unread,
Dec 15, 2018, 12:35:40 AM12/15/18
to TiddlyWiki
Daemon

Without access to your data it is hard to map a usefull breakdown structure to apply.

Could you describe what they are?

Is there any other ways you do or can subdivide your tiddlers?

This may be a case of where search is best used to first reduce the size of the set before placing it in an alphabetical index.

Regards
Tony

Damon Pritchett

unread,
Dec 15, 2018, 1:36:23 PM12/15/18
to TiddlyWiki
My project consists of a large collection of a certain type of business in Kansas. Each business is represented by its own tiddler and contains facts about that business. The title of the tiddler is the name of the business. As one can imagine, a lot of the names begin with Kansas, but there are also a lot that begin with city names.

I don't want to do anything that takes away from the name/title. I've thought that searching is likely the best way to approach this, but there are times when it's convenient or necessary to do some browsing.

As I mentioned in the initial post, I have a table of contents set up with vertical tabs for each letter of the alphabet. For long lists such as K, there's a lot of scrolling and the tabs and the top of the sidebar scroll with it. This would be less of a concern if I could have to tabs and top of the sidebar not scroll.

Breaking up into smaller pieces is what my mind is churning on in the background, but haven't come up with any ideas yet. I've also wondered if a clever method of tagging might be a way to go.

Damon

Damon Pritchett

unread,
Dec 15, 2018, 1:36:45 PM12/15/18
to TiddlyWiki
My project consists of a large collection of a certain type of business in Kansas. Each business is represented by its own tiddler and contains facts about that business. The title of the tiddler is the name of the business. As one can imagine, a lot of the names begin with Kansas, but there are also a lot that begin with city names.

I don't want to do anything that takes away from the name/title. I've thought that searching is likely the best way to approach this, but there are times when it's convenient or necessary to do some browsing.

As I mentioned in the initial post, I have a table of contents set up with vertical tabs for each letter of the alphabet. For long lists such as K, there's a lot of scrolling and the tabs and the top of the sidebar scroll with it. This would be less of a concern if I could have to tabs and top of the sidebar not scroll.

Breaking up into smaller pieces is what my mind is churning on in the background, but haven't come up with any ideas yet. I've also wondered if a clever method of tagging might be a way to go.

Damon

On Friday, December 14, 2018 at 10:35:40 PM UTC-7, TonyM wrote:

Mark S.

unread,
Dec 15, 2018, 2:27:41 PM12/15/18
to TiddlyWiki
It sounds like you want a search that works like the sidebar search but that:

* Only searches your business tiddlers
* Only searches the first letters of the title of your businesses

So, as you type "Kan" you see all the titles that start with Kan (Kanvass Clothworks, Kansas Combines, Kansas Elevator, Kantina Refreshments, e.g.) but by typing after Kansas the list gets smaller. So you effectively have the best of both worlds. You can see everything that starts with "A", or "K" or "Kan".

I've always wondered why Arkansas isn't pronounced "Ar-Kansas", but I digress.

-- Mark

Damon Pritchett

unread,
Dec 15, 2018, 2:59:07 PM12/15/18
to TiddlyWiki
Yeah, I think that's kind of the search I'm looking for. Need to think about the best way to go about that.

The pronunciation of Arkansas is highly dependent upon which state it is that you reside in. If you live in or close to Arkansas, then you pronounce it Arkan-SAW. If you live in Kansas, then it is most definitely Ar-KANSAS. Digression continues......

TonyM

unread,
Dec 15, 2018, 7:07:53 PM12/15/18
to TiddlyWiki
As mark said and I proposed

Allowing the application of a filter or search to reduce the set that you then browse is a common strategy for large datasets.

What people tend to forget is once built our queries of such data sets often already start with some fact that we can use to reduce the set we are looking at

Try and make a list of reasons you may want to browse the list for and see if you can find information you can use to limit it on, eg state, city businss type etc which is much more useful than the semi random decisions naming businesses.

Regards
Tony

Reply all
Reply to author
Forward
0 new messages