diff --git a/blocks/library/latest-posts/index.php b/blocks/library/latest-posts/index.php index bb06d4b4fe5a5e..31ef5836bf4696 100644 --- a/blocks/library/latest-posts/index.php +++ b/blocks/library/latest-posts/index.php @@ -103,7 +103,8 @@ function register_block_core_latest_posts() { 'default' => 'date', ), ), - 'render_callback' => 'render_block_core_latest_posts', + // TODO: render client side instead? + //'render_callback' => 'render_block_core_latest_posts', ) ); } diff --git a/gutenberg.php b/gutenberg.php index a6b3eefa4467b2..e61fda8a217ef3 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -134,6 +134,7 @@ function gutenberg_pre_init() { } add_filter( 'replace_editor', 'gutenberg_init', 10, 2 ); + add_action( 'wp_enqueue_scripts', 'gutenberg_view_post_scripts_and_styles' ); } /** diff --git a/lib/blocks.php b/lib/blocks.php index e28971bad032c2..2de0d08ee17eda 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -199,9 +199,20 @@ function do_blocks( $content ) { // Append remaining unmatched content. $rendered_content .= $content; - // Strip remaining block comment demarcations. - $rendered_content = preg_replace( '/\r?\n?/m', '', $rendered_content ); - return $rendered_content; } add_filter( 'the_content', 'do_blocks', 9 ); // BEFORE do_shortcode(). + +/** + * Strips remaining block comment demarcations. + * + * @since 2.5.0 + * + * @param string $content Post content. + * @return string Updated post content. + */ +function do_blocks_strip_comment_demarcations( $content ) { + return preg_replace( '/\r?\n?/m', '', $content ); +} +// TODO: It should be possible to leave comments for the processing on the frontend +//add_filter( 'the_content', 'do_blocks_strip_comment_demarcations', 9 ); // AFTER do_blocks diff --git a/lib/client-assets.php b/lib/client-assets.php index f3f688a3fae2f2..df2088bc073dab 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -963,3 +963,46 @@ function gutenberg_editor_scripts_and_styles( $hook ) { */ do_action( 'enqueue_block_editor_assets' ); } + +function gutenberg_view_post_scripts_and_styles() { + gutenberg_extend_wp_api_backbone_client(); + + // Prepare Jed locale data. + $locale_data = gutenberg_get_jed_locale_data( 'gutenberg' ); + wp_add_inline_script( + 'wp-view-post', + 'wp.i18n.setLocaleData( ' . json_encode( $locale_data ) . ' );', + 'before' + ); + + // Preload server-registered block schemas. + wp_localize_script( 'wp-blocks', '_wpBlocks', gutenberg_prepare_blocks_for_js() ); + + wp_register_script( + 'wp-view-post', + gutenberg_url( 'view-post/build/index.js' ), + array( 'wp-element', 'wp-components', 'wp-i18n', 'wp-date', 'wp-utils', 'wp-data', 'wp-api', 'wp-embed', 'wp-blocks' ), + filemtime( gutenberg_dir_path() . 'view-post/build/index.js' ), + true + ); + wp_enqueue_script( 'wp-view-post' ); + + $script = '( function() {'; + $script .= << { + return { + categories: '/wp/v2/categories', + }; + } ),*/ + ifCondition( ( categories ) => categories && categories.length ) +)( ( { categories } ) => ( +
+

Categories from API

+ { categories.map( + ( category ) =>

{ category.name }

+ ) } +
+) ); + +const ViewPost = ( ) => ( +
+ + + + +
+); + +/** + * Renders post's view. + * + * The return value of this function is not necessary if we change where we + * call initializeEditor(). This is due to metaBox timing. + */ +export function init() { + const target = document.querySelector( '.entry-content' ); + + render( + , + target + ); +} diff --git a/webpack.config.js b/webpack.config.js index 276ceb4c4db27d..bafa682ae758c4 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -57,6 +57,7 @@ const entryPointNames = [ 'data', 'viewport', [ 'editPost', 'edit-post' ], + [ 'viewPost', 'view-post' ], ]; const packageNames = [