Importing New Tiddlers From URL

Hey everyone,
I’m trying to use a single page HTML Tiddlywiki on mobile. Since I can’t drag URLs into my wiki I was hoping to be able to copy/paste a URL into some input field and execute the same import that happens when you drag / drop.

I didn’t know if this is something that already exists either through a plugin or built in and I haven’t seen it.

Thank you so much!

I’m using 5.2.7

There is the Tools → Import Button in the right sidebar. … But it opens an import dialogue. … Not sure, if that is what you want.

Can you be a bit more specific, about “copy/paste a URL”. …

  • What does the URL contain, and
  • how should it be imported.

Sadly this isn’t possible that way. Dragging means giving local object to browser window, not to upload object by URL. So you must go another way.

For example, open your wanted URL, save to device and then import to wiki by choosing file (on side of Import button is Browse button to select local file) and choose local file and import it.

By general security reason, on mobile devices most of browsers won’t call URL as local object in browsing for web browser, it works only on Windows, for example in classic Open dialog you can give URL of file and it will be loaded, but this won’t work on mobile architecture.

This lets me upload a file, but I really want to take the .json (or whatever file) from the Internet and import it into my wiki. I will expand on this a bit more with my reply to Michal.

It sound at least like it’s not possible in standard TiddlyWiki but I’m confused, Javascript downloads and executes stuff all the time, no? I might need a CORS header on the server but I feel like the below should work?

fetch('https://example.com/tiddlywiki_backup.json')
  .then(response => response.json())
  .then(data => {
    // Use the retrieved JSON data here
    console.log(data);
  })
  .catch(error => {
    // Handle any errors that occur during the fetch
    console.error(error);
  });

I’m not sure how much this helps, but this is possible. Storing Tiddlers in the Clipboard

I did see this, it’s going the other direction (I want to import not export)… HOWEVER… I do also want to export easily and this is a nice starting place.

I’m kinda surprised (which makes me think I’m missing something) since it seems so much of Tiddlywiki is built around importing content in from outside sources and this basic functionality already exists in core, that it’s a logical next step (and honestly the logical first step of the evolution) to be able to set a URL.

Not really for mobile, but the tamper monkey script listed there makes it work for importing as well.

1 Like

It sounds useable, main problem can be security restriction to fetch from URL in browser itself.

Please, let me know if it works, interesting way.

@teamcoltra

Perhaps this new feature WidgetMessage: tm-http-request offers a pathway to what you want, if you specificaly want to import bunches of tiddlers have a closer look at the plugin mechanisium, because this retrieves tiddlers from libraries.

  • keep in mind if one can change a website by simply providing a URL without some kind of user interaction it can present risks, be although you may limit it to tiddlers it is a way to “inject code” at least if it is saved and subsequently reloaded, which can be facilitated if using local storage.
    • No I dont like “the security tail, wagging the desiner dog” but we need to be realistic, and getting content signed and other posibilities should be possible.
  • If you dont control the content at the end of the URL you may be giving others to more than you think.

There are also posibilities packing tiddlers in data urls and my preference is bookmarklets. But I think I need to understand the larger picture more before recomending a solution.

1 Like

It is entirely possible in TW v5.3.0, if the server with the content to download has CORS headers on the server. However this very requirement is also why it isn’t a universal solution.

Here is some example code that imports a TiddlyWiki from a given URL, and triggers the import process. This will select all non-system tiddlers, it could easily be tweaked to only select the tiddlers identified in the URL hash.

\define loadWikiActions(wikiURL)
	<!-- actions invoked after fetching the remote data -->
	\define getWikiCallback()
		<!-- actions to turn the remote data into tiddlers -->
		\define importTiddlers()
			<$let
				tiddlerJSON={{{[<data>deserialize[application/json]]}}}
				tempTitle="$:/Import"
				tiddlers={{{ [<tiddlerJSON>jsonindexes[]] :map[<tiddlerJSON>jsonget<currentTiddler>,[title]] :and[format:titlelist[]join[ ]] }}}
			>
				<$navigator story="$:/StoryList">
					<$action-sendmessage
						$message="tm-import-tiddlers"
						$param=<<tiddlerJSON>>
						importTitle=<<tempTitle>>
						autoOpenOnImport="yes"
					/>
					<$action-setmultiplefields
						$tiddler=<<tempTitle>>
						$fields="[enlist<tiddlers>is[system]addprefix[selection-]]"
						$values="[enlist<tiddlers>] :map[[unchecked]]"
					/>
				</$navigator>
			</$let>
		\end importTiddlers
		<!-- actions invoked if there is an error fetching the data -->
		\define failureHandler()
			<$action-log status="error fetching the wiki"/>
			<$action-setfield $tiddler={{{ [[$:/temp/http/error/]addsuffix<now [UTC]YYYY0MM0DD0hh0mm0ssXXX]>] }}} text={{{ [[There was an error fetching the wiki ]addsuffix<wikiURL>addsuffix<error>] }}} tags="$:/tags/Alert"/>
		\end failureHandler
		<$list filter="[<status>match[200]]" variable="null" emptyValue=<<failureHandler>> >
			<$action-log data=<<data>> status="succcess" />
			<<importTiddlers>>
		</$list>
	\end getWikiCallback

	<!-- fetch the remote data source-->
	\define getWikiActions()
		<$action-sendmessage
			$message="tm-http-request"
			method="GET"
			bind-status={{{ [[$:/temp/http/]addsuffix<wikiURL>] }}}
			oncompletion=<<getWikiCallback>>
			url=<<wikiURL>>
			var-wikiURL=<<wikiURL>>
			>
	\end getWikiActions
<$list filter="[{$:/temp/import-from-url}!is[blank]]" variable="wikiURL">
<<getWikiActions>>
</$list>
\end loadWikiActions

<$edit tiddler="$:/temp/import-from-url" tag="input" class="tc-edit-texteditor" placeholder="Enter permalink here"/>
<$button actions=<<loadWikiActions>>>import</$button>
1 Like

Pretty impressed with @saqimtiaz way of accomplishing this with wikitext.

I have had a lot of luck over the years with this macro I found in the old google groups:

https://groups.google.com/g/tiddlywiki/c/E_X3KUHOvEk/m/ucL23ju5AAAJ

I also recently pulled a bunch of hacks like that one together into the hello-json-advanced plugin.

1 Like

@teamcoltra I just reread this thread, and realised we did not discuss this in more detail because you did not give much of an explanation at the beginning.

If you want to import a json file of tiddlers you can use the Import button and paste the full path and filename in the place of the filename, in windows at least. It will import the JSON and trigger the import dialogue as occurs with drag and drop of such files.

However if you want to import a JSON file of tiddlers, or otherwise and you don’t want to trigger the import process you can make a custom browse button, that forces it to be imported as plain/text, you can then do what you want with the imported tiddler.

<$browse deserializer="text/plain"/>

But are you wanting to import the URL itself?

  • There is plenty of options for that as well