siteorigin / tinymce-google-search

WIP: Adds Google custom search to TinyMCE
0 stars 0 forks source link

Initial Version #1

Open gregpriday opened 3 years ago

gregpriday commented 3 years ago

Google Docs has a useful feature where a user can perform a Google search for pages to create a link.

Screenshot 2021-02-19 at 07 55 21

We could add a similar feature to TinyMCE that allows users to search using Google Programmable Search Engine. Programmable Search Engine (PSE) allows a user to specify which sites/domains will be used to return results. So users of this TinyMCE plugin could choose to only show results from their own sites, or network of sites.

This feature would be perfect for creating a strong interlinking site structure.

The best way to approach this would be to add a custom button to TinyMCE. Clicking on this button should open a small modal window with a search input field, along with some results. The text the user has selected when they click the button should be autofilled into this search field. Clicking on one of the results would turn the users selected text into a link.

It might even be possible for this plugin to simply enhance the existing insert link functionality of TinyMCE, but if that's not possible, then a separate toolbar button would be perfect.

We want to emulate the layout and functionality of the Google Docs feature as closely as possible, while fitting in to the TinyMCE design.

Requests to Google Programmable Search

Ideally, this plugin should work without a server. So the Javascript should make requests directly to the PSE API. Google do have an Javascript API client, but bundling this with the plugin might be too much.

This plugin could probably just make API requests using core JS functionality.

The developer would need to add their PSE API key and search engine ID through the plugin configuration arguments.

Compatibility

Ideally, this plugin should be compatible with TinyMCE 4 and 5. WordPress (using the Classic Editor plugin) is still using version 4. Nova TinyMCE uses version 5 though.

AlexGStapleton commented 3 years ago

It might even be possible for this plugin to simply enhance the existing insert link functionality of TinyMCE

We could do this by simply setting a callback for link_list, and populating the list based on the search results.

https://www.tiny.cloud/docs/plugins/opensource/link/#exampleofacustomasynchronouscallbackfunction https://www.tiny.cloud/docs-4x/plugins/link/#link_list

WordPress uses a custom link plugin but you're able to filter those results with the wp_link_query filter or by overriding wpLink directly (it's not updated that often so casual monitoring should be fine to avoid breakage).

The potential issue with going this route is that it likely won't play well with anything that also overrides link_list/wpLink also. The trade-off of that risk however is that it's more seamless as having two buttons to basically do the same thing is... well, it's a bit much. Do you want to go down this path, or the custom button path?

gregpriday commented 3 years ago

I think we should go the custom tool/button route. Having the search field for the user to search for a different query is also some key functionality we don't want to lose out on.