How to Drop a link in a tiddler to create a subtiddler with the link as a field value?

I am a total beginner with the https://tiddlywiki.com/#DragAndDropMechanism.

I would like to build the following system :

  • a tiddler “List of books” is open
  • drag an internet link to the “List of books”
  • this trigger the creation of a tiddler “NewBook” with the field link automatically filled with the dropped link

How to drag the link into a chosen tiddler?
What to do after that?

Here’s a very basic example to get you started

\define drop-actions()
<$let dropped-link={{{ [<event-param>jsonget[0],[text]] }}} >

<$action-createtiddler $basetitle="NewBook" tags="book"
link={{{ [<dropped-link>split[
]first[]] }}}
text={{{ [<dropped-link>split[
]butfirst[]] }}}>

</$let>
\end

<$messagecatcher $tm-import-tiddlers=<<drop-actions>>>
<$dropzone class="books-import">
<ul>
<$list filter="[tag[book]]" emptyMessage="Drag a link here to add a book to the list">
<li>{{||$:/core/ui/Buttons/delete}} <a href={{!!link}}><$view field="text"><$text text={{!!link}}/></$view></a></li>
</$list>
</ul>
</$dropzone>
<$messagecatcher>

<style>
.books-import li>button{
float:left;
}
.books-import a>p{
display:contents;
}
.books-import.tc-dragover{
border: 2px dashed <<colour dropzone-background>>;
}

.books-import.tc-dragover:before{
content: "<<lingo DropMessage>>";
}
</style>

https://demos.tiddlyhost.com/#List%20of%20books

EDIT: Here’s a short explanation of what the code above does :

The dropzone widget send a tm-import-tiddlers message when a drop event is fired. Usually, this message is handled by the navigator widget and it opens the $:/Import tiddler + update the story, to prevent that, I used a messagecatcher widget. When it receive the tm-import-tiddlers message, the macro drop-actions is executed.

When a link is dropped on the wiki, it’s actually in a json form, so this macro get the json that is saved in the variable event-param, then create a tiddler with a base title of NewBook, a book tag, set the text field to the text content of the link, and the link field to the link dropped.

The list show every tiddler tagged with book, so it is updated and the link you dropped is listed.

This doesnt handle the BibText format but you could probably extend this code to detect if the input is in the bibtext format or not and save the data as appropriate. The bibtext plugin could help, I guess.

4 Likes

@TartakOO,

Since you mention a list of books, I do wonder whether you are aware of the RefNotes plugin (by Mohammad), and other work for bibliographies that people have compiled here.

One good thing about RefNotes is that it works with BibTex input (which is easily ported around in JSON format). Refnotes has a “paste zone”… But I also have a drop-zone version here as a sidebar:

https://springerspandrel.github.io/tw/biblio-demo#BibTex%20sources

BibTex stuff can be grabbed from google scholar, and I love that I automatically get lots of key fields filled in. (I then follow up manually to paste in a url for the book’s cover image, and often I add an abstract as well.)

TiddlyWiki is amazing for books!

-Springer

3 Likes

@telumire thx a lot for the detailed explanations, this is exactly what I was looking for.

@Springer thx too, I probably won’t develop my own books system, this is more a proof of concept to understand the mechanics, and books were an easy example to grasp.

1 Like