Merge pull request #106 from cmanon/feature/105-embed-url-handlers

Add transforms for embed
This commit is contained in:
Justin Foell
2021-09-24 10:34:20 -05:00
committed by GitHub
6 changed files with 63 additions and 6 deletions
+2 -1
View File
@@ -48,6 +48,7 @@ class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface {
),
)
);
add_action( 'wp_footer', array( $this, 'print_scripts' ) );
}
@@ -68,7 +69,7 @@ class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface {
$this->add_script = true;
$matches = array();
preg_match( '/\/activities\/([0-9].*)$/', $attributes['url'], $matches );
preg_match( '#/activities/([0-9].*)$#', $attributes['url'], $matches );
if ( $matches[1] ) {
// Transform from block attributes to shortcode standard.
$attributes = array(
+2 -1
View File
@@ -48,6 +48,7 @@ class WPStrava_Blocks_Route implements WPStrava_Blocks_Interface {
),
)
);
add_action( 'wp_footer', array( $this, 'print_scripts' ) );
}
@@ -68,7 +69,7 @@ class WPStrava_Blocks_Route implements WPStrava_Blocks_Interface {
$this->add_script = true;
$matches = array();
preg_match( '/\/routes\/([0-9].*)$/', $attributes['url'], $matches );
preg_match( '#/routes/([0-9].*)$#', $attributes['url'], $matches );
if ( $matches[1] ) {
// Transform from block attributes to shortcode standard.
$attributes = array(
+2 -1
View File
@@ -48,6 +48,7 @@ class WPStrava_Blocks_Segment implements WPStrava_Blocks_Interface {
),
)
);
add_action( 'wp_footer', array( $this, 'print_scripts' ) );
}
@@ -68,7 +69,7 @@ class WPStrava_Blocks_Segment implements WPStrava_Blocks_Interface {
$this->add_script = true;
$matches = array();
preg_match( '/\/segments\/([0-9].*)$/', $attributes['url'], $matches );
preg_match( '#/segments/([0-9].*)$#', $attributes['url'], $matches );
if ( $matches[1] ) {
// Transform from block attributes to shortcode standard.
$atts = array(
+19 -1
View File
@@ -1,9 +1,27 @@
/* global wp, wpStrava */
import { registerBlockType } from '@wordpress/blocks';
import { registerBlockType, createBlock } from '@wordpress/blocks';
import edit from './edit';
import metadata from './block.json';
metadata.edit = edit;
metadata.save = () => null;
metadata.transforms = {
from: [
{
type: "raw",
priority: 10,
isMatch: ( node ) =>
node.nodeName === "P" &&
node.innerText.startsWith( "https://www.strava.com/activities/" ),
transform: function( node ) {
return createBlock( metadata.name, {
url: node.innerText,
} );
}
}
]
};
registerBlockType( metadata.name, metadata );
+19 -1
View File
@@ -1,9 +1,27 @@
/* global wp, wpStrava */
import { registerBlockType } from '@wordpress/blocks';
import { registerBlockType, createBlock } from '@wordpress/blocks';
import edit from './edit';
import metadata from './block.json';
metadata.edit = edit;
metadata.save = () => null;
metadata.transforms = {
from: [
{
type: "raw",
priority: 10,
isMatch: ( node ) =>
node.nodeName === "P" &&
node.innerText.startsWith( "https://www.strava.com/routes/" ),
transform: function( node ) {
return createBlock( metadata.name, {
url: node.innerText,
} );
}
}
]
};
registerBlockType( metadata.name, metadata );
+19 -1
View File
@@ -1,9 +1,27 @@
/* global wp, wpStrava */
import { registerBlockType } from '@wordpress/blocks';
import { registerBlockType, createBlock } from '@wordpress/blocks';
import edit from './edit';
import metadata from './block.json';
metadata.edit = edit;
metadata.save = () => null;
metadata.transforms = {
from: [
{
type: "raw",
priority: 10,
isMatch: ( node ) =>
node.nodeName === "P" &&
node.innerText.startsWith( "https://www.strava.com/segments/" ),
transform: function( node ) {
return createBlock( metadata.name, {
url: node.innerText,
} );
}
}
]
};
registerBlockType( metadata.name, metadata );