File System Path: Store Tiddlers Come from a Tiddler Field

Using TiddlyWiki on Node.JS, one can set the file system path using $:/config/FileSystemPaths tiddler. For example (from doc)

[is[system]!has[draft.of]removeprefix[$:/]addprefix[_system/]]
[is[draft]search-replace:g:regexp[/|\\],[_]addprefix[drafts/]]
[tag[task]addprefix[mytasks/]]
[!tag[externalnote]addprefix[wiki/]]

My question is:
I keep some tiddlers in a field: diary of Jornal tiddlers. I am looking for a filter to store those tiddlers under diary subfolder on my file system. I tried below with no success.

[all[]contains:diary<currentTiddler>addprefix[diary/]]

What is the working filter here?

Some references

Example file structure
Assume a tiddler called “16th August 2024” and has a diary field with: One Two [[Thirty Four]], then file system path filter shall save tiddlers as below file structure.

tiddlywiki.info
tiddlers/
├─ diary/
   ├─ one.tid
   ├─ two.tid
   ├─ thirty_four.tid
├─16th_august_2024.tid

Just a guess, assuming the first part of your filter works:

[all[]contains:diary<currentTiddler>then<currentTiddler>addprefix[diary/]]

Fred

2 Likes

Thank you Fred! This does not work!
I know when tiddler saved (e.g. changed and saved) will be written to disk!
But nothing happened by above filter.

1 Like

I also tried this:

[all[]contains:diary<currentTiddler>] :map[<..currentTiddler>addprefix[diary/]]

Still no success!

Maybe this (untested):

[all[]contains:diary<currentTiddler>get[diary]enlist-input[]] :map[<..currentTiddler>addprefix[diary/]]
  • find all tiddlers for which the diary list contains the current tiddler
  • get that diary list as separate tiddler titles
  • for each of those titles, add the “diary/” prefix

-e

Please carefully read the documentation and the description, of the example configuration again.

The $:/config/FileSystemPaths tiddler contains filter expressions, that evaluate the currentTiddler against all filters.

The first filter that creates a result will be used.

  • So if you want to have a special path for every tiddler that has a diary field the filter is: [has[diary]]
  • Then you need to add a prefix eg: addprefix[diary/], which defines the path.
  • The “slash” / is the same for windows and linux systems. It will be normalized by the code.

So you should use: [has[diary]addprefix[diary/]]

So all tiddlers that have a diary field, even if it is empty will land in the /tiddlers/diary/ subdirectory.

-m

Ok, I gave the filter another try with a few test tiddlers on tiddlywiki.com and using Saq’s trick described in your link.

I got it to work with this complete filter:

[all[tiddlers]contains:diary<currentTiddler>then<currentTiddler>addprefix[diary/]]
[is[system]!has[draft.of]removeprefix[$:/]addprefix[_system/]]
[is[draft]search-replace:g:regexp[/|\\],[_]addprefix[drafts/]]
[tag[task]addprefix[mytasks/]]
[!tag[externalnote]addprefix[wiki/]]

Notes:

  • I had to place the filter higher in the filters list, before the “catchall” last line
  • I had to replace all[] by all[tiddlers] because the former means “copy every tiddler from my input to my output”, so it’s like a “do nothing” operator.

Fred

As I wrote [all[tiddlers]] should not be there at all.

$:/config/FileSystemPaths filters assume [all[current]] as the starting input

Oh, I see, you published your answer while I was writing mine! :slightly_smiling_face:

What I understood of OP is that tiddlers listed in the diary field of any other tiddler should get a diary/ prefix, hence my answer. Maybe I misunderstood?

Fred

Thank you Mario.

The question is to find a file system path filter to store tiddlers appear in diary field of other tiddlers, in diary sub folder. The tiddlers have diary field is not the question.

So assume a tiddler called “16th August 2024” and has a diary field with: One Two [[Thirty Four]], then file system path filter shall save the One Two [[Thirty Four]] into diary subfolder.

tiddlywiki.info
tiddlers/
├─ diary/
   ├─ one.tid
   ├─ two.tid
   ├─ thirty_four.tid
├─16th_august_2024.tid

Every path in TW has to be a subdirectory of /tiddlers/ – So it has to be /tiddlers/diary/*

I think your usecase can not be done with this configuration. It does not change other tiddlers. So if 16th_august_2024.tid is saved, it is the only tiddler that is handled.

If “One” is saved it does not look at other tiddlers, except “One”.

I would need to run more tests and probably have look into the code, to see if that would be possible.

The main problem I see, will be performance. Checking every other tiddler for a field value if it contains currentTiddler will be slow, if the number of tiddlers is high.

That is quite true! I revised the file structure in my previous post!

Using the @saqimtiaz trick here: Tagging operator is not working inside $:/config/FileSystemPaths - #5 by saqimtiaz I was able to find the filter. So my final filters in $:/config/FileSystemPaths is as below

[has[title]] :filter[all[tiddlers]contains:diary<currentTiddler>] :and[addprefix[diary/]]
[is[system]!has[draft.of]removeprefix[$:/]addprefix[system/]]
[is[draft]search-replace:g:regexp[/|\\],[_]addprefix[drafts/]]

As @pmario said, all tiddlers and sub directories will reside under tiddlers directory as long as the tiddlywiki.info does not alter the default-tiddler-location.

Strangely [has[title]] is required at the beginning of this filter. So, if you use [all[tiddlers]contains:diary<currentTiddler>] :and[addprefix[diary/]], it does not work!

Thank you all for your valuable inputs.

1 Like

ahh – OK. That’s tricky. But still have a look at the performance if there are 5k or 10k+ tiddlers.

Interesting discussion. Worth to be added as an example to docs.

Only for curiosity I tried below filter:

[has[title]listed[diary]] :map[get[title]addsuffix[/diary/]addsuffix<..currentTiddler>]

It works too, but strangely <..currentTiddler> is ignored, so the title of tiddler is ignored and I get .tid file on the disk. I submitted a ticket here: [BUG] Map and the Value of the Variable currentTiddler Outside the Filter run in File System Paths · Issue #8520 · TiddlyWiki/TiddlyWiki5 (github.com)

It’s important to note that simply adding an existing tiddler to the dairy field of other tiddlers does not move it to the diary directory. A tiddler will only be stored under the diary directory if you modify the tiddler itself and then save it back to the disk.