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

+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 } );