feat: add responsive CHRNX podcast atmosphere

This commit is contained in:
chrnx committed 2026-08-13 01:01:08 -05:00
1 parent 3840b7c168
commit 6443a46126
13 files changed
+190 -18

No files matched your search

+36
View File
@@ -42,3 +42,39 @@ function chrnx_get_topic_portrait_markup( string $topic_slug, string $alt = '',
return $markup;
}
/**
* Render an allowlisted decorative atmosphere using modern opaque derivatives.
*
* @param string $asset_key Fixed atmosphere key.
* @param string $class_name Optional image class.
* @return string Safe picture markup or an empty string.
*/
function chrnx_get_atmosphere_markup( string $asset_key, string $class_name = '' ): string {
if ( 'podcast-frequency' !== $asset_key ) {
return '';
}
$source = chrnx_get_topic_art_asset( $asset_key );
$dimensions = chrnx_get_topic_art_dimensions( $asset_key );
if ( '' === $source || 2 !== count( $dimensions ) ) {
return '';
}
$basename = pathinfo( $source, PATHINFO_FILENAME );
$base_uri = get_theme_file_uri( 'assets/images/generated/' . $basename );
$sizes = '(max-width: 780px) 100vw, 1200px';
$split_classes = preg_split( '/\s+/', trim( $class_name ) );
$classes = is_array( $split_classes ) ? array_filter( $split_classes ) : array();
$class = implode( ' ', array_map( 'sanitize_html_class', $classes ) );
$loading = 'lazy';
$alt = '';
$markup = '<picture class="chrnx-responsive-atmosphere" aria-hidden="true">';
$markup .= '<source type="image/avif" srcset="' . esc_url( $base_uri . '-384.avif' ) . ' 384w, ' . esc_url( $base_uri . '-768.avif' ) . ' 768w, ' . esc_url( $base_uri . '-1536.avif' ) . ' 1536w" sizes="' . esc_attr( $sizes ) . '">';
$markup .= '<source type="image/webp" srcset="' . esc_url( $base_uri . '-384.webp' ) . ' 384w, ' . esc_url( $base_uri . '-768.webp' ) . ' 768w, ' . esc_url( $base_uri . '-1536.webp' ) . ' 1536w" sizes="' . esc_attr( $sizes ) . '">';
$markup .= '<img' . ( '' !== $class ? ' class="' . esc_attr( $class ) . '"' : '' ) . ' src="' . esc_url( get_theme_file_uri( $source ) ) . '" width="' . esc_attr( $dimensions[0] ) . '" height="' . esc_attr( $dimensions[1] ) . '" loading="' . esc_attr( $loading ) . '" decoding="async" sizes="' . esc_attr( $sizes ) . '" alt="' . esc_attr( $alt ) . '">';
$markup .= '</picture>';
return $markup;
}
+13 -8
View File
@@ -624,14 +624,15 @@ function chrnx_get_related_post_ids( int $post_id, int $limit = 3 ): array {
*/
function chrnx_get_topic_art_asset( string $topic_slug ): string {
$mapping = array(
'research' => 'alter-ego-research.png',
'code' => 'alter-ego-code.png',
'literature' => 'alter-ego-literature.png',
'music' => 'the-no-names-musician-cutout.png',
'music-collage' => 'the-no-names-collage.jpeg',
'podcasts' => 'alter-ego-podcasts.png',
'life' => 'alter-ego-life.png',
'gaming' => 'alter-ego-gaming-half-body.png',
'research' => 'alter-ego-research.png',
'code' => 'alter-ego-code.png',
'literature' => 'alter-ego-literature.png',
'music' => 'the-no-names-musician-cutout.png',
'music-collage' => 'the-no-names-collage.jpeg',
'podcast-frequency' => 'podcast-frequency-grunge.png',
'podcasts' => 'alter-ego-podcasts.png',
'life' => 'alter-ego-life.png',
'gaming' => 'alter-ego-gaming-half-body.png',
);
return isset( $mapping[ $topic_slug ] ) ? 'assets/images/' . $mapping[ $topic_slug ] : '';
}
@@ -647,5 +648,9 @@ function chrnx_get_topic_art_dimensions( string $topic_slug ): array {
return array();
}
if ( 'podcast-frequency' === $topic_slug ) {
return array( 1536, 1024 );
}
return 'gaming' === $topic_slug ? array( 1024, 1536 ) : array( 1122, 1402 );
}