diff --git a/blocks/project-detail/block.json b/blocks/project-detail/block.json new file mode 100644 index 0000000..b300aec --- /dev/null +++ b/blocks/project-detail/block.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "chrnx/project-detail", + "version": "0.4.4", + "title": "Project Detail", + "category": "theme", + "description": "Cover, status, description and links for the queried project.", + "textdomain": "chrnx", + "attributes": {}, + "supports": { "html": false }, + "render": "file:./render.php" +} diff --git a/blocks/project-detail/render.php b/blocks/project-detail/render.php new file mode 100644 index 0000000..ebfc64b --- /dev/null +++ b/blocks/project-detail/render.php @@ -0,0 +1,39 @@ +taxonomy ) { + return; +} + +$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_project_status', true ); +$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_project_cover', true ) ); +$chrnx_links = chrnx_get_project_links( $chrnx_term->term_id ); +// Without status, description or links there is no second column to fill. +$chrnx_has_intro = '' !== $chrnx_status || '' !== $chrnx_term->description || ! empty( $chrnx_links ); +$chrnx_head_class = 'chrnx-project-detail__head' . ( $chrnx_has_intro ? '' : ' is-bare' ); +?> +
'chrnx-project-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> +
+
+ 0 ) : ?> + 'chrnx-project-detail__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> + + + +
+
+ +

+ + description ) : ?> +

description ); ?>

+ + +
+
+
diff --git a/inc/blocks.php b/inc/blocks.php index cf70bbe..d0935b5 100644 --- a/inc/blocks.php +++ b/inc/blocks.php @@ -29,7 +29,7 @@ function chrnx_get_current_navigation_destination() { return ''; } - if ( is_home() || is_search() || is_singular( 'post' ) || is_tax( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ) ) ) { + if ( is_home() || is_search() || is_singular( 'post' ) || is_tax( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show', 'chrnx_project' ) ) ) { return $journal_url; } @@ -232,7 +232,7 @@ function chrnx_get_editorial_card_markup( $post_id, $heading_level = 3, $class_n /** Register all block metadata directories that exist. */ function chrnx_register_editorial_blocks() { - $blocks = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools', 'reading-time', 'journal-link', 'selected-work', 'release-list', 'release-detail', 'track-meta', 'subscribe-form', 'show-links', 'project-list' ); + $blocks = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools', 'reading-time', 'journal-link', 'selected-work', 'release-list', 'release-detail', 'track-meta', 'subscribe-form', 'show-links', 'project-list', 'project-detail' ); foreach ( $blocks as $block ) { $name = 'chrnx/' . $block; if ( WP_Block_Type_Registry::get_instance()->is_registered( $name ) ) { diff --git a/inc/queries.php b/inc/queries.php index c7ddad7..ad4f110 100644 --- a/inc/queries.php +++ b/inc/queries.php @@ -374,7 +374,7 @@ function chrnx_sanitize_journal_search( $value ) { */ function chrnx_get_journal_archive_filter( $queried_object = null ): array { $queried_object = null === $queried_object ? get_queried_object() : $queried_object; - if ( ! $queried_object instanceof WP_Term || ! in_array( $queried_object->taxonomy, array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ), true ) ) { + if ( ! $queried_object instanceof WP_Term || ! in_array( $queried_object->taxonomy, array( 'chrnx_topic', 'chrnx_language', 'chrnx_show', 'chrnx_project' ), true ) ) { return array(); } @@ -401,7 +401,7 @@ function chrnx_get_journal_request_context( array $request, $queried_object = nu $context = array( 'paged' => chrnx_parse_journal_page( $request['paged'] ?? null ), ); - foreach ( array( 'chrnx_topic', 'chrnx_language' ) as $taxonomy ) { + foreach ( array( 'chrnx_topic', 'chrnx_language', 'chrnx_project' ) as $taxonomy ) { $slug = chrnx_validate_editorial_term_slug( $request[ $taxonomy ] ?? '', $taxonomy ); if ( '' !== $slug ) { $context[ $taxonomy ] = $slug; @@ -431,7 +431,7 @@ function chrnx_get_journal_base_url() { $url = get_permalink( $queried ); return is_string( $url ) ? $url : ''; } - if ( $queried instanceof WP_Term && in_array( $queried->taxonomy, array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ), true ) ) { + if ( $queried instanceof WP_Term && in_array( $queried->taxonomy, array( 'chrnx_topic', 'chrnx_language', 'chrnx_show', 'chrnx_project' ), true ) ) { $url = get_term_link( $queried ); return is_wp_error( $url ) ? '' : $url; } @@ -486,7 +486,7 @@ function chrnx_get_full_journal_url() { function chrnx_get_journal_page_url( int $page, array $filters ) { $base_url = chrnx_get_journal_base_url(); $args = array(); - foreach ( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ) as $taxonomy ) { + foreach ( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show', 'chrnx_project' ) as $taxonomy ) { $slug = chrnx_validate_editorial_term_slug( $filters[ $taxonomy ] ?? '', $taxonomy ); if ( '' !== $slug ) { $args[ $taxonomy ] = $slug; @@ -526,7 +526,7 @@ function chrnx_get_journal_query_args( array $request ): array { ); $tax_query = array(); - foreach ( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ) as $taxonomy ) { + foreach ( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show', 'chrnx_project' ) as $taxonomy ) { $value = $request[ $taxonomy ] ?? ''; $slug = chrnx_validate_editorial_term_slug( $value, $taxonomy ); if ( '' !== $slug ) { diff --git a/tests/php/ProjectBlocksTest.php b/tests/php/ProjectBlocksTest.php index b5df134..4df8510 100644 --- a/tests/php/ProjectBlocksTest.php +++ b/tests/php/ProjectBlocksTest.php @@ -73,4 +73,59 @@ class ProjectBlocksTest extends WP_UnitTestCase { $this->assertStringContainsString( 'chrnx-project-card__fallback', $markup ); } + + /** + * Ensure the detail block renders the queried project header. + */ + public function test_project_detail_renders_the_queried_term() { + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'name' => 'Ailed', + 'slug' => 'ailed-test', + 'description' => 'A chess engine that feels.', + ) + ); + update_term_meta( $term_id, 'chrnx_project_repo', 'https://github.com/example/ailed' ); + update_term_meta( $term_id, 'chrnx_project_status', 'Activo' ); + + $this->go_to( get_term_link( $term_id ) ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'A chess engine that feels.', $markup ); + $this->assertStringContainsString( 'https://github.com/example/ailed', $markup ); + $this->assertStringContainsString( 'Activo', $markup ); + } + + /** + * Ensure the detail block renders nothing outside a project archive. + */ + public function test_project_detail_is_silent_off_its_archive() { + $this->go_to( home_url( '/' ) ); + + $this->assertSame( '', trim( do_blocks( '' ) ) ); + } + + /** + * Ensure a project archive filters the journal to that project. + */ + public function test_project_archive_filters_the_journal() { + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'slug' => 'filter-test', + ) + ); + $mine = self::factory()->post->create( array( 'post_title' => 'Belongs to the project' ) ); + self::factory()->post->create( array( 'post_title' => 'Unrelated post' ) ); + wp_set_object_terms( $mine, array( $term_id ), 'chrnx_project' ); + + $this->go_to( get_term_link( $term_id ) ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'Belongs to the project', $markup ); + $this->assertStringNotContainsString( 'Unrelated post', $markup ); + } }