docs: a project archive must filter the journal, not clone a tracklist
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 file changed
+102
-12
@@ -583,17 +583,26 @@ git commit -m "feat: list every project with its status and links"
|
||||
|
||||
- Create: `blocks/project-detail/block.json`, `blocks/project-detail/render.php`
|
||||
- Modify: `inc/blocks.php:235` — add `'project-detail'` to the `$blocks` array, exactly as Task 4 added `'project-list'`
|
||||
- Modify: `inc/blocks.php:32` — add `'chrnx_project'` to the `is_tax()` list
|
||||
- Modify: `inc/queries.php` lines 377, 404, 434, 489, 529 — add `'chrnx_project'` to each taxonomy list
|
||||
- Test: `tests/php/ProjectBlocksTest.php` (extend)
|
||||
|
||||
**This block renders a HEADER ONLY. It does not list posts.** `blocks/release-detail/render.php` also renders a tracklist, and the first draft of this plan said to clone it line for line. That was wrong twice over: projects have no track numbers, and the posts belonging to a project are ordinary reverse-chronological editorial posts — which is exactly what `chrnx/journal-stream` already renders on an archive.
|
||||
|
||||
The correct model is `chrnx_show`, not `chrnx_release`. Podcast programmes list their episodes through `journal-stream` on the archive, because `chrnx_show` appears in the taxonomy lists inside `inc/queries.php`. `chrnx_project` appears in none of them, so without those five edits a project archive would render the whole unfiltered journal — the wrong posts, with no error.
|
||||
|
||||
**Interfaces:**
|
||||
|
||||
- Consumes: `chrnx_get_project_links()`, `chrnx_get_topic_portrait_markup()`.
|
||||
- Consumes: `chrnx_get_project_links()`, `chrnx_get_topic_portrait_markup()`, `chrnx_get_heading_level()`.
|
||||
- Produces: block `chrnx/project-detail`, consumed by `templates/taxonomy-chrnx_project.html`.
|
||||
|
||||
- [ ] **Step 1: Read the release equivalent**
|
||||
- [ ] **Step 1: Add `chrnx_project` to every taxonomy list**
|
||||
|
||||
Run: `cat blocks/release-detail/render.php`
|
||||
The project version renders the same shape: cover, status, description, links. Copy its structure exactly rather than inventing a new one.
|
||||
Five in `inc/queries.php` and one in `inc/blocks.php`. Read each one before editing; two of them list only two taxonomies rather than three.
|
||||
|
||||
```bash
|
||||
grep -n "chrnx_topic', 'chrnx_language'" inc/queries.php inc/blocks.php
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Write the failing test**
|
||||
|
||||
@@ -613,6 +622,7 @@ Append to `tests/php/ProjectBlocksTest.php`:
|
||||
)
|
||||
);
|
||||
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 ) );
|
||||
|
||||
@@ -620,30 +630,108 @@ Append to `tests/php/ProjectBlocksTest.php`:
|
||||
|
||||
$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 );
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Run the test to verify it fails**
|
||||
- [ ] **Step 3: Run the tests to verify they fail**
|
||||
|
||||
Run: `npm run test:php`
|
||||
Expected: FAIL, block not registered.
|
||||
Expected: FAIL — the block is unregistered, and the archive filter test shows the unrelated post.
|
||||
|
||||
- [ ] **Step 4: Create the block**
|
||||
|
||||
`blocks/project-detail/block.json` mirrors Task 4's JSON with `"name": "chrnx/project-detail"`, `"title": "Project Detail"`, `"description": "Cover, status and links for the queried project."`, and no `headingLevel` attribute.
|
||||
`blocks/project-detail/block.json` mirrors Task 4's JSON with `"name": "chrnx/project-detail"`, `"title": "Project Detail"`, `"description": "Cover, status, description and links for the queried project."`, and a `headingLevel` attribute defaulting to 2.
|
||||
|
||||
`blocks/project-detail/render.php` follows `blocks/release-detail/render.php` line for line, substituting `chrnx_release` with `chrnx_project`, `chrnx_get_release_links` with `chrnx_get_project_links`, `chrnx_release_cover` with `chrnx_project_cover`, `chrnx_release_status` with `chrnx_project_status`, `placeholder-release` with `placeholder-project`, and the `chrnx-release-` class prefix with `chrnx-project-`.
|
||||
`blocks/project-detail/render.php` follows the HEAD section of `blocks/release-detail/render.php` only — its guard, its art column, and its intro column. Stop before the tracklist; do not port it.
|
||||
|
||||
- [ ] **Step 5: Run the tests to verify they pass**
|
||||
```php
|
||||
<?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>
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Register the block**
|
||||
|
||||
Add `'project-detail'` to the `$blocks` array at `inc/blocks.php:235`.
|
||||
|
||||
- [ ] **Step 6: Run the tests to verify they pass**
|
||||
|
||||
Run: `npm run test:php && npm run phpcs`
|
||||
Expected: PASS.
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
- [ ] **Step 7: Commit**
|
||||
|
||||
```bash
|
||||
git add blocks/project-detail tests/php/ProjectBlocksTest.php
|
||||
git commit -m "feat: give each project its own page header"
|
||||
git add blocks/project-detail inc/blocks.php inc/queries.php tests/php/ProjectBlocksTest.php
|
||||
git commit -m "feat: give each project its own page header and post stream"
|
||||
```
|
||||
|
||||
---
|
||||
@@ -678,6 +766,8 @@ Expected: FAIL, both templates missing.
|
||||
<main id="chrnx-main" class="wp-block-group chrnx-archive chrnx-project-archive" tabindex="-1">
|
||||
<!-- wp:query-title {"type":"archive","level":1,"showPrefix":false} /-->
|
||||
<!-- wp:chrnx/project-detail /-->
|
||||
<!-- wp:chrnx/journal-stream /-->
|
||||
<!-- wp:chrnx/subscribe-cta {"className":"is-style-quiet"} /-->
|
||||
</main>
|
||||
<!-- /wp:group -->
|
||||
|
||||
|
||||
Reference in new issue
Block a user