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