Skip to content

Commit

Permalink
Merge pull request #116 from cmanon/feature/115-block-transforms
Browse files Browse the repository at this point in the history
Added some transformations
  • Loading branch information
jrfoell authored Nov 26, 2021
2 parents 7630626 + 5cc106a commit 6f5cd24
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: cmanon, jrfoell, lancewillett, dlintott, sebastianerb
Tags: strava, activity, bicycle, cycling, biking, running, run, swimming, swim, paddle, kayak, gps, shortcode, widget, plugin, block, blocks
Requires at least: 4.6
Tested up to: 5.8
Stable tag: 2.10.1
Stable tag: 2.11.0
Requires PHP: 5.3
License: GPLv2 or later

Expand Down Expand Up @@ -134,6 +134,10 @@ On the WP-Strava settings page you cannot currently remove and add another athle

== Changelog ==

= 2.11.0 =
Added additional block transformations for "Activity" (from: Paragraph, Classic Shortcode; to: Paragraph)


= 2.10.1 =
Reworked settings save with multiple athletes, related to https://wordpress.org/support/topic/wp-strava-error-401-unauthorized/

Expand Down
46 changes: 39 additions & 7 deletions src/blocks/activity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,51 @@ metadata.save = () => null;
metadata.transforms = {
from: [
{
type: "raw",
priority: 10,
isMatch: ( node ) =>
node.nodeName === "P" &&
node.innerText.startsWith( "https://www.strava.com/activities/" ),

type: 'raw',
isMatch: ( node ) => {
return (
node.nodeName === 'P' &&
node.innerText.startsWith( 'https://www.strava.com/activities/' )
);
},
transform: function( node ) {
return createBlock( metadata.name, {
url: node.innerText,
} );
}
},
{
type: 'block',
blocks: [ 'core/paragraph' ],
isMatch: ( node ) => {
return node.content.startsWith( 'https://www.strava.com/activities/' );
},
transform: function( node ) {
return createBlock( metadata.name, { url: node.content } );
}
},
{
type: 'shortcode',
tag: [ 'activity', 'ride' ],
attributes: {
url: {
type: 'string',
shortcode: ( { named: atts } ) => {
return 'https://www.strava.com/activities/' + atts.id;
},
},
},
}
]
],
to: [
{
type: 'block',
blocks: [ 'core/paragraph' ],
transform: ( attributes ) => {
return createBlock( 'core/paragraph', { content: attributes.url } );
}
},
],
};

registerBlockType( metadata.name, metadata );
4 changes: 2 additions & 2 deletions wp-strava.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Strava
* Plugin URI: https://wordpress.org/plugins/wp-strava/
* Description: Show your strava.com activity on your WordPress site. Some Icons are Copyright © Yusuke Kamiyamane. All rights reserved. Licensed under a Creative Commons Attribution 3.0 license.
* Version: 2.10.1
* Version: 2.11.0
* Author: Carlos Santa Cruz, Justin Foell, Lance Willett, Daniel Lintott, Sebastian Erb
* License: GPL2
* Text Domain: wp-strava
Expand All @@ -27,7 +27,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

define( 'WPSTRAVA_PLUGIN_VERSION', '2.10.1' );
define( 'WPSTRAVA_PLUGIN_VERSION', '2.11.0' );
define( 'WPSTRAVA_PLUGIN_FILE', __FILE__ );
define( 'WPSTRAVA_PLUGIN_DIR', trailingslashit( dirname( __FILE__ ) ) );
define( 'WPSTRAVA_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
Expand Down

0 comments on commit 6f5cd24

Please sign in to comment.