Skip to content

Commit

Permalink
Load pages in the correct menu_order, add missing assets
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed May 1, 2024
1 parent ad58b79 commit e151518
Show file tree
Hide file tree
Showing 62 changed files with 7,754 additions and 20 deletions.
14 changes: 12 additions & 2 deletions start-server.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#!/bin/bash

bun --config=/Users/cloudnik/.bunfig.toml /Users/cloudnik/www/Automattic/core/plugins/playground/packages/playground/cli/src/cli.ts start --mount=./wp-content/plugins/wp-docs-plugin:/wordpress/wp-content/plugins/wp-docs-plugin --mount=./wp-content/html-pages:/wordpress/wp-content/html-pages --mount=./wp-content/uploads:/wordpress/wp-content/uploads --mount=./wp-content/themes/playground-docs:/wordpress/wp-content/themes/playground-docs --blueprint=./wp-content/blueprint-wp-now.json --wp=6.5

mkdir -p output
bunx @wp-playground/cli@latest \
server \
--mount=./wp-content/plugins/wp-docs-plugin:/wordpress/wp-content/plugins/wp-docs-plugin \
--mount=./wp-content/plugins/export-static-site:/wordpress/wp-content/plugins/export-static-site \
--mount=./wp-content/html-pages:/wordpress/wp-content/html-pages \
--mount=./wp-content/uploads:/wordpress/wp-content/uploads \
--mount=./wp-content/themes/playground-docs:/wordpress/wp-content/themes/playground-docs \
--mount=./output:/output \
--blueprint=./wp-content/blueprint-serve.json \
--wp=6.5 \
--php=8.0
6 changes: 0 additions & 6 deletions start-site.sh

This file was deleted.

38 changes: 38 additions & 0 deletions wp-content/blueprint-serve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"landingPage": "/wp-admin/edit.php?post_type=page",
"preferredVersions": {
"wp": "latest",
"php": "8.0"
},
"login": true,
"steps": [
{
"step": "installTheme",
"themeZipFile": {
"resource": "wordpress.org/themes",
"slug": "twentytwentyfour"
}
},
{
"step": "mkdir",
"path": "/wordpress/wp-content/mu-plugins"
},
{
"step": "writeFile",
"path": "/wordpress/wp-content/mu-plugins/0-hide-admin-bar.php",
"data": "<?php add_filter( 'show_admin_bar', '__return_false' ); "
},
{
"step": "installPlugin",
"pluginZipFile": {
"resource": "wordpress.org/plugins",
"slug": "create-block-theme"
}
},
{
"step": "activatePlugin",
"pluginPath": "wp-docs-plugin/plugin.php"
}
]
}
39 changes: 27 additions & 12 deletions wp-content/plugins/wp-docs-plugin/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,15 @@ function download_docs_callback() {
function create_db_pages_from_html_files($dir, $parent_id = 0) {
$indexFilePath = $dir . '/index.html';
if(file_exists($indexFilePath)) {
$parent_id = create_db_page_from_html_file(new SplFileInfo($indexFilePath), $parent_id);
$parent_id = create_db_page_from_html_file(
new SplFileInfo($indexFilePath),
$parent_id,
get_order_from_filename(basename($dir))
);
}

foreach (scandir($dir) as $file) {
$files = scandir($dir);
foreach ($files as $file) {
if ($file === '.' || $file === '..' || $file === 'index.html') {
continue;
}
Expand All @@ -195,16 +200,25 @@ function create_db_pages_from_html_files($dir, $parent_id = 0) {
if (is_dir($filePath)) {
create_db_pages_from_html_files($filePath, $parent_id);
} else if (pathinfo($file, PATHINFO_EXTENSION) === 'html') {
create_db_page_from_html_file(new SplFileInfo($filePath), $parent_id);
create_db_page_from_html_file(
new SplFileInfo($filePath),
$parent_id,
get_order_from_filename(basename($filePath))
);
}
}
}

function create_db_page_from_html_file(SplFileInfo $file, $parent_id = 0) {
function get_order_from_filename($filename) {
if(preg_match('/^(\d+)_/', $filename, $matches)) {
return $matches[1];
}
return 0;
}

function create_db_page_from_html_file(SplFileInfo $file, $parent_id = 0, $order = 0) {
$content = file_get_contents($file->getRealPath());
// Add a comment to prevent this failure:
// 'PHP Fatal error: Uncaught ValueError: strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
$p = new Playground_Post_Export_Processor($content . '<!-- -->');
$p = new Playground_Post_Export_Processor($content);
$p->next_tag();
if($p->get_tag() === 'H1') {
$p->set_bookmark('start');
Expand All @@ -214,7 +228,11 @@ function create_db_page_from_html_file(SplFileInfo $file, $parent_id = 0) {
// Removing the tag doesn't affect the whitespace that follows, so
// we need to trim the content or else we'll start accumulating leading
// newlines.
$content = trim($p->get_updated_html());
try {
$content = trim($p->get_updated_html());
} catch(ValueError $e) {
$content = '';
}
// Replace placeholder site URLs with the URL of the current site.
// @TODO: This is very naive, let's actually parse the block
// markup and the HTML markup and make these replacements
Expand All @@ -237,11 +255,8 @@ function create_db_page_from_html_file(SplFileInfo $file, $parent_id = 0) {
'post_author' => get_current_user_id(),
'post_type' => 'page',
'post_parent' => $parent_id,
'menu_order' => $order
);

if(preg_match('/^(\d+)_/', $file->getFilename(), $matches)) {
$post_data['menu_order'] = $matches[1];
}

$page_id = wp_insert_post($post_data);
if("0" == get_option('page_on_front')) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e151518

Please sign in to comment.