feat: complete CHRNX responsive content states

This commit is contained in:
chrnx committed 2026-08-12 08:42:20 -05:00
1 parent 9385c1b9fb
commit 5073178492
60 files changed
+1699 -22

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
#!/bin/sh
set -eu
chrnx_image_script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
chrnx_image_root=$(dirname -- "$chrnx_image_script_dir")
chrnx_image_output="$chrnx_image_root/assets/images/generated"
chrnx_image_tmp=$(mktemp -d "${TMPDIR:-/tmp}/chrnx-images.XXXXXX")
trap 'rm -rf -- "$chrnx_image_tmp"' EXIT HUP INT TERM
for chrnx_image_tool in sips cwebp avifenc; do
if ! command -v "$chrnx_image_tool" >/dev/null 2>&1; then
echo "Required image tool is missing: $chrnx_image_tool" >&2
exit 1
fi
done
mkdir -p -- "$chrnx_image_output"
chrnx_build_portrait() {
chrnx_image_basename=$1
chrnx_image_source="$chrnx_image_root/assets/images/$chrnx_image_basename.png"
if [ ! -f "$chrnx_image_source" ]; then
echo "Source portrait 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"
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"
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"
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"
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"
+77
View File
@@ -0,0 +1,77 @@
import { mkdir } from 'node:fs/promises';
import { chromium } from '@playwright/test';
const baseURL = process.env.CHRNX_REVIEW_URL || 'http://localhost:8888';
const host = new URL(baseURL).hostname;
if (!['localhost', '127.0.0.1'].includes(host)) {
throw new Error('Visual review capture is restricted to local WordPress.');
}
const output = new URL('../tmp/imagegen/', import.meta.url);
await mkdir(output, { recursive: true });
const browser = await chromium.launch();
async function capture({ name, path, theme, viewport, fullPage = true }) {
const context = await browser.newContext({
viewport,
colorScheme: theme,
reducedMotion: 'reduce',
});
await context.addInitScript(
(preference) => localStorage.setItem('chrnx-theme', preference),
theme,
);
const page = await context.newPage();
await page.goto(new URL(path, baseURL).href, { waitUntil: 'networkidle' });
await page.addStyleTag({
content: '*,*::before,*::after{animation:none!important;transition:none!important}',
});
await page.evaluate(async () => {
await document.fonts.ready;
for (let y = 0; y <= document.documentElement.scrollHeight; y += window.innerHeight) {
window.scrollTo(0, y);
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
}
await Promise.race([
Promise.all(
[...document.images].map((image) =>
image.complete ? Promise.resolve() : image.decode().catch(() => {}),
),
),
new Promise((resolve) => setTimeout(resolve, 3000)),
]);
window.scrollTo(0, 0);
});
await page.screenshot({ path: new URL(`${name}.png`, output).pathname, fullPage });
console.log(
`${name}.png ${await page.evaluate(
() => `${document.documentElement.scrollWidth}x${document.documentElement.scrollHeight}`,
)}`,
);
await context.close();
}
const desktop = { width: 1440, height: 900 };
const mobile = { width: 375, height: 812 };
for (const spec of [
{ name: 'home-desktop-dark', path: '/', theme: 'dark', viewport: desktop },
{ name: 'home-desktop-light', path: '/', theme: 'light', viewport: desktop },
{ name: 'home-mobile-dark', path: '/', theme: 'dark', viewport: mobile },
{ name: 'home-mobile-light', path: '/', theme: 'light', viewport: mobile },
{ name: 'topic-code-desktop-dark', path: '/topic/code/', theme: 'dark', viewport: desktop },
{
name: 'topic-research-desktop-dark',
path: '/topic/research/',
theme: 'dark',
viewport: desktop,
},
{ name: 'topic-gaming-desktop-dark', path: '/topic/gaming/', theme: 'dark', viewport: desktop },
{ name: 'music-desktop-dark', path: '/music/', theme: 'dark', viewport: desktop },
{ name: 'podcasts-desktop-dark', path: '/podcasts/', theme: 'dark', viewport: desktop },
{ name: 'about-desktop-dark', path: '/about/', theme: 'dark', viewport: desktop },
]) {
await capture(spec);
}
await browser.close();
+152
View File
@@ -0,0 +1,152 @@
<?php
/**
* Seed deterministic, local-only visual review fixtures.
*
* Run through scripts/seed-test-content.sh, never against a public site.
*
* @package CHRNX
*/
$chrnx_seed_host = wp_parse_url( home_url( '/' ), PHP_URL_HOST );
if ( ! in_array( $chrnx_seed_host, array( 'localhost', '127.0.0.1' ), true ) ) {
WP_CLI::error( 'Refusing to seed a non-local WordPress site.' );
}
/**
* Read one fixture JSON document from the mapped theme.
*
* @param string $filename Fixture filename.
* @return array<int,array<string,mixed>> Fixture records.
*/
function chrnx_seed_read_fixture( string $filename ): array {
$path = get_theme_file_path( 'tests/fixtures/' . $filename );
if ( ! is_readable( $path ) ) {
WP_CLI::error( 'Fixture is not readable: ' . $filename );
}
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- This is a local mapped theme fixture, never a URL.
$data = json_decode( (string) file_get_contents( $path ), true );
if ( ! is_array( $data ) || ! array_is_list( $data ) ) {
WP_CLI::error( 'Fixture JSON is invalid: ' . $filename );
}
return $data;
}
/**
* Find the post managed by one stable fixture key.
*
* @param string $fixture_key Fixture key.
* @param string $post_type Post type.
* @return int Post ID or zero.
*/
function chrnx_seed_find_post( string $fixture_key, string $post_type ): int {
$ids = get_posts(
array(
'post_type' => $post_type,
'post_status' => 'any',
'posts_per_page' => 1,
'fields' => 'ids',
'no_found_rows' => true,
'suppress_filters' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
'meta_key' => '_chrnx_fixture_key',
'meta_value' => $fixture_key,
)
);
return empty( $ids ) ? 0 : absint( $ids[0] );
}
/**
* Insert or update one fixture-owned post without touching unrelated content.
*
* @param array<string,mixed> $fixture Fixture record.
* @param string $post_type Post type.
* @param int $offset Stable publication-date offset.
* @return int Post ID.
*/
function chrnx_seed_upsert_post( array $fixture, string $post_type, int $offset ): int {
$key = isset( $fixture['fixtureKey'] ) ? sanitize_key( $fixture['fixtureKey'] ) : '';
if ( '' === $key ) {
WP_CLI::error( 'Every fixture requires a fixtureKey.' );
}
$post_id = chrnx_seed_find_post( $key, $post_type );
$payload = array(
'ID' => $post_id,
'post_type' => $post_type,
'post_status' => sanitize_key( $fixture['status'] ?? 'publish' ),
'post_title' => sanitize_text_field( $fixture['title'] ?? '' ),
'post_name' => sanitize_title( $fixture['slug'] ?? $fixture['title'] ?? $key ),
'post_excerpt' => wp_kses_post( $fixture['excerpt'] ?? '' ),
'post_content' => wp_kses_post( $fixture['content'] ?? '' ),
'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '2026-08-01 18:00:00 UTC' ) + ( $offset * HOUR_IN_SECONDS ) ),
);
$result = $post_id ? wp_update_post( $payload, true ) : wp_insert_post( $payload, true );
if ( is_wp_error( $result ) ) {
WP_CLI::error( 'Could not upsert fixture ' . $key . '.' );
}
update_post_meta( $result, '_chrnx_fixture_key', $key );
return absint( $result );
}
chrnx_seed_editorial_terms();
$chrnx_seed_pages = chrnx_seed_read_fixture( 'pages.json' );
$chrnx_seed_posts = chrnx_seed_read_fixture( 'posts.json' );
$chrnx_seed_page_ids = array();
$chrnx_seed_post_ids = array();
foreach ( $chrnx_seed_pages as $chrnx_seed_index => $chrnx_seed_page ) {
$chrnx_seed_page_id = chrnx_seed_upsert_post( $chrnx_seed_page, 'page', $chrnx_seed_index );
$chrnx_seed_page_ids[ $chrnx_seed_page['slug'] ] = $chrnx_seed_page_id;
}
foreach ( $chrnx_seed_posts as $chrnx_seed_index => $chrnx_seed_post ) {
$chrnx_seed_post_id = chrnx_seed_upsert_post( $chrnx_seed_post, 'post', 24 + $chrnx_seed_index );
wp_set_object_terms( $chrnx_seed_post_id, sanitize_key( $chrnx_seed_post['topic'] ?? '' ), 'chrnx_topic', false );
wp_set_object_terms( $chrnx_seed_post_id, sanitize_key( $chrnx_seed_post['language'] ?? '' ), 'chrnx_language', false );
if ( isset( $chrnx_seed_post['show'] ) ) {
wp_set_object_terms( $chrnx_seed_post_id, sanitize_key( $chrnx_seed_post['show'] ), 'chrnx_show', false );
} else {
wp_set_object_terms( $chrnx_seed_post_id, array(), 'chrnx_show', false );
}
foreach ( array( 'chrnx_episode_number', 'chrnx_episode_duration' ) as $chrnx_seed_meta_key ) {
delete_post_meta( $chrnx_seed_post_id, $chrnx_seed_meta_key );
}
if ( isset( $chrnx_seed_post['episodeNumber'] ) ) {
update_post_meta( $chrnx_seed_post_id, 'chrnx_episode_number', absint( $chrnx_seed_post['episodeNumber'] ) );
}
if ( isset( $chrnx_seed_post['episodeDuration'] ) ) {
update_post_meta( $chrnx_seed_post_id, 'chrnx_episode_duration', chrnx_sanitize_episode_duration( $chrnx_seed_post['episodeDuration'] ) );
}
$chrnx_seed_post_ids[ $chrnx_seed_post['fixtureKey'] ] = $chrnx_seed_post_id;
}
$chrnx_seed_sticky_ids = array();
foreach ( $chrnx_seed_posts as $chrnx_seed_post ) {
if ( ! empty( $chrnx_seed_post['featured'] ) && isset( $chrnx_seed_post_ids[ $chrnx_seed_post['fixtureKey'] ] ) ) {
$chrnx_seed_sticky_ids[] = $chrnx_seed_post_ids[ $chrnx_seed_post['fixtureKey'] ];
}
}
update_option( 'sticky_posts', $chrnx_seed_sticky_ids );
update_option( 'blogname', 'CHRNX' );
update_option( 'blogdescription', 'Ideas made tangible.' );
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $chrnx_seed_page_ids['home'] );
update_option( 'page_for_posts', 0 );
update_option( 'chrnx_subscribe_page_id', $chrnx_seed_page_ids['subscribe'] );
update_option( 'permalink_structure', '/%postname%/' );
flush_rewrite_rules( false );
WP_CLI::log(
sprintf(
'CHRNX_FIXTURES pages=%d posts=%d front=%d',
count( $chrnx_seed_page_ids ),
count( $chrnx_seed_post_ids ),
$chrnx_seed_page_ids['home']
)
);
+22
View File
@@ -0,0 +1,22 @@
#!/bin/sh
set -eu
chrnx_script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
chrnx_project_dir=$(dirname -- "$chrnx_script_dir")
chrnx_docker_cli_dir=${CHRNX_DOCKER_CLI_DIR:-/opt/homebrew/opt/docker/bin}
if [ ! -x "$chrnx_docker_cli_dir/docker" ]; then
echo "Docker CLI not found at the approved Colima path: $chrnx_docker_cli_dir/docker" >&2
exit 1
fi
cd -- "$chrnx_project_dir"
chrnx_seed_probe=$(PATH="$chrnx_docker_cli_dir:$PATH" npm exec -- wp-env run cli wp eval 'echo "CHRNX_HOST=" . wp_parse_url( home_url( "/" ), PHP_URL_HOST );')
case "$chrnx_seed_probe" in
*CHRNX_HOST=localhost*|*CHRNX_HOST=127.0.0.1*) ;;
*)
echo "Refusing to seed anything except localhost or 127.0.0.1." >&2
exit 1
;;
esac
PATH="$chrnx_docker_cli_dir:$PATH" npm exec -- wp-env run cli wp eval-file wp-content/themes/chrnx/scripts/seed-test-content.php