I am keen to continue with the idea of an interactive way to build a Plugin Library, primarily because I think it would provide a better way to share plugins and tiddlers, not just to the world but between managed wikis on one desktop or the LAN. Below are some ideas that may help someone with the background knowledge to help send me in the right direction.
- perhaps you can read through this and contribute?
- Do you have a published/public library you can zip all the resulting files and send to me? @pmario or @Mohammad perhaps?
- With that I can possibly reverse engineer this.
I believe I am 90% of the way to a solution.
But first;
Perhaps we could make a wiki, not unlike the upgrade wiki on which you drop a set of plugins and/or tiddlers. It would then construct a library tiddler, the library and the payload files by pushing them into a Zip tiddler and file for download to the libraries URL.
- It seems that tiddlyWiki now has fundamentally different features since the original library generation function was developed, and it was primarily to build the core plugin library.
I discovered on an install of Bob.exe the plugin $:/plugins/tiddlywiki/pluginlibrary containing the following tiddlers;
-
$:/plugins/tiddlywiki/pluginlibrary/asset-list-json
- Is only used to set a variable containing a list of asset tiddlers, according to items in a non-existent tiddler $:/UpgradeLibrary/List, I placed two tiddler titles in this tiddler and it seems to recognise them.
-
$:/plugins/tiddlywiki/pluginlibrary/readme
-
$:/plugins/tiddlywiki/pluginlibrary/library.template.html
- transcludes the other two tiddlers (not readme) effectively inside a HTML page.
- This seems to populate the above HTML page for saving to make the library root html files.
- If you view as HTML (preview) it seems to be valid, but I don’t know if it needs a specific filename Full HTML copy below
-
$:/plugins/tiddlywiki/pluginlibrary/libraryserver.js
- The Guts of this appears to be $:/plugins/tiddlywiki/pluginlibrary/libraryserver.js and is presented below.
-
The titles listed in $:/UpgradeLibrary/List appear inside the "rendered HTML as follows;
<code>var assetList = </code>$:/plugins/tiddlywiki/menubar
$:/plugins/tiddlywiki/internals<code>;
</code>
<pre><code>/*\
- The assetList is used to name the tiddlers.
- If you trawl through the included JavaScript you can see how it tries to get these “assets”.
What do I need now?
- I basically need to understand what is normally retrieved from the plugin files, or tiddlers and the necessary files and layout that are included so I can replicate this from my single file wiki.
Reference material for you convivence follows.
- This is the resulting Library tiddler rendered in HTML
<p><!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="application-name" content="TiddlyWiki Plugin Library" />
<meta name="application-version" content="v0.0.0" />
<meta name="copyright" content="Copyright 2015 Jeremy Ruston" />
<link id="faviconLink" rel="shortcut icon" href="favicon.ico">
<title>Plugin Library</title>
<script>
<code>var assetList = </code>$:/plugins/tiddlywiki/menubar
$:/plugins/tiddlywiki/internals<code>;
</code>
<pre><code>/*\
title: $:/plugins/tiddlywiki/pluginlibrary/libraryserver.js
type: application/javascript
module-type: library
A simple HTTP-over-window.postMessage implementation of a standard TiddlyWeb-compatible server. It uses real HTTP to load the individual tiddler JSON files.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
// Listen for window messages
window.addEventListener("message",function listener(event){
console.log("plugin library: Received message from",event.origin);
console.log("plugin library: Message content",event.data);
switch(event.data.verb) {
case "GET":
if(event.data.url === "recipes/library/tiddlers.json") {
// Route for recipes/library/tiddlers.json
event.source.postMessage({
verb: "GET-RESPONSE",
status: "200",
cookies: event.data.cookies,
url: event.data.url,
type: "application/json",
body: JSON.stringify(assetList,null,4)
},"*");
} else if(event.data.url.indexOf("recipes/library/tiddlers/") === 0) {
var url = "recipes/library/tiddlers/" + encodeURIComponent(removePrefix(event.data.url,"recipes/library/tiddlers/"));
// Route for recipes/library/tiddlers/<uri-encoded-tiddler-title>.json
httpGet(url,function(err,responseText) {
if(err) {
event.source.postMessage({
verb: "GET-RESPONSE",
status: "404",
cookies: event.data.cookies,
url: event.data.url,
type: "text/plain",
body: "Not found"
},"*");
} else {
event.source.postMessage({
verb: "GET-RESPONSE",
status: "200",
cookies: event.data.cookies,
url: event.data.url,
type: "application/json",
body: responseText
},"*");
}
});
} else {
event.source.postMessage({
verb: "GET-RESPONSE",
status: "404",
cookies: event.data.cookies,
url: event.data.url,
type: "text/plain",
body: "Not found"
},"*");
}
break;
}
},false);
// Helper to remove string prefixes
function removePrefix(string,prefix) {
if(string.indexOf(prefix) === 0) {
return string.substr(prefix.length);
} else {
return string;
}
}
// Helper for HTTP GET
function httpGet(url,callback) {
var http = new XMLHttpRequest();
http.open("GET",url,true);
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
callback(null,http.responseText);
}
};
http.send();
}
})();
</code></pre>
</script>
</head>
<body></p><p><h1>HelloThere</h1></p><p><p>This is the TiddlyWiki plugin library. It is not intended to be opened directly in the browser.</p></p><p><p>See <a href="https://tiddlywiki.com/" target="_blank">https://tiddlywiki.com/</a> for details of how to install plugins.</p></p><p></body>
</html></p>