diff --git a/includes/class-spacefast-plugin.php b/includes/class-spacefast-plugin.php index 1dfffd3..c1d35a8 100644 --- a/includes/class-spacefast-plugin.php +++ b/includes/class-spacefast-plugin.php @@ -844,6 +844,7 @@ public static function register_simply_static(): void { require_once dirname( __DIR__ ) . '/includes/class-spacefast-simply-static-task.php'; add_filter( 'simplystatic.archive_creation_job.task_list', array( __CLASS__, 'simply_static_tasks' ), 20, 2 ); add_filter( 'simply_static_class_name', array( __CLASS__, 'simply_static_task_class' ), 20, 2 ); + add_filter( 'ss_additional_urls', array( __CLASS__, 'simply_static_archive_urls' ), 20 ); add_action( 'ss_archive_creation_job_after_start_queue', array( __CLASS__, 'static_export_started' ), 20 ); } @@ -891,6 +892,41 @@ public static function simply_static_task_class( string $class_name, string $tas : $class_name; } + /** + * Simply Static discovers custom post entries but not every custom post type + * archive. Include those archive routes so navigation links cannot publish as + * broken pages. + * + * @param array $urls Additional source URLs. + * @return array + */ + public static function simply_static_archive_urls( array $urls ): array { + if ( Spacefast_Settings::MODE_STATIC !== Spacefast_Settings::mode() ) { + return $urls; + } + $options = get_option( 'simply-static', array() ); + $options = is_array( $options ) ? $options : array(); + $selected = isset( $options['post_types'] ) && is_array( $options['post_types'] ) + ? $options['post_types'] + : array(); + $configured = ! empty( $options['post_types_configured'] ) || array() !== $selected; + $post_types = get_post_types( array( 'public' => true ), 'objects' ); + foreach ( $post_types as $name => $post_type ) { + if ( + 'attachment' === $name + || empty( $post_type->has_archive ) + || ( $configured && ! in_array( $name, $selected, true ) ) + ) { + continue; + } + $archive_url = get_post_type_archive_link( $name ); + if ( is_string( $archive_url ) && '' !== $archive_url ) { + $urls[] = $archive_url; + } + } + return array_values( array_unique( $urls ) ); + } + public static function static_export_started( int $blog_id = 0 ): void { unset( $blog_id ); if ( diff --git a/readme.txt b/readme.txt index 587cd45..021bb43 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: spacefast Tags: static site, headless cms, simply static, deployment Requires at least: 6.5 Requires PHP: 8.1 -Stable tag: 0.5.6 +Stable tag: 0.5.7 License: GPLv2 or later Publish a Simply Static export to Spacefast, or rebuild a headless site when WordPress content changes. @@ -31,6 +31,9 @@ OAuth access is limited to the Team you authorize and the mode you choose. WordP == Changelog == += 0.5.7 = +* Include public custom post type archive routes in Simply Static exports. + = 0.5.6 = * Make static WordPress exports publicly readable by default while preserving an explicit sf.jsonc access policy. diff --git a/spacefast-wordpress.php b/spacefast-wordpress.php index 7178ac2..0b65d4d 100644 --- a/spacefast-wordpress.php +++ b/spacefast-wordpress.php @@ -3,7 +3,7 @@ * Plugin Name: Spacefast * Plugin URI: https://spacefast.com/ * Description: Publishes static WordPress exports or rebuilds a headless Spacefast site. - * Version: 0.5.6 + * Version: 0.5.7 * Update URI: https://github.com/spacefast/wordpress * Requires at least: 6.5 * Requires PHP: 8.1 @@ -14,7 +14,7 @@ defined( 'ABSPATH' ) || exit; -define( 'SPACEFAST_WORDPRESS_VERSION', '0.5.6' ); +define( 'SPACEFAST_WORDPRESS_VERSION', '0.5.7' ); define( 'SPACEFAST_WORDPRESS_FILE', __FILE__ ); require_once __DIR__ . '/includes/class-spacefast-settings.php'; diff --git a/tests/acceptance/wordpress.php b/tests/acceptance/wordpress.php index 90700e7..dc620bd 100644 --- a/tests/acceptance/wordpress.php +++ b/tests/acceptance/wordpress.php @@ -113,7 +113,7 @@ function spacefast_accept( bool $condition, string $message ): void { ); $plugin = get_plugin_data( WP_PLUGIN_DIR . '/spacefast-wordpress/spacefast-wordpress.php', false, false ); -spacefast_accept( '0.5.6' === $plugin['Version'], 'Unexpected plugin version.' ); +spacefast_accept( '0.5.7' === $plugin['Version'], 'Unexpected plugin version.' ); spacefast_accept( 'https://github.com/spacefast/wordpress' === $plugin['UpdateURI'], 'Update URI is missing.' ); Spacefast_Settings::disconnect(); diff --git a/tests/behavior.php b/tests/behavior.php index aea1326..8cd742c 100644 --- a/tests/behavior.php +++ b/tests/behavior.php @@ -116,6 +116,16 @@ function wp_json_encode( $value ): string { function get_post_type_object( string $post_type ) { return $GLOBALS['spacefast_post_types'][ $post_type ] ?? null; } +function get_post_types( array $args = array(), string $output = 'names' ): array { + $post_types = array_filter( + $GLOBALS['spacefast_post_types'], + static fn( object $post_type ): bool => ! isset( $args['public'] ) || $post_type->public === $args['public'] + ); + return 'objects' === $output ? $post_types : array_keys( $post_types ); +} +function get_post_type_archive_link( string $post_type ) { + return $GLOBALS['spacefast_post_types'][ $post_type ]->archive_link ?? false; +} function wp_generate_uuid4(): string { return '00000000-0000-4000-8000-000000000001'; } @@ -839,6 +849,33 @@ static function ( string $url ) use ( &$invalid_receipt_requests ): array { ), 'publishes after export delivery and before cleanup' ); +$GLOBALS['spacefast_post_types']['case_study'] = (object) array( + 'public' => true, + 'has_archive' => 'case-studies', + 'archive_link' => 'https://wp.example.test/case-studies/', +); +$GLOBALS['spacefast_post_types']['private_story'] = (object) array( + 'public' => false, + 'has_archive' => 'private-stories', + 'archive_link' => 'https://wp.example.test/private-stories/', +); +check( + array( 'https://wp.example.test/manual/', 'https://wp.example.test/case-studies/' ) + === Spacefast_Plugin::simply_static_archive_urls( + array( 'https://wp.example.test/manual/', 'https://wp.example.test/case-studies/' ) + ), + 'includes public custom post archives once in static exports' +); +$GLOBALS['spacefast_options']['simply-static'] = array( + 'post_types' => array( 'post' ), + 'post_types_configured' => true, +); +check( + array( 'https://wp.example.test/manual/' ) + === Spacefast_Plugin::simply_static_archive_urls( array( 'https://wp.example.test/manual/' ) ), + 'respects the Simply Static post type selection for archives' +); +unset( $GLOBALS['spacefast_options']['simply-static'] ); $archive = sys_get_temp_dir() . '/spacefast-wordpress-static-' . uniqid(); mkdir( $archive );