Before you run and test any of the following, please ensure you have multiple backups of your TiddlyWiki. I do not assume any responsibility for consequences arising from this article. You absolutely, positively, must back up your data.
In a Node.js TiddlyWiki, there’s a configurable tiddler called $:/config/FileSystemPaths
. This tiddler allows you to store different content in various disk paths based on filter expressions. For details, you can refer to Customising Tiddler File Naming . However, this is a configuration tiddler, meaning you can only write filter expressions in it, not wikitext. While simple categorization is fine, if you have thousands or even tens of thousands of tiddlers, and you want to categorize them on your hard drive, you’ll need another solution.
Why categorize? Because Windows can become sluggish when a single folder contains tens of thousands of files. So, categorization might be necessary later on. Of course, if you exceed TiddlyWiki’s limits and performance thresholds, a better approach might be to use multiple TiddlyWikis for management.
Now, let’s get to the main topic: how to categorize. I’ll explain with a simple example. First, you’ll need some tiddlers that have a test
field, with different values for this field. Prepare a good number of these tiddlers to see the effect more clearly. This method also applies to Markdown files.
Next, create a new tiddler. The name can be anything; I’ll use Filter Expression Generation
. This tiddler will be used to generate filter expressions. The code for it is as follows:
<$list filter="[has[test]get[test]unique[]enlist-input[]]" variable="testField">
<$set name="fieldValue" value=<<testField>> >
<$let
filterExpresision=`[test[$(fieldValue)$]addprefix[\]addprefix[$(fieldValue)$]]` >
<$text text=<<filterExpresision>> />
</$let>
</$set>
</$list>
After saving, you’ll see content similar to this:
[test[123]addprefix[\]addprefix[123]] [test[0023]addprefix[\]addprefix[0023]] [test[1111]addprefix[\]addprefix[1111]] [test[22]addprefix[\]addprefix[22]]
However, this content isn’t “wikified” and cannot be used directly. So, we need a second tiddler. The name is arbitrary again; I’ll use Filter Expression Button
. This tiddler will use a button to store the filter expressions generated above. The code is as follows:
<$wikify name="filterExpressionStorage" text={{Filter Expression Generation}} >
<$button>
<$let filterExpressionStorageValue={{{ [<filterExpressionStorage>search-replace:g:regexp[\n],[ ]search-replace:g:regexp[\s+],[ ]trim[]] }}} >
<$action-setfield $tiddler="Filter Expression Storage" $field="text" $value=<<filterExpressionStorageValue>> />
<$action-navigate $to="Filter Expression Storage"/>
Create or Update
</$let>
</$button>
</$wikify>
A quick explanation here: this code uses regular expressions for replacement. But don’t worry, it’s not replacing anything critical, just removing extra newlines and spaces, and trimming leading/trailing spaces to make it look cleaner.
Okay, now click the button. This will create a tiddler named Filter Expression Storage
and save the filter expression content into it. Now you can finally process $:/config/FileSystemPaths
. This is very simple: create this tiddler if it doesn’t exist, or edit it if it does. Then, save the following content into it. Of course, you can have other content as well.
[subfilter{Filter Expression Storage}addprefix[test/]]
By now, you should understand. subfilter
will automatically read the value within, running each filter expression. These filter expressions, in turn, are created and kept updated by the Filter Expression Button
. You don’t need to manually enter them. The filter expressions themselves are built from Filter Expression Generation
. If you’re a professional TiddlyWiki user, you can certainly extrapolate and create many different uses. The key point here is that the tiddler names above aren’t absolute, but you need to keep them consistent. You can use system prefixes or your own custom ones, but onsistent must be maintained.
But it’s not over yet. Existing tiddlers won’t update automatically unless you edit them. You certainly don’t want to manually edit thousands of tiddlers one by one. Therefore, you can use the plugin $:/plugins/kookma/commander
. Open the $:/Commander
tiddler and enter an appropriate filter expression. Check the Selective operation?
box, then click the Select all
button, and then uncheck the box. This will cause the filtered tiddlers to be “modified,” but only their modification time will change; their content will remain untouched. This is acceptable.
At this point, if you check your files, you’ll find them neatly categorized into different folders.
I know you might have more questions, and I’ve thought about them too. What if the filter is very complex, or there are many of them? Do you have to enter them one by one? That’s too much trouble. So, we can implement the same filter expression construction based on the above content.
Create a tiddler with any name; I’ll use Filter Expression Generation No Prefix
, indicating no prefix is added, which gives you regular filter expressions.
<$list filter="[has[test]get[test]unique[]enlist-input[]]" variable="testField">
<$set name="fieldValue" value=<<testField>> >
<$let
filterExpresision=`[test[$(fieldValue)$]]` >
<$text text=<<filterExpresision>> />
</$let>
</$set>
</$list>
Next, we’ll similarly create a button tiddler. The name is arbitrary; I’ll choose Filter Expression Button No Prefix
. The content is as follows:
<$wikify name="filterExpressionStorage" text={{Filter Expression Generation No Prefix}} >
<$button>
<$let filterExpressionStorageValue={{{ [<filterExpressionStorage>search-replace:g:regexp[\n],[ ]search-replace:g:regexp[\s+],[ ]trim[]] }}} >
<$action-setfield $tiddler="Filter Expression Storage No Prefix" $field="text" $value=<<filterExpressionStorageValue>> />
Create or Update
</$let>
</$button>
</$wikify>
Then you can use the following filter expression:
[subfilter{Filter Expression Storage No Prefix}]
Isn’t that incredibly simple? I want to emphasize again: in TiddlyWiki, tiddler names aren’t fixed. Anyone can name them as they like, but you must maintain consistency in naming, otherwise, this won’t work.
Finally, I must reiterate: you absolutely, positively, must back up your data and your TiddlyWiki. Before performing any tests, always back up. If you don’t use Git for backups, irreversible consequences could occur. I do not assume responsibility for any consequences resulting from the content above. Please ensure you have conducted sufficient testing and made enough backups before proceeding. For users with limited TiddlyWiki experience, consider asking for help from others by posting a post.
updated,add the closed tags </$wikify>
.