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

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

@@ -0,0 +1,5 @@
{
"source": "podcast-frequency-grunge.png",
"formats": [ "avif", "webp" ],
"widths": [ 384, 768, 1536 ]
}
+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 );
}
+20
View File
@@ -73,6 +73,23 @@ chrnx_build_responsive_image() {
done
}
chrnx_build_responsive_background() {
chrnx_image_basename=$1
chrnx_image_source_name=$2
chrnx_image_source="$chrnx_image_root/assets/images/$chrnx_image_source_name"
if [ ! -f "$chrnx_image_source" ]; then
echo "Source image is missing: $chrnx_image_source" >&2
exit 1
fi
for chrnx_image_width in 384 768 1536; do
chrnx_image_resized="$chrnx_image_tmp/$chrnx_image_basename-$chrnx_image_width.png"
sips --resampleWidth "$chrnx_image_width" "$chrnx_image_source" --out "$chrnx_image_resized" >/dev/null
cwebp -quiet -preset picture -q 62 -m 6 -metadata none "$chrnx_image_resized" -o "$chrnx_image_output/$chrnx_image_basename-$chrnx_image_width.webp"
avifenc --ignore-exif --ignore-xmp --ignore-icc --qcolor 52 --speed 6 "$chrnx_image_resized" "$chrnx_image_output/$chrnx_image_basename-$chrnx_image_width.avif" >/dev/null
done
}
for chrnx_image_topic in code gaming life literature podcasts research; do
chrnx_build_responsive_image "alter-ego-$chrnx_image_topic" "alter-ego-$chrnx_image_topic.png"
printf '{\n\t"source": "alter-ego-%s.png",\n\t"formats": [ "avif", "webp" ],\n\t"widths": [ 384, 768 ]\n}\n' "$chrnx_image_topic" > "$chrnx_image_output/alter-ego-$chrnx_image_topic.json"
@@ -86,3 +103,6 @@ printf '{\n\t"source": "the-no-names-musician-cutout.png",\n\t"formats": [ "avif
chrnx_build_responsive_image "the-no-names-collage" "the-no-names-collage.jpeg" 58
printf '{\n\t"source": "the-no-names-collage.jpeg",\n\t"formats": [ "avif", "webp" ],\n\t"widths": [ 384, 768 ]\n}\n' > "$chrnx_image_output/the-no-names-collage.json"
chrnx_build_responsive_background "podcast-frequency-grunge" "podcast-frequency-grunge.png"
printf '{\n\t"source": "podcast-frequency-grunge.png",\n\t"formats": [ "avif", "webp" ],\n\t"widths": [ 384, 768, 1536 ]\n}\n' > "$chrnx_image_output/podcast-frequency-grunge.json"
+45
View File
@@ -1,3 +1,4 @@
import json
import shutil
import subprocess
import sys
@@ -9,6 +10,7 @@ from PIL import Image
PROJECT_ROOT = Path(__file__).resolve().parents[2]
ASSET_DIRECTORY = PROJECT_ROOT / "assets" / "images"
GENERATED_DIRECTORY = ASSET_DIRECTORY / "generated"
ALTER_EGO_ASSETS = (
"alter-ego-code.png",
"alter-ego-literature.png",
@@ -19,6 +21,12 @@ ALTER_EGO_ASSETS = (
)
ALTER_EGO_SOURCE_ASSETS = (*ALTER_EGO_ASSETS, "alter-ego-gaming-half-body.png")
BACKGROUND_ASSETS = ("podcast-frequency-grunge.png",)
PODCAST_DERIVATIVES = tuple(
f"podcast-frequency-grunge-{width}.{extension}"
for width in (384, 768, 1536)
for extension in ("avif", "webp")
)
PODCAST_MANIFEST = "podcast-frequency-grunge.json"
CONTACT_SHEET_SCRIPT = PROJECT_ROOT / "scripts" / "build-alter-ego-contact-sheet.py"
@@ -144,6 +152,43 @@ def test_background_asset_inventory_and_image_contract() -> None:
)
def test_podcast_responsive_derivative_inventory_manifest_and_budgets() -> None:
generated_names = sorted(path.name for path in GENERATED_DIRECTORY.iterdir())
assert len(generated_names) == 52, (
f"generated inventory expected 52 files, got {len(generated_names)}"
)
for name in (*PODCAST_DERIVATIVES, PODCAST_MANIFEST):
assert name in generated_names, f"missing {name}"
manifest = json.loads((GENERATED_DIRECTORY / PODCAST_MANIFEST).read_text())
assert manifest == {
"source": "podcast-frequency-grunge.png",
"formats": ["avif", "webp"],
"widths": [384, 768, 1536],
}
family_total = 0
for name in PODCAST_DERIVATIVES:
size = (GENERATED_DIRECTORY / name).stat().st_size
width = int(name.rsplit("-", 1)[1].split(".", 1)[0])
limit = 260 * 1024 if width == 1536 else 160 * 1024
assert size <= limit, f"{name} exceeds {limit} bytes: {size} bytes"
family_total += size
assert family_total <= 620 * 1024, (
"podcast-frequency-grunge family exceeds 620 KiB: "
f"{family_total} total bytes"
)
binary_total = sum(
path.stat().st_size
for path in GENERATED_DIRECTORY.iterdir()
if path.suffix in {".avif", ".webp"}
)
assert binary_total <= 2.75 * 1024 * 1024, (
f"generated binary payload exceeds 2.75 MiB: {binary_total} total bytes"
)
def test_background_contract_rejects_corrupt_idat_data(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
+36
View File
@@ -7,6 +7,42 @@
/** Responsive asset helper coverage. */
class ResponsiveMediaTest extends WP_UnitTestCase {
/** The podcast atmosphere resolves only to its fixed local master and dimensions. */
public function test_podcast_atmosphere_asset_is_allowlisted_with_exact_dimensions() {
$this->assertSame( 'assets/images/podcast-frequency-grunge.png', chrnx_get_topic_art_asset( 'podcast-frequency' ) );
$this->assertSame( array( 1536, 1024 ), chrnx_get_topic_art_dimensions( 'podcast-frequency' ) );
}
/** Podcast atmosphere markup exposes all modern widths and a decorative fallback. */
public function test_podcast_atmosphere_markup_is_responsive_and_decorative() {
$markup = chrnx_get_atmosphere_markup( 'podcast-frequency', 'chrnx-character-stage__frequency' );
$this->assertStringContainsString( '<picture', $markup );
$this->assertStringContainsString( 'class="chrnx-responsive-atmosphere"', $markup );
$this->assertStringContainsString( 'aria-hidden="true"', $markup );
$this->assertStringContainsString( 'type="image/avif"', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-384.avif 384w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-768.avif 768w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-1536.avif 1536w', $markup );
$this->assertStringContainsString( 'type="image/webp"', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-384.webp 384w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-768.webp 768w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-1536.webp 1536w', $markup );
$this->assertStringContainsString( 'sizes="(max-width: 780px) 100vw, 1200px"', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge.png', $markup );
$this->assertStringContainsString( 'class="chrnx-character-stage__frequency"', $markup );
$this->assertStringContainsString( 'width="1536"', $markup );
$this->assertStringContainsString( 'height="1024"', $markup );
$this->assertStringContainsString( 'loading="lazy"', $markup );
$this->assertStringContainsString( 'decoding="async"', $markup );
$this->assertStringContainsString( 'alt=""', $markup );
}
/** Unknown atmosphere keys cannot synthesize asset paths or markup. */
public function test_unknown_atmosphere_returns_empty_markup() {
$this->assertSame( '', chrnx_get_atmosphere_markup( '../../private', 'unsafe class' ) );
}
/** Approved topic portraits render a compact picture element with a PNG fallback. */
public function test_topic_portrait_picture_markup_has_modern_sources_and_dimensions() {
$markup = chrnx_get_topic_portrait_markup( 'code', 'Code workshop portrait', 'chrnx-section-portrait' );
+35 -10
View File
@@ -166,7 +166,7 @@ test( 'lower home sections preserve editorial order and define layered panel tre
}
} );
test( 'all approved portraits rebuild byte-identically within payload bounds', () => {
test( 'all approved responsive media rebuild byte-identically within payload bounds', () => {
const readme = read( 'README.md' );
const documentedCommand = 'mktemp -d "${TMPDIR:-/tmp}/chrnx-responsive.XXXXXX"';
assert.ok( readme.includes( documentedCommand ) );
@@ -182,7 +182,7 @@ test( 'all approved portraits rebuild byte-identically within payload bounds', (
assert.deepEqual( readdirSync( external ), [ 'sentinel' ] );
execFileSync( './scripts/build-responsive-images.sh', [ output ], { cwd: new URL( '../..', import.meta.url ) } );
const names = readdirSync( output ).sort();
assert.equal( names.length, 45 );
assert.equal( names.length, 52 );
for ( const name of [
'alter-ego-gaming-half-body-384.avif',
'alter-ego-gaming-half-body-384.webp',
@@ -194,19 +194,37 @@ test( 'all approved portraits rebuild byte-identically within payload bounds', (
'the-no-names-collage-768.avif',
'the-no-names-collage-768.webp',
'the-no-names-collage.json',
'podcast-frequency-grunge-384.avif',
'podcast-frequency-grunge-384.webp',
'podcast-frequency-grunge-768.avif',
'podcast-frequency-grunge-768.webp',
'podcast-frequency-grunge-1536.avif',
'podcast-frequency-grunge-1536.webp',
'podcast-frequency-grunge.json',
] ) {
assert.ok( names.includes( name ), `missing ${ name }` );
}
assert.deepEqual(
JSON.parse( readFileSync( join( output, 'podcast-frequency-grunge.json' ), 'utf8' ) ),
{
source: 'podcast-frequency-grunge.png',
formats: [ 'avif', 'webp' ],
widths: [ 384, 768, 1536 ],
},
);
let total = 0;
let collageTotal = 0;
let gamingHalfBodyTotal = 0;
let podcastTotal = 0;
for ( const name of names ) {
const generated = readFileSync( join( output, name ) );
const committed = readFileSync( new URL( `../../assets/images/generated/${ name }`, import.meta.url ) );
assert.deepEqual( generated, committed, `${ name } must rebuild byte-identically` );
if ( /\.(?:avif|webp)$/.test( name ) ) {
assert.ok( statSync( join( output, name ) ).size <= 160 * 1024, `${ name } exceeds 160 KiB` );
const expectedWidth = Number( name.match( /-(384|768)\.(?:avif|webp)$/ )[ 1 ] );
const binarySize = statSync( join( output, name ) ).size;
const expectedWidth = Number( name.match( /-(384|768|1536)\.(?:avif|webp)$/ )[ 1 ] );
const binaryLimit = expectedWidth === 1536 ? 260 * 1024 : 160 * 1024;
assert.ok( binarySize <= binaryLimit, `${ name } exceeds ${ binaryLimit } bytes: ${ binarySize } bytes` );
const dimensions = execFileSync( 'sips', [ '-g', 'pixelWidth', '-g', 'pixelHeight', join( output, name ) ], { encoding: 'utf8' } );
assert.match( dimensions, new RegExp( `pixelWidth: ${ expectedWidth }` ) );
assert.match( dimensions, /pixelHeight: [1-9][0-9]*/ );
@@ -223,14 +241,21 @@ test( 'all approved portraits rebuild byte-identically within payload bounds', (
if ( name.startsWith( 'alter-ego-gaming-half-body-' ) ) {
gamingHalfBodyTotal += generated.length;
}
if ( name.startsWith( 'podcast-frequency-grunge-' ) ) {
podcastTotal += generated.length;
}
}
}
assert.ok( collageTotal <= 400 * 1024, `collage derivatives exceed 400 KiB: ${ collageTotal }` );
assert.ok( collageTotal <= 400 * 1024, `collage family exceeds 400 KiB: ${ collageTotal } total bytes` );
assert.ok(
gamingHalfBodyTotal <= 340 * 1024,
`gaming half-body derivatives exceed 340 KiB: ${ gamingHalfBodyTotal }`,
`gaming half-body family exceeds 340 KiB: ${ gamingHalfBodyTotal } total bytes`,
);
assert.ok( total <= 2.4 * 1024 * 1024, `derivatives exceed 2.4 MiB: ${ total }` );
assert.ok(
podcastTotal <= 620 * 1024,
`podcast-frequency-grunge family exceeds 620 KiB: ${ podcastTotal } total bytes`,
);
assert.ok( total <= 2.75 * 1024 * 1024, `generated binary payload exceeds 2.75 MiB: ${ total } total bytes` );
} finally {
rmSync( output, { recursive: true, force: true } );
rmSync( external, { recursive: true, force: true } );
@@ -243,14 +268,14 @@ test( 'post-card CSS fallbacks never reuse approved section portraits', () => {
assert.doesNotMatch( components, /url\([^)]*(?:alter-ego-|the-no-names-musician-cutout)/ );
} );
test( 'podcast background source stays separate from portrait and card fallbacks', () => {
test( 'podcast background source uses fixed art and stays separate from card fallbacks', () => {
assert.ok(
existsSync( new URL( `../../${ PODCAST_BACKGROUND_SOURCE }`, import.meta.url ) ),
`missing ${ PODCAST_BACKGROUND_SOURCE }`,
);
const portraitAllowlist = read( 'inc/queries.php' );
assert.doesNotMatch( portraitAllowlist, /podcast-frequency-grunge\.png/ );
const artAllowlist = read( 'inc/queries.php' );
assert.match( artAllowlist, /'podcast-frequency'\s*=>\s*'podcast-frequency-grunge\.png'/ );
for ( const path of [
'assets/css/components.css',