Deprecated: Return type of I::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 62

Deprecated: Return type of I::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 91

Deprecated: Return type of I::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 71

Deprecated: Return type of I::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 101

Deprecated: Return type of I::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 53

Deprecated: Return type of Collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/collection.php on line 80

Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in /home/public/kirby/toolkit/lib/url.php on line 135
One Tap Less | Clean Markdown Links in Riposte

Clean Markdown Links in Riposte

One cool thing about most App.net clients is their support for Markdown links. Wrap the title in brackets, followed by the link between parenthesis and you're good to go. What about sharing some links straight from Safari to Riposte as Markdown links?

The Easy Way

We'll dive into the world of bookmarklets again and, as you may guess, I have plenty of those in my Safari. This exercise will introduce you to Riposte's URL scheme and also refresh your mind on how to build a bookmarklet.

The url to create a new post in Riposte is as follows:

riposte://x-callback-url/createNewPost?text=Hello%20World

This will create a Hello World message, but what we really want is to grab the title and url of the current page we're visiting in Safari. For the title we use document.title, meanwhile for the url we go with location.href. We also must URL encode this content and add our Markdown link syntax. The outcome will look like this:

javascript:window.location='riposte://x-callback-url/createNewPost?text='+encodeURIComponent('['+document.title+']('+location.href+')')

But what if we wanted to put Clean Links into the mix to remove all that crap people attach to links these days? Well, let's say things can get quite nasty.

The Hard Way

Remember when we discussed the retParam in 1Writer? Well, Clean Links has that as well, but turns out it doesn't help in our situation since we want to modify the output and the retParam doesn't allow that as far as I'm concerned. Yet, Clean Links has another kind of output: the clipboard. But how can I send the clipboard to Riposte? Using Drafts, of course! Now that I got your head all messed up, let's start this bookmarklet backwards:

riposte://x-callback-url/createNewPost?text=[[draft]]

You may be familiar with that URL, it is available in Drafts' Action Directory. Install it, the headache will get a lot easier by using Drafts' built-in action. Next we build the Markdown link using ||clipboard|| because we're power users.

javascript:window.location='drafts://x-callback-url/create?text='+encodeURIComponent('['+document.title+'](||clipboard||)')+'&action=Send%20to%20Riposte&afterSuccess=Delete'

Actually, I wanted to introduce you to the ||clipboard|| element in this article. From the official docs:

The /create action supports a special ||clipboard|| tag. If this tag is found in the "text" parameter, it will be replaced with the current contents of the device clipboard before creating the draft. This is particularly useful when used in x-success parameters when chaining URLs, when the clipboard might have changed while you were in another app.

Cool, right? If you skipped the quote, I'll let you know that [[clipboard]] wouldn't work in our case, it would send the tag, literally, to Riposte. To make use of it you'd need a custom action that creates the Markdown link using the [[draft]], which would be only the title, and then the clipboard, which wouldn't change since we triggered Clean Links. Confusing? Just stick to my example then.

After hours of trial and error, we're ready to include Clean Links, the first step is to encode everything we made so far and set it as the x-success parameter for Clean Links. The location.href must be encoded as well, so be careful with that.

javascript:window.location='clean-links://x-callback-url/clean?url='+encodeURIComponent(location.href)+'&x-success='+encodeURIComponent('drafts://x-callback-url/create?text='+encodeURIComponent('['+document.title+'](||clipboard||)')+'&action=Send%2520to%2520Riposte&afterSuccess=Delete')

We reviewed a few tricks for Riposte, the App.net crew goes wild, and our bookmarklet skills. We also saw the recently added ||clipboard|| parameter in Drafts and learned that getting rid of those url shorteners is harder than it sounds. See you next time, I promise it will be sooner.