fix: address CHRNX editorial review findings

This commit is contained in:
chrnx committed 2026-08-11 18:18:05 -05:00
1 parent 247f9a7915
commit 7297523e26
17 files changed
+236 -10

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "chrnx/journal-link",
"version": "0.1.0",
"title": "Journal Link",
"category": "theme",
"description": "Display a translated portable link to the full Journal.",
"textdomain": "chrnx",
"supports": { "html": false },
"render": "file:./render.php"
}
+8
View File
@@ -0,0 +1,8 @@
<?php
/**
* Journal Link block render.
*
* @package CHRNX
*/
?>
<p <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-journal-link' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>><a href="<?php echo esc_url( chrnx_get_full_journal_url() ); ?>"><?php echo esc_html__( 'Browse the full Journal', 'chrnx' ); ?></a></p>
+4 -1
View File
@@ -101,6 +101,9 @@ $chrnx_title_id = wp_unique_id( 'chrnx-journal-title-' );
</nav>
<?php endif; ?>
<?php else : ?>
<p class="chrnx-journal-stream__empty"><?php echo esc_html__( 'No journal entries match these filters yet.', 'chrnx' ); ?></p>
<p class="chrnx-journal-stream__empty">
<?php echo esc_html__( 'No journal entries match these filters yet.', 'chrnx' ); ?>
<a href="<?php echo esc_url( chrnx_get_full_journal_url() ); ?>"><?php echo esc_html__( 'Browse the full Journal', 'chrnx' ); ?></a>
</p>
<?php endif; ?>
</section>
+13
View File
@@ -0,0 +1,13 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "chrnx/reading-time",
"version": "0.1.0",
"title": "Reading Time",
"category": "theme",
"description": "Display a localized estimate based on the current post content.",
"textdomain": "chrnx",
"usesContext": ["postId", "postType"],
"supports": { "html": false },
"render": "file:./render.php"
}
+23
View File
@@ -0,0 +1,23 @@
<?php
/**
* Reading Time block render.
*
* @package CHRNX
*/
$chrnx_post_id = isset( $block->context['postId'] ) ? absint( $block->context['postId'] ) : get_the_ID();
$chrnx_post = get_post( $chrnx_post_id );
if ( ! $chrnx_post instanceof WP_Post ) {
return;
}
$chrnx_minutes = chrnx_get_reading_time_minutes( $chrnx_post->post_content );
if ( 0 === $chrnx_minutes ) {
return;
}
$chrnx_label = sprintf(
/* translators: %s: estimated reading time in minutes. */
_n( '%s minute read', '%s minutes read', $chrnx_minutes, 'chrnx' ),
number_format_i18n( $chrnx_minutes )
);
?>
<span <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-reading-time' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>><?php echo esc_html( $chrnx_label ); ?></span>
+3 -2
View File
@@ -11,7 +11,8 @@ if ( '' === $chrnx_topic && is_tax( 'chrnx_topic' ) ) {
$chrnx_topic = $chrnx_queried instanceof WP_Term ? $chrnx_queried->slug : '';
}
$chrnx_asset = chrnx_get_topic_art_asset( $chrnx_topic );
if ( '' === $chrnx_asset ) {
$chrnx_size = chrnx_get_topic_art_dimensions( $chrnx_topic );
if ( '' === $chrnx_asset || 2 !== count( $chrnx_size ) ) {
return;
}
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
@@ -24,7 +25,7 @@ $chrnx_label = $chrnx_term instanceof WP_Term ? $chrnx_term->name : ucfirst( $
</div>
<div class="chrnx-topic-hero__art">
<?php if ( is_readable( get_theme_file_path( $chrnx_asset ) ) ) : ?>
<img src="<?php echo esc_url( get_theme_file_uri( $chrnx_asset ) ); ?>" width="1122" height="1402" loading="lazy" decoding="async" alt="" aria-hidden="true">
<img src="<?php echo esc_url( get_theme_file_uri( $chrnx_asset ) ); ?>" width="<?php echo esc_attr( $chrnx_size[0] ); ?>" height="<?php echo esc_attr( $chrnx_size[1] ); ?>" loading="lazy" decoding="async" alt="" aria-hidden="true">
<?php else : ?>
<span class="chrnx-topic-hero__fallback" aria-hidden="true"></span>
<?php endif; ?>
+6
View File
@@ -2,6 +2,12 @@
min-width: min(100%, 16rem);
}
.chrnx-topic-hero__art img {
display: block;
height: auto;
max-width: 100%;
}
.chrnx-topic-hero__fallback {
aspect-ratio: 4 / 5;
background-color: var(--wp--preset--color--panel);
+29 -1
View File
@@ -17,6 +17,34 @@ function chrnx_get_heading_level( $value, $fallback_level = 2 ) {
return in_array( $level, array( 2, 3, 4, 5, 6 ), true ) ? $level : $fallback_level;
}
/**
* Estimate localized reading time from stored post content without rendering it.
*
* @param string $content Raw post content.
* @return int Estimated whole minutes, or zero for empty content.
*/
function chrnx_get_reading_time_minutes( $content ) {
if ( ! is_string( $content ) || '' === trim( $content ) ) {
return 0;
}
$text = preg_replace( '/<!--(?:.|\s)*?-->/', ' ', strip_shortcodes( $content ) );
$text = html_entity_decode( wp_strip_all_tags( (string) $text, true ), ENT_QUOTES | ENT_HTML5, 'UTF-8' );
$text = wp_check_invalid_utf8( $text );
if ( '' === trim( $text ) ) {
return 0;
}
if ( str_starts_with( wp_get_word_count_type(), 'characters' ) ) {
$characters = preg_replace( '/\s+/u', '', $text );
$count = mb_strlen( (string) $characters, 'UTF-8' );
return max( 1, (int) ceil( $count / 500 ) );
}
$count = preg_match_all( "/[\p{L}\p{N}]+(?:['’\x{2010}-\x{2015}-][\p{L}\p{N}]+)*/u", $text );
return false === $count || 0 === $count ? 0 : max( 1, (int) ceil( $count / 200 ) );
}
/**
* Render a post's meaningful featured image or decorative topic fallback.
*
@@ -74,7 +102,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' );
$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' );
foreach ( $blocks as $block ) {
$name = 'chrnx/' . $block;
if ( WP_Block_Type_Registry::get_instance()->is_registered( $name ) ) {
+31
View File
@@ -332,6 +332,23 @@ function chrnx_get_journal_base_url() {
return add_query_arg( $routing_values, $base_url );
}
/**
* Return the canonical full Journal destination independent of current filters.
*
* @return string Portable Journal URL.
*/
function chrnx_get_full_journal_url() {
$page = get_page_by_path( 'journal', OBJECT, 'page' );
if ( $page instanceof WP_Post && 'publish' === $page->post_status ) {
$url = get_permalink( $page );
if ( is_string( $url ) && '' !== $url ) {
return $url;
}
}
return home_url( '/journal/' );
}
/**
* Build a Journal page URL from only validated public filters.
*
@@ -543,3 +560,17 @@ function chrnx_get_topic_art_asset( string $topic_slug ): string {
);
return isset( $mapping[ $topic_slug ] ) ? 'assets/images/' . $mapping[ $topic_slug ] : '';
}
/**
* Return exact intrinsic dimensions for allowlisted topic art.
*
* @param string $topic_slug Supported topic slug.
* @return int[] Width and height, or an empty array.
*/
function chrnx_get_topic_art_dimensions( string $topic_slug ): array {
if ( '' === chrnx_get_topic_art_asset( $topic_slug ) ) {
return array();
}
return 'gaming' === $topic_slug ? array( 1024, 1536 ) : array( 1122, 1402 );
}
+2 -2
View File
@@ -13,9 +13,9 @@ $chrnx_research_url = esc_url( 'https://arxiv.org/abs/2603.05352' );
<!-- wp:group {"tagName":"section","className":"chrnx-about","layout":{"type":"constrained","contentSize":"70ch"}} -->
<section class="wp-block-group chrnx-about">
<!-- wp:heading {"level":1} --><h1 class="wp-block-heading"><?php echo esc_html__( 'About', 'chrnx' ); ?></h1><!-- /wp:heading -->
<!-- wp:paragraph --><p><?php echo esc_html__( 'I am an autistic Level 1 independent researcher and software developer exploring emotion modeling and game AI.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
<!-- wp:paragraph --><p><?php echo esc_html__( 'I work as Lead Developer @Expressive Tea, building full-stack software with JavaScript and Python. My practice includes open source work and amateur data science.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
<!-- wp:paragraph --><p><?php echo esc_html__( 'I work as Lead Developer @Expressive Tea, building full-stack software with JavaScript and Python. I am also an independent researcher exploring emotion modeling and game AI; my practice includes open source work and amateur data science.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
<!-- wp:paragraph --><p><?php echo esc_html__( 'I am a published researcher. My current paper is available on', 'chrnx' ); ?> <a href="<?php echo $chrnx_research_url; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped at assignment. ?>" target="_blank" rel="noopener noreferrer external"><?php echo esc_html__( 'arXiv:2603.05352', 'chrnx' ); ?></a>.</p><!-- /wp:paragraph -->
<!-- wp:paragraph --><p><?php echo esc_html__( 'I am an autistic Level 1 software developer and researcher.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
<!-- wp:heading --><h2 class="wp-block-heading"><?php echo esc_html__( 'Beyond the work', 'chrnx' ); ?></h2><!-- /wp:heading -->
<!-- wp:paragraph --><p><?php echo esc_html__( 'I am the father of three wonderful children, a musician, a gamer, and pet-friendly.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
</section>
+7 -1
View File
@@ -9,6 +9,7 @@
* @package CHRNX
*/
$chrnx_music_collage = get_theme_file_uri( 'assets/images/the-no-names-collage.jpeg' );
$chrnx_music_cutout = get_theme_file_uri( 'assets/images/the-no-names-musician-cutout.png' );
?>
<!-- wp:group {"tagName":"section","className":"chrnx-music-landing","layout":{"type":"constrained"}} -->
<section class="wp-block-group chrnx-music-landing">
@@ -16,7 +17,12 @@ $chrnx_music_collage = get_theme_file_uri( 'assets/images/the-no-names-collage.j
<!-- wp:paragraph --><p><?php echo esc_html__( 'Grunge mexicano para cerebros que no se callan.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
<!-- wp:paragraph --><p><?php echo esc_html__( 'The No Names es una banda activa y un proyecto de grunge en español mexicano desde Sinaloa: guitarras sucias, graves físicos, dinámica cruda de estudio y una voz que va de la contención a la ruptura. estudio crudo, cero live.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
<!-- wp:paragraph --><p><?php echo esc_html__( 'El proceso usa generative AI anclada en la voz humana real de Chrnx. Es una herramienta de producción, no una mitología ficticia ni una promesa sobre lo que la tecnología puede hacer.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
<!-- wp:html --><img class="chrnx-music-landing__art" src="<?php echo esc_url( $chrnx_music_collage ); ?>" width="1122" height="1402" loading="lazy" decoding="async" alt="<?php echo esc_attr__( 'The No Names collage', 'chrnx' ); ?>"><!-- /wp:html -->
<!-- wp:group {"className":"chrnx-music-landing__art","layout":{"type":"flex","flexWrap":"wrap"}} -->
<div class="wp-block-group chrnx-music-landing__art">
<!-- wp:html --><img src="<?php echo esc_url( $chrnx_music_collage ); ?>" width="1122" height="1402" loading="lazy" decoding="async" alt="<?php echo esc_attr__( 'The No Names collage', 'chrnx' ); ?>"><!-- /wp:html -->
<!-- wp:html --><img src="<?php echo esc_url( $chrnx_music_cutout ); ?>" width="1122" height="1402" loading="lazy" decoding="async" alt="<?php echo esc_attr__( 'The No Names musician portrait', 'chrnx' ); ?>"><!-- /wp:html -->
</div>
<!-- /wp:group -->
<!-- wp:heading --><h2 class="wp-block-heading"><?php echo esc_html__( 'Releases in progress', 'chrnx' ); ?></h2><!-- /wp:heading -->
<!-- wp:group {"className":"chrnx-release-list","layout":{"type":"grid","minimumColumnWidth":"18rem"}} -->
<div class="wp-block-group chrnx-release-list">
+2
View File
@@ -8,10 +8,12 @@
*
* @package CHRNX
*/
$chrnx_podcast_show_art = get_theme_file_uri( 'assets/images/alter-ego-podcasts.png' );
?>
<!-- wp:group {"tagName":"article","className":"chrnx-podcast-show","layout":{"type":"constrained"}} -->
<article class="wp-block-group chrnx-podcast-show">
<!-- wp:post-title {"level":1} /-->
<!-- wp:html --><img class="chrnx-podcast-show__art" src="<?php echo esc_url( $chrnx_podcast_show_art ); ?>" width="1122" height="1402" loading="lazy" decoding="async" alt="" aria-hidden="true"><!-- /wp:html -->
<!-- wp:group {"metadata":{"name":"chrnx/show-cover"},"layout":{"type":"constrained"}} --><div class="wp-block-group"></div><!-- /wp:group -->
<!-- wp:group {"metadata":{"name":"chrnx/show-description"},"layout":{"type":"constrained"}} --><div class="wp-block-group"></div><!-- /wp:group -->
<!-- wp:group {"metadata":{"name":"chrnx/show-hosts"},"layout":{"type":"constrained"}} --><div class="wp-block-group"></div><!-- /wp:group -->
+1
View File
@@ -8,6 +8,7 @@
<!-- wp:navigation {"overlayMenu":"never","className":"chrnx-not-found__recovery"} -->
<!-- wp:home-link {"label":"Home"} /-->
<!-- /wp:navigation -->
<!-- wp:chrnx/journal-link /-->
</main>
<!-- /wp:group -->
+1
View File
@@ -8,6 +8,7 @@
<!-- wp:post-terms {"term":"chrnx_topic"} /-->
<!-- wp:post-terms {"term":"chrnx_language"} /-->
<!-- wp:post-date /-->
<!-- wp:chrnx/reading-time /-->
</div>
<!-- /wp:group -->
<!-- wp:post-featured-image {"aspectRatio":"3/2"} /-->
+78 -2
View File
@@ -15,9 +15,9 @@ class BlockRenderingTest extends WP_UnitTestCase {
delete_option( 'chrnx_subscribe_page_id' );
}
/** All twelve block types register from metadata. */
/** All fourteen block types register from metadata. */
public function test_all_editorial_blocks_are_registered() {
$names = 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' );
$names = 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' );
foreach ( $names as $name ) {
$type = WP_Block_Type_Registry::get_instance()->get_registered( 'chrnx/' . $name );
$this->assertInstanceOf( WP_Block_Type::class, $type, $name );
@@ -145,9 +145,73 @@ class BlockRenderingTest extends WP_UnitTestCase {
);
foreach ( $expected as $slug => $filename ) {
$this->assertSame( 'assets/images/' . $filename, chrnx_get_topic_art_asset( $slug ) );
$this->assertSame( 'gaming' === $slug ? array( 1024, 1536 ) : array( 1122, 1402 ), chrnx_get_topic_art_dimensions( $slug ) );
}
foreach ( array( '', 'unknown', '../secret.png', 'assets/images/anything.png' ) as $value ) {
$this->assertSame( '', chrnx_get_topic_art_asset( $value ) );
$this->assertSame( array(), chrnx_get_topic_art_dimensions( $value ) );
}
}
/** Reading time counts real Unicode words, ignores markup, and localizes singular/plural labels. */
public function test_reading_time_is_robust_and_localized() {
$this->assertSame( 0, chrnx_get_reading_time_minutes( '' ) );
$this->assertSame( 1, chrnx_get_reading_time_minutes( '<!-- wp:paragraph --><p>Árbol, café &amp; código.</p><!-- /wp:paragraph -->' ) );
$this->assertSame( 2, chrnx_get_reading_time_minutes( implode( ' ', array_fill( 0, 201, 'palabra' ) ) ) );
$post_id = self::factory()->post->create(
array(
'post_content' => implode( ' ', array_fill( 0, 201, 'palabra' ) ),
)
);
$translate = static function ( $translation, $single, $plural, $number, $domain ) {
if ( 'chrnx' === $domain && '%s minute read' === $single ) {
return 1 === $number ? '%s minuto de lectura' : '%s minutos de lectura';
}
return $translation;
};
add_filter( 'ngettext', $translate, 10, 5 );
try {
$output = $this->render_for_post( 'chrnx/reading-time', $post_id );
} finally {
remove_filter( 'ngettext', $translate, 10 );
}
$this->assertStringContainsString( '2 minutos de lectura', $output );
$this->assertStringNotContainsString( 'palabra', $output );
}
/** Empty/recovery links always point directly to a portable full Journal URL. */
public function test_journal_recovery_links_are_localized_and_portable() {
$portable_home = static function ( $url, $path ) {
return 'https://example.test/subdirectory/' . ltrim( (string) $path, '/' );
};
add_filter( 'home_url', $portable_home, 10, 2 );
try {
$link = render_block(
array(
'blockName' => 'chrnx/journal-link',
'attrs' => array(),
'innerBlocks' => array(),
'innerHTML' => '',
'innerContent' => array(),
)
);
$this->assertStringContainsString( 'href="https://example.test/subdirectory/journal/"', $link );
$this->assertStringContainsString( 'Browse the full Journal', $link );
$stream = render_block(
array(
'blockName' => 'chrnx/journal-stream',
'attrs' => array(),
'innerBlocks' => array(),
'innerHTML' => '',
'innerContent' => array(),
)
);
$this->assertStringContainsString( 'href="https://example.test/subdirectory/journal/"', $stream );
$this->assertStringContainsString( 'Browse the full Journal', $stream );
} finally {
remove_filter( 'home_url', $portable_home, 10 );
}
}
@@ -235,6 +299,18 @@ class BlockRenderingTest extends WP_UnitTestCase {
)
);
$this->assertSame( '', $unsafe );
$gaming = render_block(
array(
'blockName' => 'chrnx/topic-hero',
'attrs' => array( 'topic' => 'gaming' ),
'innerBlocks' => array(),
'innerHTML' => '',
'innerContent' => array(),
)
);
$this->assertStringContainsString( 'width="1024"', $gaming );
$this->assertStringContainsString( 'height="1536"', $gaming );
}
/** Subscribe CTA is exactly empty until a published Page is configured. */
+14 -1
View File
@@ -58,7 +58,7 @@ class PatternsTest extends WP_UnitTestCase {
/** Local art is generated through escaped theme URIs with intrinsic dimensions. */
public function test_art_patterns_use_only_escaped_local_theme_images() {
foreach ( array( 'home-music', 'music-landing', 'podcast-landing' ) as $name ) {
foreach ( array( 'home-music', 'music-landing', 'podcast-landing', 'podcast-show' ) as $name ) {
$source = file_get_contents( get_theme_file_path( 'patterns/' . $name . '.php' ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local test fixture.
$content = $this->render_pattern( get_theme_file_path( 'patterns/' . $name . '.php' ) );
$this->assertStringContainsString( 'get_theme_file_uri(', $source, $name );
@@ -66,6 +66,15 @@ class PatternsTest extends WP_UnitTestCase {
$this->assertMatchesRegularExpression( '/<img\b[^>]*\bwidth="1122"[^>]*\bheight="1402"/i', $content, $name );
$this->assertMatchesRegularExpression( '/<img\b[^>]*\bloading="lazy"[^>]*\bdecoding="async"/i', $content, $name );
}
$music = $this->render_pattern( get_theme_file_path( 'patterns/music-landing.php' ) );
$this->assertStringContainsString( 'the-no-names-collage.jpeg', $music );
$this->assertStringContainsString( 'the-no-names-musician-cutout.png', $music );
$this->assertSame( 2, substr_count( $music, '<img' ) );
$show = $this->render_pattern( get_theme_file_path( 'patterns/podcast-show.php' ) );
$this->assertStringContainsString( 'alter-ego-podcasts.png', $show );
$this->assertStringContainsString( 'alt=""', $show );
$this->assertStringContainsString( 'aria-hidden="true"', $show );
}
/** Music copy contains only the exact approved public facts and release statuses. */
@@ -102,6 +111,10 @@ class PatternsTest extends WP_UnitTestCase {
$this->assertStringContainsString( 'target="_blank"', $content );
$this->assertStringContainsString( 'rel="noopener noreferrer external"', $content );
$this->assertDoesNotMatchRegularExpression( '/diagnos|inspir|overcame|despite/i', $content );
$plain = wp_strip_all_tags( $content );
$this->assertLessThan( strpos( $plain, 'autistic Level 1' ), strpos( $plain, 'Lead Developer @Expressive Tea' ) );
$this->assertLessThan( strpos( $plain, 'autistic Level 1' ), strpos( $plain, 'emotion modeling and game AI' ) );
$this->assertLessThan( strpos( $plain, 'father of three wonderful children' ), strpos( $plain, 'autistic Level 1' ) );
}
/** Reusable project/release/show/episode structures do not invent visible starter data. */
+2
View File
@@ -63,6 +63,7 @@ test('single provides readable content, neutral metadata, and post-only componen
assert.match(markup, /wp:post-terms \{"term":"chrnx_topic"/);
assert.match(markup, /wp:post-terms \{"term":"chrnx_language"/);
assert.match(markup, /wp:post-date/);
assert.match(markup, /wp:chrnx\/reading-time/);
assert.match(markup, /wp:post-featured-image/);
assert.match(markup, /wp:post-content/);
assert.match(markup, /wp:chrnx\/podcast-meta/);
@@ -100,5 +101,6 @@ test('404 offers concise recovery with search, Journal, and home links', async (
assert.match(markup, /Page not found/);
assert.match(markup, /wp:search/);
assert.match(markup, /wp:home-link/);
assert.match(markup, /wp:chrnx\/journal-link/);
assert.doesNotMatch(markup, /"url":"\//);
});