Skip to content

Commit

Permalink
[Data Liberation] Build Markdown importer as phar
Browse files Browse the repository at this point in the history
Builds data-liberation-markdown.phar.gz (200KB) to enable downloading the
Markdown importer only when needed instead of on every page load.

A part of:

* #2080
* #1894

 ## Testing instructions

Run `nx build playground-data-liberation-markdown`, confirm it finished
without errors. A smoke test of the built phar file is included in the
build command.
  • Loading branch information
adamziel committed Dec 17, 2024
1 parent 53a4da4 commit 7b86104
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 89 deletions.
Binary file not shown.
45 changes: 45 additions & 0 deletions packages/playground/data-liberation-markdown/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "playground-data-liberation-markdown",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/playground/data-liberation-markdown",
"projectType": "library",
"targets": {
"install": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/playground/data-liberation-markdown",
"commands": ["composer install"],
"parallel": false
}
},
"build:phar": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/playground/data-liberation-markdown",
"commands": ["bash ./phar-build.sh"],
"parallel": false
},
"dependsOn": ["playground-data-liberation:build:phar"]
},
"lint:php": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/playground/data-liberation-markdown",
"commands": [
"../data-liberation/vendor/bin/phpcs --standard=./phpcs.xml -s ./src ./*.php"
],
"parallel": false
}
},
"lint:php:fix": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/playground/data-liberation-markdown",
"commands": [
"../data-liberation/vendor/bin/phpcbf --standard=./phpcs.xml ./src"
],
"parallel": false
}
}
}
}
5 changes: 0 additions & 5 deletions packages/playground/data-liberation-markdown/scoper.inc.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ public static function create_for_markdown_directory( $markdown_directory, $opti
return WP_Markdown_Importer::create(
function ( $cursor = null ) use ( $markdown_directory ) {
// @TODO: Handle $cursor
return new WP_Directory_Tree_Entity_Reader(
return new WP_Directory_Tree_Entity_Reader(
new WP_Filesystem(),
array (
array(
'root_dir' => $markdown_directory,
'first_post_id' => 1,
'allowed_extensions' => array( 'md' ),
'index_file_patterns' => array( '#^index\.md$#' ),
'markup_converter_factory' => function( $content ) {
'markup_converter_factory' => function ( $content ) {
return new WP_Markdown_To_Blocks( $content );
},
)
Expand All @@ -42,7 +42,7 @@ protected static function parse_options( $options ) {
return false;
}
$options['local_markdown_assets_root'] = rtrim( $options['local_markdown_assets_root'], '/' );

return parent::parse_options( $options );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ private function convert_markdown_to_blocks() {
$parser = new MarkdownParser( $environment );

$document = $parser->parse( $this->markdown );
$this->frontmatter = [];
foreach( $document->data as $key => $value ) {
$this->frontmatter = array();
foreach ( $document->data as $key => $value ) {
// Use an array as a value to comply with the WP_Block_Markup_Converter interface.
$this->frontmatter[ $key ] = [$value];
$this->frontmatter[ $key ] = array( $value );
}

$walker = $document->walker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
require_once __DIR__ . '/WP_Markdown_Importer.php';
require_once __DIR__ . '/WP_Markdown_To_Blocks.php';

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';
2 changes: 1 addition & 1 deletion packages/playground/data-liberation/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
require_once __DIR__ . '/src/wordpress-core-html-api/html5-named-character-references.php';
}

require_once __DIR__ . '/src/block-markup/WP_Block_Markup_Converter.php';
require_once __DIR__ . '/src/block-markup/WP_Block_Markup_Processor.php';
require_once __DIR__ . '/src/block-markup/WP_Block_Markup_Url_Processor.php';
require_once __DIR__ . '/src/block-markup/WP_URL_In_Text_Processor.php';
Expand All @@ -63,7 +64,6 @@
require_once __DIR__ . '/src/import/WP_Stream_Importer.php';
require_once __DIR__ . '/src/import/WP_Entity_Iterator_Chain.php';
require_once __DIR__ . '/src/import/WP_Retry_Frontloading_Iterator.php';
require_once __DIR__ . '/src/import/WP_Markdown_Importer.php';

require_once __DIR__ . '/src/utf8_decoder.php';

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

interface WP_Block_Markup_Converter {
public function convert();
public function get_block_markup();
public function get_all_metadata();
public function get_meta_value( $key );
}

This file was deleted.

0 comments on commit 7b86104

Please sign in to comment.