Skip to content

Commit 7b86104

Browse files
committed
[Data Liberation] Build Markdown importer as phar
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.
1 parent 53a4da4 commit 7b86104

10 files changed

Lines changed: 62 additions & 89 deletions

File tree

Binary file not shown.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "playground-data-liberation-markdown",
3+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "packages/playground/data-liberation-markdown",
5+
"projectType": "library",
6+
"targets": {
7+
"install": {
8+
"executor": "nx:run-commands",
9+
"options": {
10+
"cwd": "packages/playground/data-liberation-markdown",
11+
"commands": ["composer install"],
12+
"parallel": false
13+
}
14+
},
15+
"build:phar": {
16+
"executor": "nx:run-commands",
17+
"options": {
18+
"cwd": "packages/playground/data-liberation-markdown",
19+
"commands": ["bash ./phar-build.sh"],
20+
"parallel": false
21+
},
22+
"dependsOn": ["playground-data-liberation:build:phar"]
23+
},
24+
"lint:php": {
25+
"executor": "nx:run-commands",
26+
"options": {
27+
"cwd": "packages/playground/data-liberation-markdown",
28+
"commands": [
29+
"../data-liberation/vendor/bin/phpcs --standard=./phpcs.xml -s ./src ./*.php"
30+
],
31+
"parallel": false
32+
}
33+
},
34+
"lint:php:fix": {
35+
"executor": "nx:run-commands",
36+
"options": {
37+
"cwd": "packages/playground/data-liberation-markdown",
38+
"commands": [
39+
"../data-liberation/vendor/bin/phpcbf --standard=./phpcs.xml ./src"
40+
],
41+
"parallel": false
42+
}
43+
}
44+
}
45+
}

‎packages/playground/data-liberation-markdown/scoper.inc.php‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎packages/playground/data-liberation-markdown/src/WP_Markdown_Importer.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ public static function create_for_markdown_directory( $markdown_directory, $opti
88
return WP_Markdown_Importer::create(
99
function ( $cursor = null ) use ( $markdown_directory ) {
1010
// @TODO: Handle $cursor
11-
return new WP_Directory_Tree_Entity_Reader(
11+
return new WP_Directory_Tree_Entity_Reader(
1212
new WP_Filesystem(),
13-
array (
13+
array(
1414
'root_dir' => $markdown_directory,
1515
'first_post_id' => 1,
1616
'allowed_extensions' => array( 'md' ),
1717
'index_file_patterns' => array( '#^index\.md$#' ),
18-
'markup_converter_factory' => function( $content ) {
18+
'markup_converter_factory' => function ( $content ) {
1919
return new WP_Markdown_To_Blocks( $content );
2020
},
2121
)
@@ -42,7 +42,7 @@ protected static function parse_options( $options ) {
4242
return false;
4343
}
4444
$options['local_markdown_assets_root'] = rtrim( $options['local_markdown_assets_root'], '/' );
45-
45+
4646
return parent::parse_options( $options );
4747
}
4848

‎packages/playground/data-liberation-markdown/src/WP_Markdown_To_Blocks.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ private function convert_markdown_to_blocks() {
8080
$parser = new MarkdownParser( $environment );
8181

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

8989
$walker = $document->walker();

‎packages/playground/data-liberation-markdown/src/bootstrap.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
require_once __DIR__ . '/WP_Markdown_Importer.php';
44
require_once __DIR__ . '/WP_Markdown_To_Blocks.php';
55

6-
require_once __DIR__ . '/../vendor/autoload.php';
6+
require_once __DIR__ . '/../vendor/autoload.php';

‎packages/playground/data-liberation/bootstrap.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
require_once __DIR__ . '/src/wordpress-core-html-api/html5-named-character-references.php';
4545
}
4646

47+
require_once __DIR__ . '/src/block-markup/WP_Block_Markup_Converter.php';
4748
require_once __DIR__ . '/src/block-markup/WP_Block_Markup_Processor.php';
4849
require_once __DIR__ . '/src/block-markup/WP_Block_Markup_Url_Processor.php';
4950
require_once __DIR__ . '/src/block-markup/WP_URL_In_Text_Processor.php';
@@ -63,7 +64,6 @@
6364
require_once __DIR__ . '/src/import/WP_Stream_Importer.php';
6465
require_once __DIR__ . '/src/import/WP_Entity_Iterator_Chain.php';
6566
require_once __DIR__ . '/src/import/WP_Retry_Frontloading_Iterator.php';
66-
require_once __DIR__ . '/src/import/WP_Markdown_Importer.php';
6767

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

Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
interface WP_Block_Markup_Converter {
4+
public function convert();
5+
public function get_block_markup();
6+
public function get_all_metadata();
7+
public function get_meta_value( $key );
8+
}

‎packages/playground/data-liberation/src/import/WP_Markdown_Importer.php‎

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)