feat: list every project with its status and links
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
4 files changed
+119
-1
No files matched your search
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||||
|
"apiVersion": 3,
|
||||||
|
"name": "chrnx/project-list",
|
||||||
|
"version": "0.4.4",
|
||||||
|
"title": "Project List",
|
||||||
|
"category": "theme",
|
||||||
|
"description": "Every project, each linking to its own page.",
|
||||||
|
"textdomain": "chrnx",
|
||||||
|
"attributes": {
|
||||||
|
"headingLevel": { "type": "integer", "default": 4, "enum": [2, 3, 4, 5, 6] }
|
||||||
|
},
|
||||||
|
"supports": { "html": false },
|
||||||
|
"render": "file:./render.php"
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Project List block render.
|
||||||
|
*
|
||||||
|
* @package CHRNX
|
||||||
|
*/
|
||||||
|
|
||||||
|
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 4, 4 );
|
||||||
|
$chrnx_terms = get_terms(
|
||||||
|
array(
|
||||||
|
'taxonomy' => 'chrnx_project',
|
||||||
|
'hide_empty' => false,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if ( is_wp_error( $chrnx_terms ) || empty( $chrnx_terms ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-project-list' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||||
|
<?php
|
||||||
|
foreach ( $chrnx_terms as $chrnx_term ) :
|
||||||
|
$chrnx_link = get_term_link( $chrnx_term );
|
||||||
|
$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 );
|
||||||
|
?>
|
||||||
|
<article class="chrnx-project-card">
|
||||||
|
<?php if ( ! is_wp_error( $chrnx_link ) ) : ?>
|
||||||
|
<a class="chrnx-project-card__link" href="<?php echo esc_url( $chrnx_link ); ?>">
|
||||||
|
<?php endif; ?>
|
||||||
|
<span class="chrnx-project-card__art">
|
||||||
|
<?php if ( $chrnx_cover > 0 ) : ?>
|
||||||
|
<?php echo wp_get_attachment_image( $chrnx_cover, 'chrnx-card', false, array( 'class' => 'chrnx-project-card__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||||
|
<?php else : ?>
|
||||||
|
<?php echo chrnx_get_topic_portrait_markup( 'placeholder-project', '', 'chrnx-project-card__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</span>
|
||||||
|
<h<?php echo esc_attr( $chrnx_heading ); ?> class="chrnx-project-card__title"><?php echo esc_html( $chrnx_term->name ); ?></h<?php echo esc_attr( $chrnx_heading ); ?>>
|
||||||
|
<?php if ( '' !== $chrnx_status ) : ?>
|
||||||
|
<p class="chrnx-project-card__status"><?php echo esc_html( $chrnx_status ); ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ( ! is_wp_error( $chrnx_link ) ) : ?>
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php echo chrnx_get_platform_links_markup( $chrnx_links, 'chrnx-platform-links', chrnx_get_project_link_slots() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||||
|
</article>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
+1
-1
@@ -232,7 +232,7 @@ function chrnx_get_editorial_card_markup( $post_id, $heading_level = 3, $class_n
|
|||||||
|
|
||||||
/** Register all block metadata directories that exist. */
|
/** Register all block metadata directories that exist. */
|
||||||
function chrnx_register_editorial_blocks() {
|
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' );
|
$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' );
|
||||||
foreach ( $blocks as $block ) {
|
foreach ( $blocks as $block ) {
|
||||||
$name = 'chrnx/' . $block;
|
$name = 'chrnx/' . $block;
|
||||||
if ( WP_Block_Type_Registry::get_instance()->is_registered( $name ) ) {
|
if ( WP_Block_Type_Registry::get_instance()->is_registered( $name ) ) {
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Tests for the project blocks.
|
||||||
|
*
|
||||||
|
* @package CHRNX
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify project block rendering.
|
||||||
|
*/
|
||||||
|
class ProjectBlocksTest extends WP_UnitTestCase {
|
||||||
|
/**
|
||||||
|
* Register blocks and taxonomies before each test.
|
||||||
|
*/
|
||||||
|
public function set_up() {
|
||||||
|
parent::set_up();
|
||||||
|
do_action( 'init' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure the list renders one card per project with its status.
|
||||||
|
*/
|
||||||
|
public function test_project_list_renders_a_card_per_project() {
|
||||||
|
$term_id = self::factory()->term->create(
|
||||||
|
array(
|
||||||
|
'taxonomy' => 'chrnx_project',
|
||||||
|
'name' => 'Green Tea',
|
||||||
|
'slug' => 'green-tea-test',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
update_term_meta( $term_id, 'chrnx_project_status', 'Beta' );
|
||||||
|
|
||||||
|
$markup = do_blocks( '<!-- wp:chrnx/project-list /-->' );
|
||||||
|
|
||||||
|
$this->assertStringContainsString( 'chrnx-project-card', $markup );
|
||||||
|
$this->assertStringContainsString( 'Green Tea', $markup );
|
||||||
|
$this->assertStringContainsString( 'Beta', $markup );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure a project without a cover still renders art.
|
||||||
|
*/
|
||||||
|
public function test_project_without_cover_uses_placeholder_art() {
|
||||||
|
self::factory()->term->create(
|
||||||
|
array(
|
||||||
|
'taxonomy' => 'chrnx_project',
|
||||||
|
'slug' => 'coverless-test',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$markup = do_blocks( '<!-- wp:chrnx/project-list /-->' );
|
||||||
|
|
||||||
|
$this->assertStringContainsString( 'chrnx-project-card__fallback', $markup );
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user