fix: address CHRNX editorial review findings
This commit is contained in:
17 files changed
+236
-10
No files matched your search
+29
-1
@@ -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 ) ) {
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
Reference in new issue
Block a user