feat: give each project its own page header and post stream

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
chrnxandClaude Opus 5 committed 2026-08-15 14:19:58 -05:00
1 parent 51532118bc
commit aea2c6754b
5 files changed
+114 -7

No files matched your search

+13
View File
@@ -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"
}
+39
View File
@@ -0,0 +1,39 @@
<?php
/**
* Project Detail block render.
*
* @package CHRNX
*/
$chrnx_term = get_queried_object();
if ( ! $chrnx_term instanceof WP_Term || 'chrnx_project' !== $chrnx_term->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' );
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-project-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<div class="<?php echo esc_attr( $chrnx_head_class ); ?>">
<div class="chrnx-project-detail__art">
<?php if ( $chrnx_cover > 0 ) : ?>
<?php echo wp_get_attachment_image( $chrnx_cover, 'large', false, array( 'class' => 'chrnx-project-detail__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?>
<?php echo chrnx_get_topic_portrait_markup( 'placeholder-project', '', 'chrnx-project-detail__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
<?php endif; ?>
</div>
<div class="chrnx-project-detail__intro">
<?php if ( '' !== $chrnx_status ) : ?>
<p class="chrnx-project-detail__status"><?php echo esc_html( $chrnx_status ); ?></p>
<?php endif; ?>
<?php if ( '' !== $chrnx_term->description ) : ?>
<p class="chrnx-project-detail__description"><?php echo esc_html( $chrnx_term->description ); ?></p>
<?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 ?>
</div>
</div>
</section>
+2 -2
View File
@@ -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 ) ) {
+5 -5
View File
@@ -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 ) {
+55
View File
@@ -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( '<!-- wp:chrnx/project-detail /-->' );
$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( '<!-- wp:chrnx/project-detail /-->' ) ) );
}
/**
* 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( '<!-- wp:chrnx/journal-stream /-->' );
$this->assertStringContainsString( 'Belongs to the project', $markup );
$this->assertStringNotContainsString( 'Unrelated post', $markup );
}
}