I haven’t really tested this since I don’t use [img[]]
constructions in any of my wikis, but perhaps it can get you started:
<$let
imgfile="\.(jpg|png|gif)"
rb="]]"
img="[img["
>
<$button>New Tiddlers
<$list filter="[all[tiddlers]!is[system]!is[shadow]search:text:regexp<imgfile>]" variable="tid">
<$list filter="[<tid>get[text]split<rb>] :map[split<img>butfirst[]] +[regexp<imgfile>!is[tiddler]]" variable="imgs">
<$action-createtiddler
$basetitle={{{ [<imgs>split[/]last[]] }}}
_canonical_uri=<<imgs>>
type=`image/${ [<imgs>split[.]last[]] }$`
label="">
<$action-listops $field="output" $subfilter="[<createTiddler-title>]" />
</$action-createtiddler>
</$list>
</$list>
</$button>
</$let>
Some notes:
- I don’t seen any particular benefit to using the
format:titlelist[]join[ ]
+ enlist
combination here (and also note that, in your original variable definitions, you have an unnecessary enlist-input[]
in tids=
and would need enlist<tids>
in imgs=
).
-
+[regexp<imgfile>!is[tiddler]]
in the second $list means that the button will only create a new image tiddler if you don’t already have a tiddler by that title. This should prevent you from overwriting/duplicating anything.
- I used
$action-createtiddler
in place of <$action-sendmessage $message="tm-new-tiddler"
so the newly-created tiddlers won’t be immediately added to your story river (which seemed likely to cause problems if you have more than a few!)
- I added the
type=
line to programmatically add an appropriate type
field based on the image file suffix. Without the correct tiddler type, _canonical_uri
won’t be handled correctly.
- I also added the
<$action-listops $field="output" $subfilter="[<createTiddler-title>]" />
, which adds each newly-created title to the output
field of the tiddler where you use this button.
- This will let you use, for example,
<<list-links "[enlist{!!output}]">>
to get a quick list of all the image tiddlers you’ve just added.
- If you don’t need this list, you can replace
>
<$action-listops $field="output" $subfilter="[<createTiddler-title>]" />
</$action-createtiddler>
in the above code with />