If we drag and drop a uri/url link from a browser address bar into a drop zone, it will have the “title” in the following form; [[https://plugins.tiddlyhost.com/ Plugins - for TiddlyWiki — Support on and libraries]]
Can we now find away to split this reliably?, as follows is not perfect?
{{{ [[https://plugins.tiddlyhost.com/ Plugins - for TiddlyWiki — Support on and libraries]split[ ]first[]] }}}
{{{ [[https://plugins.tiddlyhost.com/ Plugins - for TiddlyWiki — Support on and libraries]split[ ]bufirst[]join[ ]] }}}
I want to find a reliable method to do this so I can continue to store url/pretty links in this form?
For security reasons, regular browsers do not expose the path to the dragged file, which makes it impossible to construct a _canonical_uri tiddler.
The “External Attachments” plugin from the official plugin library does what you want but it requires the use of TiddlyDesktop instead of a regular browser.
my use case is really very special, I think.
Ok, let me describe what I am doing here.
I am member of a boyscott group and we have collected tons ons songs with lyrics and notes from the past. Of course all of them on paper. We scanned them and still collecting and scanning, so this is an ongoing process.
We decided to use tiddlywiki as songbook due to the fact that it is lean if we use it in this way as I describe it here.
We have one folder named “songbook” and there is only the tiddlywiki saved
We have several subfolders with the pdf files in this songbook folder
For each song we create a tiddler with the name of the song
3a. Some tags or fields will be added if we know who wrote the text and who made the melody, but this is optional. Also we add tags or fields if the song has a special character like “sea shanties”.
We add the path and filename as canonical_uri e.g. ./subfolder1./Blue mountains.pdf
Why we do that in this way? The community is big, really big.
In the past when we sit around the campfire and sing we used paper songbooks. If some of use don’t have the song available it was difficult and change them out.
We are in the 21st century now. Most of us have a tablet instead of paper songbook.
We don’t have always a internet available therefore we want to have a local working solution.
In the case that someone has a song in the songbook but some of us not we can easily export the tiddler and pdf and all of us are able to import the song to their own songbook. And sometimes we have meetings only to exchange the songs to each other.
Everything what will help us not to copy the filename and path from the explorer (or finder in case of using an apple device) and to paste it in the canonical_uri field and to have may be automatically the Tiddler named with the filename, will make the life easier.
Finally, why we do not import the pdfs directly? Simple we speak about hundreds of pdfs. The tiddlywiki songbook will be too big to use on a tablet or smartphone.
So, that is the use case. A little bit longer but helpfully to understand my super special private wish. And I understand that not always and everything can be realised. We are happy to have this tool.
In this sort of use, I think I would try to work in 2 times.
First you create a xls or csv file to create the database of your local files. You can there create as many columns as field you would like to insert in your tiddlers.
There is tools to bulk import the local links from a directory (for example : LibreOffice Calc 6 - "batch" hyperlink to files in folder? - English - Ask LibreOffice)
Then when the xls/csv file is ready use, install the XLSX Utils: XLSX spreadsheet utilities plugin from the TW official plugin library to import an create in the same time --ALL the tiddlers-- at once !
It needs a little bit of understanding of those tools, but you will gain a lot of time instead of manually modify your tiddlers. And the XLS file cans be used to easily modify fields by copy/paste and then push those modifications back to you wiki at any time…
why does using split[ ]first[] not work? URLs are not allowed to have spaces (see ietf.org/rfc/rfc3986.txt Appendix A for URI syntax) and so would need to be encoded. if an external link always imports with the URL first, then that should work?
Thank you for your answer but my problem is not the bulk import.
It is more the effort to copy the path and filename and to paste it in the canonical_uri field to the tiddler and to paste it also in the title.
What is not perfect about split[ ]first[]? Do you have a failing test case? As @Scribs said, the url part should not have spaces. I tried in firefox with a url having spaces (example https://tiddlywiki.com/#a%20b%20c%20d) and the filter worked fine. The filter won’t see $20 as a space.
What are you trying to accomplish with encoding the whole string?
@btheado I will just try and restate this; I am browsing a website and find a link on the page I want to keep, click and drag the link, drop on tiddlywiki and it imports an “Untitled” tiddler containing this;
Now I could just split on space and use split[ ]first[] to get the url and use the rest to get the pretty name magical mandarin recipes.
But is this always true?
are there other cases where a space can be part of the url?
I am keen to be able to drag and drop links and capture the link and its pretty name. I know how to do this but I am unsure if all the possible urls will obey this “all before the first space rule”.
Also if I drag and drop such a link on a list such as made by the list-links draggable macro, I get the example in the OT
[[https://plugins.tiddlyhost.com/ Plugins - for TiddlyWiki — Support on and libraries]] and it follows a similar pattern.
I can put an action on drop to convert this to a link eg `[[Plugins - for TiddlyWiki — Support on and libraries|https://plugins.tiddlyhost.com/]]
If this split on the first space “is the rule” then I will build a way to parse the links into tiddlywiki or html href’s with pretty link.
While from a URL syntax perspective you will be fine, be aware browsers behave differently.
If you open the javascript console and type $tw.log.IMPORT=true and they drag and drop the url, then you can see the dataTransfer object details.
In firefox it has the title information:
Available data types:
type text/plain https://tiddlywiki.com/
type text/x-moz-url https://tiddlywiki.com/ TiddlyWiki — a non-linear personal web notebook
type text/html <a href="https://tiddlywiki.com/">TiddlyWiki — a non-linear personal web notebook</a>
Importing data type 'text/x-moz-url', data: 'https://tiddlywiki.com/ TiddlyWiki — a non-linear personal web notebook'
But for me, chrome is putting much less data in the dataTransfer object and you don’t get the title:
Available data types:
type text/plain tiddlywiki.com
type text/uri-list https://tiddlywiki.com/
Importing data type 'URL', data: 'https://tiddlywiki.com/'
BTW, to drag the url, I click on the url address bar, the text highlights and I drag the highlighted text. Not sure if there is another way in which you are doing it.