From f4211ca880193f82d67116143364c85e1a6fd6fc Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 26 Nov 2021 13:06:21 -0600 Subject: [PATCH] Added some transformations --- src/blocks/activity/index.js | 46 ++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/blocks/activity/index.js b/src/blocks/activity/index.js index 333c154..cf2cb16 100644 --- a/src/blocks/activity/index.js +++ b/src/blocks/activity/index.js @@ -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 );