fix: optimize CHRNX editorial media

This commit is contained in:
chrnx committed 2026-08-12 15:52:53 -05:00
1 parent 55e21bca81
commit c5720b21ca
14 files changed
+252 -46

No files matched your search

+5 -4
View File
@@ -83,11 +83,12 @@ responsive_output=$(mktemp -d "${TMPDIR:-/tmp}/chrnx-responsive.XXXXXX")
The rebuild rejects symlinks, nested paths, nonexistent paths, and destinations
outside the canonical system temporary directory. The automated smoke test
byte-compares all 35 outputs, validates their formats and dimensions, and
enforces 160 KiB per derivative and 1.7 MiB total payload bounds.
byte-compares all 40 outputs, validates their formats and dimensions, and
enforces 160 KiB per derivative, 400 KiB for the collage family, and a 2.1 MiB
total inventory bound.
The PNG masters remain unchanged. WordPress serves 384 px and 768 px AVIF or
WebP sources, with the PNG as a fallback.
The source masters remain unchanged. WordPress serves 384 px and 768 px AVIF or
WebP sources, with the original source as a fallback.
Capture the approved local review routes with Chromium:
+47 -11
View File
@@ -546,17 +546,30 @@ footer a {
color: #e6edf3;
}
.chrnx-home-music .wp-block-columns::before {
.chrnx-home-music__collage-layer {
position: absolute;
z-index: 0;
inset: 0;
background-image:
linear-gradient(90deg, rgb(13 17 23 / 62%), rgb(13 17 23 / 8%)),
url(../images/the-no-names-collage.jpeg);
background-position: center, 72% 42%;
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
pointer-events: none;
}
.chrnx-home-music__collage-layer::after {
position: absolute;
inset: 0;
background: linear-gradient(90deg, rgb(13 17 23 / 62%), rgb(13 17 23 / 8%));
content: "";
}
.chrnx-home-music__collage-layer .chrnx-responsive-portrait,
.chrnx-home-music__collage {
width: 100%;
height: 100%;
}
.chrnx-home-music__collage {
object-fit: cover;
object-position: 72% 42%;
filter: saturate(0.72) contrast(1.08);
opacity: 0.72;
}
@@ -583,6 +596,11 @@ html[data-theme="light"] .chrnx-home-music p {
}
.chrnx-home-music .wp-block-column:first-child {
z-index: 2;
}
.chrnx-home-music .wp-block-column:first-child > h2,
.chrnx-home-music .wp-block-column:first-child > p {
position: relative;
z-index: 2;
}
@@ -593,7 +611,7 @@ html[data-theme="light"] .chrnx-home-music p {
align-self: end;
}
.chrnx-home-music .chrnx-responsive-portrait {
.chrnx-home-music .wp-block-column:last-child .chrnx-responsive-portrait {
width: min(100%, 29rem);
margin: auto auto 0;
filter: drop-shadow(0 1.5rem 2rem rgb(0 0 0 / 42%));
@@ -632,6 +650,24 @@ html[data-theme="light"] .chrnx-home-music p {
padding: clamp(1.5rem, 4vw, 3rem);
}
@media (min-width: 781px) {
.chrnx-podcast-card__link {
display: grid;
grid-template-columns: minmax(15rem, 0.72fr) minmax(0, 1.28fr);
align-items: stretch;
padding: clamp(1.25rem, 2.5vw, 2rem);
}
.chrnx-podcast-card__image,
.chrnx-podcast-card__fallback {
height: 100%;
min-height: 15rem;
max-height: 19rem;
aspect-ratio: auto;
}
}
.chrnx-home-about-preview,
.chrnx-subscribe-cta {
display: grid;
@@ -974,12 +1010,12 @@ html[data-theme="light"] .chrnx-home-music p {
padding-block: 0;
}
.chrnx-home-music .wp-block-columns::before {
background-position: center, 60% center;
.chrnx-home-music__collage {
object-position: 60% center;
opacity: 0.56;
}
.chrnx-home-music .chrnx-responsive-portrait {
.chrnx-home-music .wp-block-column:last-child .chrnx-responsive-portrait {
width: min(82%, 20rem);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

@@ -0,0 +1,5 @@
{
"source": "the-no-names-collage.jpeg",
"formats": [ "avif", "webp" ],
"widths": [ 384, 768 ]
}
+3
View File
@@ -30,6 +30,9 @@ function chrnx_get_topic_portrait_markup( string $topic_slug, string $alt = '',
$decorative = '' === $alt ? ' aria-hidden="true"' : '';
$loading = 'eager' === $loading ? 'eager' : 'lazy';
$priority = 'eager' === $loading ? ' fetchpriority="high"' : '';
if ( 'music-collage' === $topic_slug ) {
$sizes = '(max-width: 599px) 100vw, 720px';
}
$markup = '<picture class="chrnx-responsive-portrait"' . $decorative . '>';
$markup .= '<source type="image/avif" srcset="' . esc_url( $base_uri . '-384.avif' ) . ' 384w, ' . esc_url( $base_uri . '-768.avif' ) . ' 768w" sizes="' . esc_attr( $sizes ) . '">';
+8 -7
View File
@@ -624,13 +624,14 @@ 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',
'podcasts' => 'alter-ego-podcasts.png',
'life' => 'alter-ego-life.png',
'gaming' => 'alter-ego-gaming.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',
'podcasts' => 'alter-ego-podcasts.png',
'life' => 'alter-ego-life.png',
'gaming' => 'alter-ego-gaming.png',
);
return isset( $mapping[ $topic_slug ] ) ? 'assets/images/' . $mapping[ $topic_slug ] : '';
}
+1
View File
@@ -14,6 +14,7 @@
<!-- wp:columns {"verticalAlignment":"center"} -->
<div class="wp-block-columns are-vertically-aligned-center">
<!-- wp:column {"verticalAlignment":"center"} --><div class="wp-block-column is-vertically-aligned-center">
<!-- wp:html --><span class="chrnx-home-music__collage-layer" aria-hidden="true"><?php echo chrnx_get_topic_portrait_markup( 'music-collage', '', 'chrnx-home-music__collage' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?></span><!-- /wp:html -->
<!-- wp:heading --><h2 class="wp-block-heading"><?php echo esc_html__( 'The No Names', 'chrnx' ); ?></h2><!-- /wp:heading -->
<!-- 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__( 'Un proyecto de banda activo hecho en Sinaloa: estudio crudo, cero live.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
+13 -7
View File
@@ -54,26 +54,32 @@ done
mkdir -p -- "$chrnx_image_output"
chrnx_build_portrait() {
chrnx_build_responsive_image() {
chrnx_image_basename=$1
chrnx_image_source="$chrnx_image_root/assets/images/$chrnx_image_basename.png"
chrnx_image_source_name=$2
chrnx_image_webp_quality=${3:-78}
chrnx_image_source="$chrnx_image_root/assets/images/$chrnx_image_source_name"
chrnx_image_source_extension=${chrnx_image_source_name##*.}
if [ ! -f "$chrnx_image_source" ]; then
echo "Source portrait is missing: $chrnx_image_source" >&2
echo "Source image is missing: $chrnx_image_source" >&2
exit 1
fi
for chrnx_image_width in 384 768; do
chrnx_image_resized="$chrnx_image_tmp/$chrnx_image_basename-$chrnx_image_width.png"
chrnx_image_resized="$chrnx_image_tmp/$chrnx_image_basename-$chrnx_image_width.$chrnx_image_source_extension"
sips --resampleWidth "$chrnx_image_width" "$chrnx_image_source" --out "$chrnx_image_resized" >/dev/null
cwebp -quiet -preset picture -q 78 -alpha_q 90 -m 6 -metadata none "$chrnx_image_resized" -o "$chrnx_image_output/$chrnx_image_basename-$chrnx_image_width.webp"
cwebp -quiet -preset picture -q "$chrnx_image_webp_quality" -alpha_q 90 -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 58 --qalpha 85 --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_portrait "alter-ego-$chrnx_image_topic"
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"
done
chrnx_build_portrait "the-no-names-musician-cutout"
chrnx_build_responsive_image "the-no-names-musician-cutout" "the-no-names-musician-cutout.png"
printf '{\n\t"source": "the-no-names-musician-cutout.png",\n\t"formats": [ "avif", "webp" ],\n\t"widths": [ 384, 768 ]\n}\n' > "$chrnx_image_output/the-no-names-musician-cutout.json"
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"
+131 -10
View File
@@ -123,8 +123,10 @@ test( 'lower home sections form compact, contained editorial panels in both them
const panelRects = panels.map( ( panel ) => panel.getBoundingClientRect() );
const journalRect = home.querySelector( '.chrnx-journal-stream' ).getBoundingClientRect();
const musicFrame = panels[ 1 ];
const collage = window.getComputedStyle( musicFrame, '::before' );
const collageLayer = musicFrame.querySelector( '.chrnx-home-music__collage-layer' );
const collage = collageLayer?.querySelector( '.chrnx-home-music__collage' );
const musician = musicFrame.querySelector( '.chrnx-home-music__art' );
const musicHeading = musicFrame.querySelector( 'h2' );
const projectPortraits = [
...panels[ 0 ].querySelectorAll( '.chrnx-section-portrait' ),
].filter( ( portrait ) => portrait.getClientRects().length > 0 );
@@ -151,13 +153,21 @@ test( 'lower home sections form compact, contained editorial panels in both them
isContained( portrait, panels[ 0 ] ),
),
projectsTreated: projectPortraits.every( isTreated ),
collageBackground: collage.backgroundImage,
collageContent: collage.content,
collageContained:
collage.position === 'absolute' &&
[ collage.inset, collage.top, collage.right, collage.bottom, collage.left ]
.join( ' ' )
.includes( '0px' ),
collageSources: collageLayer
? [ ...collageLayer.querySelectorAll( 'source' ) ].map( ( source ) => ( {
type: source.type,
srcset: source.srcset,
} ) )
: [],
collageLazy: collage?.loading,
collageFallback: collage?.getAttribute( 'src' ),
collageContained: Boolean( collageLayer && isContained( collageLayer, musicFrame ) ),
collageTreated: Boolean( collage && isTreated( collage ) ),
collageZIndex: collageLayer
? Number.parseInt( window.getComputedStyle( collageLayer ).zIndex, 10 )
: Number.NaN,
copyPosition: window.getComputedStyle( musicHeading ).position,
copyZIndex: Number.parseInt( window.getComputedStyle( musicHeading ).zIndex, 10 ),
musicianContained: isContained( musician, musicFrame ),
musicianTreated: isTreated( musician ),
};
@@ -176,9 +186,22 @@ test( 'lower home sections form compact, contained editorial panels in both them
).toBeTruthy();
expect( result.projectsContained ).toBeTruthy();
expect( result.projectsTreated ).toBeTruthy();
expect( result.collageBackground ).toContain( 'the-no-names-collage.jpeg' );
expect( result.collageContent ).not.toBe( 'none' );
expect( result.collageSources ).toEqual( [
expect.objectContaining( {
type: 'image/avif',
srcset: expect.stringContaining( 'the-no-names-collage-384.avif' ),
} ),
expect.objectContaining( {
type: 'image/webp',
srcset: expect.stringContaining( 'the-no-names-collage-384.webp' ),
} ),
] );
expect( result.collageLazy ).toBe( 'lazy' );
expect( result.collageFallback ).toContain( 'the-no-names-collage.jpeg' );
expect( result.collageContained ).toBeTruthy();
expect( result.collageTreated ).toBeTruthy();
expect( result.copyPosition ).not.toBe( 'static' );
expect( result.copyZIndex ).toBeGreaterThan( result.collageZIndex );
expect( result.musicianContained ).toBeTruthy();
expect( result.musicianTreated ).toBeTruthy();
await expectNoHorizontalOverflow( page );
@@ -186,12 +209,110 @@ test( 'lower home sections form compact, contained editorial panels in both them
}
} );
test( 'latest podcast is a compact horizontal panel on desktop', async ( { page } ) => {
await page.setViewportSize( { width: 1440, height: 900 } );
await page.goto( '/' );
const geometry = await page.locator( '.chrnx-latest-podcast' ).evaluate( ( panel ) => {
const link = panel.querySelector( '.chrnx-podcast-card__link' );
const media = panel.querySelector(
'.chrnx-podcast-card__image, .chrnx-podcast-card__fallback',
);
const content = panel.querySelector( '.chrnx-podcast-card__content' );
const panelRect = panel.getBoundingClientRect();
const mediaRect = media.getBoundingClientRect();
const contentRect = content.getBoundingClientRect();
return {
display: window.getComputedStyle( link ).display,
panelHeight: panelRect.height,
viewportHeight: window.innerHeight,
mediaHeight: mediaRect.height,
mediaRight: mediaRect.right,
contentLeft: contentRect.left,
};
} );
expect( geometry.display ).toBe( 'grid' );
expect( geometry.panelHeight ).toBeLessThanOrEqual( geometry.viewportHeight * 0.72 );
expect( geometry.mediaHeight ).toBeLessThanOrEqual( geometry.panelHeight * 0.72 );
expect( geometry.mediaRight ).toBeLessThanOrEqual( geometry.contentLeft + 1 );
} );
test( 'lower home panels survive missing media and reduced motion', async ( { page } ) => {
await page.emulateMedia( { reducedMotion: 'reduce' } );
await page.route( /\/assets\/images\//, ( route ) => route.abort() );
await page.setViewportSize( { width: 375, height: 812 } );
await page.goto( '/' );
const fallback = await page.locator( '.chrnx-podcast-card__fallback' ).evaluate( ( media ) => {
const card = media.closest( '.chrnx-podcast-card' );
const panel = media.closest( '.chrnx-latest-podcast' );
const mediaRect = media.getBoundingClientRect();
const cardRect = card.getBoundingClientRect();
const panelRect = panel.getBoundingClientRect();
const style = window.getComputedStyle( media );
return {
width: mediaRect.width,
height: mediaRect.height,
backgroundImage: style.backgroundImage,
inCard:
mediaRect.left >= cardRect.left - 1 &&
mediaRect.right <= cardRect.right + 1 &&
mediaRect.top >= cardRect.top - 1 &&
mediaRect.bottom <= cardRect.bottom + 1,
cardInPanel:
cardRect.left >= panelRect.left - 1 &&
cardRect.right <= panelRect.right + 1 &&
cardRect.top >= panelRect.top - 1 &&
cardRect.bottom <= panelRect.bottom + 1,
};
} );
expect( fallback.width ).toBeGreaterThan( 0 );
expect( fallback.height ).toBeGreaterThan( 0 );
expect( fallback.backgroundImage ).toMatch( /gradient/ );
expect( fallback.inCard ).toBeTruthy();
expect( fallback.cardInPanel ).toBeTruthy();
const musicFallback = await page
.locator( '.chrnx-home-music .wp-block-columns' )
.evaluate( ( frame ) => {
const layer = frame.querySelector( '.chrnx-home-music__collage-layer' );
const copy = frame.querySelector( '.wp-block-column:first-of-type' );
const frameRect = frame.getBoundingClientRect();
const copyRect = copy.getBoundingClientRect();
const layerRect = layer?.getBoundingClientRect();
return {
hasLayer: Boolean( layer ),
decorativeAlt: layer?.querySelector( 'img' )?.getAttribute( 'alt' ),
layerCoversFrame: Boolean(
layerRect &&
Math.abs( layerRect.left - frameRect.left ) <= 1 &&
Math.abs( layerRect.right - frameRect.right ) <= 1 &&
Math.abs( layerRect.top - frameRect.top ) <= 1 &&
Math.abs( layerRect.bottom - frameRect.bottom ) <= 1,
),
copyContained:
copyRect.left >= frameRect.left - 1 &&
copyRect.right <= frameRect.right + 1 &&
copyRect.top >= frameRect.top - 1 &&
copyRect.bottom <= frameRect.bottom + 1,
};
} );
expect( musicFallback.hasLayer ).toBeTruthy();
expect( musicFallback.decorativeAlt ).toBe( '' );
expect( musicFallback.layerCoversFrame ).toBeTruthy();
expect( musicFallback.copyContained ).toBeTruthy();
await expect( page.locator( '.chrnx-home-music h2' ) ).toContainText( 'The No Names' );
await expect( page.locator( '.chrnx-home-music p' ) ).toHaveCount( 2 );
await expect( page.locator( '.chrnx-home-projects h3' ) ).toHaveCount( 3 );
await expect( page.locator( '.chrnx-home-about-preview p' ) ).not.toBeEmpty();
await expect( page.locator( '.chrnx-subscribe-cta__link' ) ).toBeVisible();
for ( const selector of [
'.chrnx-home-projects',
'.chrnx-home-music .wp-block-columns',
+18
View File
@@ -78,6 +78,24 @@ class PatternsTest extends WP_UnitTestCase {
$this->assertStringContainsString( 'aria-hidden="true"', $show );
}
/** Home music layers a lazy responsive collage and musician in one frame. */
public function test_home_music_uses_responsive_decorative_collage_layer() {
$source = file_get_contents( get_theme_file_path( 'patterns/home-music.php' ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local test fixture.
$content = $this->render_pattern( get_theme_file_path( 'patterns/home-music.php' ) );
$this->assertStringContainsString( "chrnx_get_topic_portrait_markup( 'music-collage'", $source );
$this->assertStringContainsString( 'chrnx-home-music__collage-layer', $content );
$this->assertStringContainsString( 'the-no-names-collage-384.avif 384w', $content );
$this->assertStringContainsString( 'the-no-names-collage-768.webp 768w', $content );
$this->assertStringContainsString( 'sizes="(max-width: 599px) 100vw, 720px"', $content );
$this->assertMatchesRegularExpression( '/class="chrnx-home-music__collage"[^>]*loading="lazy"[^>]*alt=""/', $content );
$this->assertStringContainsString( 'the-no-names-musician-cutout.png', $content );
$this->assertLessThan(
strpos( $content, 'the-no-names-musician-cutout.png' ),
strpos( $content, 'the-no-names-collage-384.avif' )
);
}
/** Music copy contains only the exact approved public facts and release statuses. */
public function test_music_patterns_use_approved_honest_copy() {
$content = $this->render_pattern( get_theme_file_path( 'patterns/music-landing.php' ) );
+21 -7
View File
@@ -91,6 +91,7 @@ test( 'the page canvas is atmospheric rather than a repeating grid', () => {
test( 'lower home sections preserve editorial order and define layered panel treatments', () => {
const front = read( 'templates/front-page.html' );
const homeMusic = read( 'patterns/home-music.php' );
const components = read( 'assets/css/components.css' );
const orderedSections = [
'chrnx/home-projects',
@@ -107,13 +108,12 @@ test( 'lower home sections preserve editorial order and define layered panel tre
previousIndex = currentIndex;
}
assert.match( homeMusic, /chrnx_get_topic_portrait_markup\( 'music-collage'/ );
assert.match( homeMusic, /chrnx-home-music__collage-layer/ );
assert.doesNotMatch( components, /url\([^)]*the-no-names-collage\.jpeg/ );
assert.match(
components,
/\.chrnx-home-music \.wp-block-columns::before\s*\{[\s\S]*?the-no-names-collage\.jpeg/,
);
assert.match(
components,
/\.chrnx-home-music \.chrnx-responsive-portrait\s*\{[\s\S]*?(?:filter|box-shadow|mask(?:-image)?):/,
/\.chrnx-home-music \.wp-block-column:last-child \.chrnx-responsive-portrait\s*\{[\s\S]*?(?:filter|box-shadow|mask(?:-image)?):/,
);
for ( const selector of [
'.chrnx-home-projects',
@@ -146,8 +146,18 @@ 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, 35 );
assert.equal( names.length, 40 );
for ( const name of [
'the-no-names-collage-384.avif',
'the-no-names-collage-384.webp',
'the-no-names-collage-768.avif',
'the-no-names-collage-768.webp',
'the-no-names-collage.json',
] ) {
assert.ok( names.includes( name ), `missing ${ name }` );
}
let total = 0;
let collageTotal = 0;
for ( const name of names ) {
const generated = readFileSync( join( output, name ) );
const committed = readFileSync( new URL( `../../assets/images/generated/${ name }`, import.meta.url ) );
@@ -165,9 +175,13 @@ test( 'all approved portraits rebuild byte-identically within payload bounds', (
assert.equal( generated.subarray( 4, 12 ).toString(), 'ftypavif' );
}
total += generated.length;
if ( name.startsWith( 'the-no-names-collage-' ) ) {
collageTotal += generated.length;
}
}
}
assert.ok( total <= 1.7 * 1024 * 1024, `derivatives exceed 1.7 MiB: ${ total }` );
assert.ok( collageTotal <= 400 * 1024, `collage derivatives exceed 400 KiB: ${ collageTotal }` );
assert.ok( total <= 2.1 * 1024 * 1024, `derivatives exceed 2.1 MiB: ${ total }` );
} finally {
rmSync( output, { recursive: true, force: true } );
rmSync( external, { recursive: true, force: true } );