mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-03 12:23:51 +00:00
Allow templating of URLs for TiddlyWebAdaptor
Templates for TiddlyWeb URLs are defined in the tiddler `$:/config/tiddlyweb/host` as a string that can include `$protocol$` and `$host$`. The default is `$protocol$//$host$/`
This commit is contained in:
parent
5994a84644
commit
892b24d6e1
@ -12,12 +12,28 @@ A sync adaptor module for synchronising with TiddlyWeb compatible servers
|
|||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var CONFIG_HOST_TIDDLER = "$:/config/tiddlyweb/host",
|
||||||
|
DEFAULT_HOST_TIDDLER = "$protocol$//$host$/";
|
||||||
|
|
||||||
function TiddlyWebAdaptor(syncer) {
|
function TiddlyWebAdaptor(syncer) {
|
||||||
this.syncer = syncer;
|
this.syncer = syncer;
|
||||||
this.host = document.location.protocol + "//" + document.location.host + "/";
|
this.host = this.getHost();
|
||||||
this.recipe = undefined;
|
this.recipe = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TiddlyWebAdaptor.prototype.getHost = function() {
|
||||||
|
var text = this.syncer.wiki.getTiddlerText(CONFIG_HOST_TIDDLER,DEFAULT_HOST_TIDDLER),
|
||||||
|
substitutions = [
|
||||||
|
{name: "protocol", value: document.location.protocol},
|
||||||
|
{name: "host", value: document.location.host}
|
||||||
|
];
|
||||||
|
for(var t=0; t<substitutions.length; t++) {
|
||||||
|
var s = substitutions[t];
|
||||||
|
text = text.replace(new RegExp("\\$" + s.name + "\\$","mg"),s.value);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
};
|
||||||
|
|
||||||
TiddlyWebAdaptor.prototype.getTiddlerInfo = function(tiddler) {
|
TiddlyWebAdaptor.prototype.getTiddlerInfo = function(tiddler) {
|
||||||
return {
|
return {
|
||||||
bag: tiddler.fields["bag"]
|
bag: tiddler.fields["bag"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user