janboddez / indieblocks

Use blocks, and, optionally, "short-form" post types to more easily "IndieWebify" your WordPress site.
https://indieblocks.xyz
GNU General Public License v3.0
22 stars 3 forks source link

Bookmarklets? #142

Open janboddez opened 7 months ago

janboddez commented 7 months ago

So, I never really felt the need for bookmarklets anymore, as:

  1. on mobile there's a few decent Micropub clients, and this plugin supports Micropub and (if applicable) will even attempt to convert your Micropub content to blocks, and set the correct post type; and
  2. on the desktop, we can just use WP Admin, copy-and-paste a URL and (possibly) some of the liked/bookmarked/replied-to page's content, etc.

However, it could be nice to have some sort of bookmarklet functionality, so that we can just select some text on a page, click the bookmark (or so) bookmarklet, hit "Publish."

Side note: one could also set up some "starter patterns," like, have a bookmark block already present for the "bookmark" pattern, etc. (Currently, only likes come with a "preinstalled" Like block, because a note can be different "post kinds" [including a like, even, haha].)

janboddez commented 7 months ago

It probably is possible to work off the existing Press This plugin/bookmarklet, although it'll likely need modified (a bit).

Like, on the JS side, might have to add a post type (manually, once for each [type of] bookmarklet).

Because the default interface does not support a post type field (yet). And I don't think it's filterable either. Although there is a button to switch to the "regular" editor, where, if you have a post type switcher plugin installed, you could select a post type. Only thing is it breaks IndieBlocks' automatic slug function.

And then on the server side we can have a filter callback pick this up.

And, additionally, have the submitted content set as a certain "Indie" block's InnerBlocks, for instance.

janboddez commented 7 months ago

Alternatively, it might be possible to just do, you know, https://example.org/wp-admin/post-new.php?post_type=indieblocks_like&url=http://example.net or something, and have the block code pick up that URL. Not sure if we want that, though? I mean, I don't think it's any different, really, from those "Share on Twitter" and so on links?

That wouldn't be too different from copy-and-pasting the URL, although it would save you a few clicks. You'd lose the possibility to select text and whatnot, though. Compared to "Press This," I mean.

cagrimmett commented 7 months ago

I also use Micropub on mobile. Since I'm on iOS, I made shortcuts to post with Micropub: https://cagrimmett.com/development/2023/02/12/ios-shortcut-actions-for-micropub-posting/

The main reason I asked about this on Mastodon in the first place is that I was hoping to reduce the few clicks on desktop :) What I had in mind was something like &url=https://example.com on the end of the URL (though in this particular example &url is used for the Embed block) and maybe a &quote to pass highlighted text to an innerblock. In this case it would open up a browser tab with the url and highlighted content pre-filled so I can edit and press publish. I briefly glanced over the block code and didn't see anything, so I thought I'd ask.

It isn't a blocker in any way, as there are options, just a nice to have. Thanks for your consideration!

janboddez commented 3 months ago

(Don't mind me, just going through some old issues here ...)

So, one reason I didn't pick this up (other than not really needing it myself 😬) is me typically being overly paranoid about "CSRF attacks" and the like.


Like, adding a URL to a IndieBlocks block will typically, or eventually, fire off a server-side fetch of the resource at that URL. Which may very well be harmless. [We do limit response sizes, for instance.]

Or you could be adding, I don't know, invisible text or something to your post. Like, if someone sent you a link that'd send you to the Create Post screen with some params pre-filled. [Although we should probably strip all HTML tags and whatnot.]

And, even though you'd still need to press Publish, a draft of the post may get saved without user interaction.

I'm guessing the bookmarklet would pick up the current URL + window.getSelection() or something, and then tack those onto, e.g., https://example.org/wp-admin/post-new.php?post_type=indieblocks_note and forward the user to that page?


Note to self: looks like wp.data.dispatch('core/editor').insertBlocks() may allow us to inject a block into the editor. So we could look for a certain URL parameter, set up a block if it's there, then inject it into the editor.

janboddez commented 3 months ago

Note to self: looks like wp.data.dispatch('core/editor').insertBlocks() may allow us to inject a block into the editor. So we could look for a certain URL parameter, set up a block if it's there, then inject it into the editor.

Ha, so we could potentially have something like https://example.org/wp-admin/post-new.php?post_type=indieblocks_note&kind=bookmark and at least add an (empty) bookmark block. (Or maybe we should pick a different name for the arg, to not interfere with Post Kinds.)

Not quite there, but it'd save a couple clicks. (Wouldn't have to select either a block pattern nor click in the editor and type /boo or something until the block can be selected.)