mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-03-01 09:20:02 +00:00
Add setquerystring operator
This commit is contained in:
parent
261f0f5261
commit
9288420c67
@ -13,25 +13,11 @@ Filter operators for URL operations
|
||||
"use strict";
|
||||
|
||||
exports["setquerystring"] = function(source,operator,options) {
|
||||
var URL = $tw.browser ? window.URL : require("url").URL,
|
||||
URLSearchParams = $tw.browser ? window.URLSearchParams : require("url").URLSearchParams,
|
||||
name = operator.operands.length >= 1 ? operator.operands[0] : null,
|
||||
var name = operator.operands.length >= 1 ? operator.operands[0] : null,
|
||||
value = operator.operands.length >= 2 ? operator.operands[1] : "",
|
||||
results = [];
|
||||
source(function(tiddler,title) {
|
||||
var url;
|
||||
try {
|
||||
url = new URL(title);
|
||||
} catch(e) {
|
||||
}
|
||||
if(url) {
|
||||
var params = new URLSearchParams(url.search);
|
||||
if(name) {
|
||||
params.set(name,value);
|
||||
}
|
||||
url.search = params.toString();
|
||||
results.push(url.toString());
|
||||
}
|
||||
results.push($tw.utils.setQueryStringParameter(title,name,value));
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
@ -10,6 +10,7 @@ title: Output
|
||||
<$let lf={{{ [charcode[10],[13]]}}}>
|
||||
|
||||
<$text text={{{
|
||||
[[$$$]setquerystring[habitat],[desert]]
|
||||
[<url>setquerystring[]]
|
||||
[<url>setquerystring[animal],[elephant]]
|
||||
[<url>setquerystring[animal],[elephant]setquerystring[animal],[ostrich]]
|
||||
@ -21,6 +22,7 @@ title: Output
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
$$$
|
||||
https://tiddlywiki.com/
|
||||
https://tiddlywiki.com/?animal=elephant
|
||||
https://tiddlywiki.com/?animal=ostrich
|
||||
|
Loading…
x
Reference in New Issue
Block a user