From 016a062d5105a9c9b24c6805b059fc3e81907e02 Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Wed, 12 Feb 2020 15:54:03 -0800 Subject: [PATCH 1/4] Blocks: Update keywords for better search results Changes and adds keywords to a few blocks that will hopefully be easier to find now. --- extensions/blocks/map/settings.js | 2 +- extensions/blocks/pinterest/index.js | 4 ++- extensions/editor.js | 1 + extensions/shared/block-keywords.js | 46 ++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 extensions/shared/block-keywords.js diff --git a/extensions/blocks/map/settings.js b/extensions/blocks/map/settings.js index 9871d427053a6..b67a77285619f 100644 --- a/extensions/blocks/map/settings.js +++ b/extensions/blocks/map/settings.js @@ -26,7 +26,7 @@ export const settings = { ), category: 'jetpack', keywords: [ - _x( 'map', 'block search term', 'jetpack' ), + _x( 'maps', 'block search term', 'jetpack' ), _x( 'location', 'block search term', 'jetpack' ), _x( 'navigation', 'block search term', 'jetpack' ), ], diff --git a/extensions/blocks/pinterest/index.js b/extensions/blocks/pinterest/index.js index d29b3ca604afb..e588244aed6ee 100644 --- a/extensions/blocks/pinterest/index.js +++ b/extensions/blocks/pinterest/index.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { __ } from '@wordpress/i18n'; +import { __, _x } from '@wordpress/i18n'; import { G, Path, Rect, SVG } from '@wordpress/components'; import { createBlock } from '@wordpress/blocks'; @@ -34,6 +34,8 @@ export const settings = { category: 'jetpack', + keywords: [ _x( 'social', 'block search term', 'jetpack' ) ], + supports: { align: false, html: false, diff --git a/extensions/editor.js b/extensions/editor.js index 3d61997fa354f..50c98717e92ce 100644 --- a/extensions/editor.js +++ b/extensions/editor.js @@ -3,6 +3,7 @@ */ import './shared/public-path'; import './shared/block-category'; +import './shared/block-keywords'; import './shared/plan-upgrade-notification'; import './shared/stripe-connection-notification'; import analytics from '../_inc/client/lib/analytics'; diff --git a/extensions/shared/block-keywords.js b/extensions/shared/block-keywords.js new file mode 100644 index 0000000000000..139998e3f905d --- /dev/null +++ b/extensions/shared/block-keywords.js @@ -0,0 +1,46 @@ +/** + * External dependencies + */ +import { addFilter } from '@wordpress/hooks'; +import { _x } from '@wordpress/i18n'; +import { includes } from 'lodash'; + +/** + * Filters block registration to add keywords to core blocks. + * + * @param {Object} settings Block Settings. + * @param {string} name Block name. + * @return {Object} Filtered block settings. + */ +function addBlockKeywords( settings, name ) { + const social = _x( 'social', 'block search term', 'jetpack' ); + const survey = _x( 'survey', 'block search term', 'jetpack' ); + const video = _x( 'video', 'block search term', 'jetpack' ); + + switch ( name ) { + case 'core-embed/facebook': + case 'core-embed/instagram': + case 'core-embed/tumblr': + case 'core-embed/twitter': + if ( ! includes( settings.keywords, social ) ) { + settings.keywords.push( social ); + } + break; + + case 'core-embed/crowdsignal': + if ( ! includes( settings.keywords, survey ) ) { + settings.keywords.push( survey ); + } + break; + + case 'core-embed/hulu': + if ( ! includes( settings.keywords, video ) ) { + settings.keywords.push( video ); + } + break; + } + + return settings; +} + +addFilter( 'blocks.registerBlockType', 'jetpack/block-keywords', addBlockKeywords ); From a59c4cf582b60ec654abef522b48a486e0acc54d Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Thu, 13 Feb 2020 11:23:38 -0800 Subject: [PATCH 2/4] Make `maps` a separate keyword Just because `map` is part of `maps` in English, doesn't mean that that'll be the case in all languages. Props @marekhrabe --- extensions/blocks/map/settings.js | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/blocks/map/settings.js b/extensions/blocks/map/settings.js index b67a77285619f..606f790c5b75e 100644 --- a/extensions/blocks/map/settings.js +++ b/extensions/blocks/map/settings.js @@ -26,6 +26,7 @@ export const settings = { ), category: 'jetpack', keywords: [ + _x( 'map', 'block search term', 'jetpack' ), _x( 'maps', 'block search term', 'jetpack' ), _x( 'location', 'block search term', 'jetpack' ), _x( 'navigation', 'block search term', 'jetpack' ), From 1243e4360cbe834971b03b6e1047a83c3f1fca74 Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Thu, 13 Feb 2020 13:34:02 -0800 Subject: [PATCH 3/4] Add core PR reference. Props @jeherve. --- extensions/shared/block-keywords.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extensions/shared/block-keywords.js b/extensions/shared/block-keywords.js index 139998e3f905d..6c38d227cfd0f 100644 --- a/extensions/shared/block-keywords.js +++ b/extensions/shared/block-keywords.js @@ -1,3 +1,10 @@ +/** + * Please feel free to remove this file once the Core patch was merged and + * Jetpack only supports WordPress 5.4+. + * + * @see https://github.com/WordPress/gutenberg/pull/20224 + */ + /** * External dependencies */ @@ -42,5 +49,4 @@ function addBlockKeywords( settings, name ) { return settings; } - addFilter( 'blocks.registerBlockType', 'jetpack/block-keywords', addBlockKeywords ); From b0b0317964dd85441a1f30b497e9663bb2b211f6 Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Thu, 13 Feb 2020 16:19:49 -0800 Subject: [PATCH 4/4] Remove block keywords filter We'll use core's update --- extensions/editor.js | 1 - extensions/shared/block-keywords.js | 52 ----------------------------- 2 files changed, 53 deletions(-) delete mode 100644 extensions/shared/block-keywords.js diff --git a/extensions/editor.js b/extensions/editor.js index 50c98717e92ce..3d61997fa354f 100644 --- a/extensions/editor.js +++ b/extensions/editor.js @@ -3,7 +3,6 @@ */ import './shared/public-path'; import './shared/block-category'; -import './shared/block-keywords'; import './shared/plan-upgrade-notification'; import './shared/stripe-connection-notification'; import analytics from '../_inc/client/lib/analytics'; diff --git a/extensions/shared/block-keywords.js b/extensions/shared/block-keywords.js deleted file mode 100644 index 6c38d227cfd0f..0000000000000 --- a/extensions/shared/block-keywords.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Please feel free to remove this file once the Core patch was merged and - * Jetpack only supports WordPress 5.4+. - * - * @see https://github.com/WordPress/gutenberg/pull/20224 - */ - -/** - * External dependencies - */ -import { addFilter } from '@wordpress/hooks'; -import { _x } from '@wordpress/i18n'; -import { includes } from 'lodash'; - -/** - * Filters block registration to add keywords to core blocks. - * - * @param {Object} settings Block Settings. - * @param {string} name Block name. - * @return {Object} Filtered block settings. - */ -function addBlockKeywords( settings, name ) { - const social = _x( 'social', 'block search term', 'jetpack' ); - const survey = _x( 'survey', 'block search term', 'jetpack' ); - const video = _x( 'video', 'block search term', 'jetpack' ); - - switch ( name ) { - case 'core-embed/facebook': - case 'core-embed/instagram': - case 'core-embed/tumblr': - case 'core-embed/twitter': - if ( ! includes( settings.keywords, social ) ) { - settings.keywords.push( social ); - } - break; - - case 'core-embed/crowdsignal': - if ( ! includes( settings.keywords, survey ) ) { - settings.keywords.push( survey ); - } - break; - - case 'core-embed/hulu': - if ( ! includes( settings.keywords, video ) ) { - settings.keywords.push( video ); - } - break; - } - - return settings; -} -addFilter( 'blocks.registerBlockType', 'jetpack/block-keywords', addBlockKeywords );