Is this the smallest wikitext to package a plugin?

Hello everyone! I’m currently working on https://plugin-library.tiddlyhost.com, a setup that allow anyone to create its own plugin library hosted on tiddlyhost. To make this work, everything needs to be in the wiki file, so to keep things loading fast I’m trying to do everything I can to keep the code as small as possible.

I’m now working on optimizing the plugin maker of this library. Can you make this even smaller?

\function .get() [<tiddler>get{!!title}]

\function json.fields(tiddler,exclude)
-"ℹ️Get the list of relevant fields that are not empty"
[<tiddler>fields:exclude:<exclude>]:filter[.get[]]

-"ℹ️Get the value of each field and reduce to a json object."
:reduce[<accumulator>jsonset{!!title},<.get>]~{}
\end

\function json.tiddler(tiddler,exclude)
-"ℹ️Get the fields of a tiddler as a json object."
[json.fields<tiddler>,<exclude>]

-"ℹ️Map the result to a tiddler json object."
:map[["$(tiddler)$":$(currentTiddler)$]substitute[]]
\end

\function json.tiddlers()
-"ℹ️Default filter"
[<plugin>plugintiddlers[]] [prefix<plugin>!<plugin>] 

-"ℹ️Additional tiddlers to include"
[subfilter<filter>]

-"ℹ️Transform the list of tiddlers to json (text content for the plugin)"
:map[json.tiddler{!!title},[created creator modified modifier title]]
+[join[,]]
:map[[{"tiddlers": {$(currentTiddler)$}}]substitute[]]
\end

\function to.plugin(plugin,filter)
-"ℹ️Add the packaged tiddlers to the plugin text field"
[json.tiddlers[]]:map[json.fields<plugin>,[created creator modified modifier text]jsonset[text],{!!title}]
\end

Demo (without comments): share

5 Likes

Shouldn’t be like (note to colons)

[<tiddler>fields:exclude<exclude>]:filter[.get[]]

I love the trick you have used to inject comments into the functions :wink:

1 Like

You’re absolutely right! I missed it because the syntax is forgiving:

Thanks for catching that, @Mohammad!

I think I first saw this trick from @TW_Tones a while back, but I might be misremembering. :sweat_smile: It would be great to have an official way to add comments to filter runs, this trick doesn’t work in every scenario (if I’m recalling correctly).

1 Like