mirror of
https://github.com/10h30/wp-strava.git
synced 2026-07-17 13:43:50 +09:00
Add transforms for routes
This commit is contained in:
@@ -48,6 +48,7 @@ class WPStrava_Blocks_Route implements WPStrava_Blocks_Interface {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
add_action( 'wp_footer', array( $this, 'print_scripts' ) );
|
add_action( 'wp_footer', array( $this, 'print_scripts' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ class WPStrava_Blocks_Route implements WPStrava_Blocks_Interface {
|
|||||||
$this->add_script = true;
|
$this->add_script = true;
|
||||||
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
preg_match( '/\/routes\/([0-9].*)$/', $attributes['url'], $matches );
|
preg_match( '#/routes/([0-9].*)$#', $attributes['url'], $matches );
|
||||||
if ( $matches[1] ) {
|
if ( $matches[1] ) {
|
||||||
// Transform from block attributes to shortcode standard.
|
// Transform from block attributes to shortcode standard.
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
|
|||||||
@@ -1,9 +1,27 @@
|
|||||||
/* global wp, wpStrava */
|
/* global wp, wpStrava */
|
||||||
import { registerBlockType } from '@wordpress/blocks';
|
import { registerBlockType, createBlock } from '@wordpress/blocks';
|
||||||
import edit from './edit';
|
import edit from './edit';
|
||||||
import metadata from './block.json';
|
import metadata from './block.json';
|
||||||
|
|
||||||
metadata.edit = edit;
|
metadata.edit = edit;
|
||||||
metadata.save = () => null;
|
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 );
|
registerBlockType( metadata.name, metadata );
|
||||||
|
|||||||
Reference in New Issue
Block a user