Merge branch 'fix/document-language'
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
26 files changed
+157
-24
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
|
||||
"core": "https://wordpress.org/wordpress-6.9.6.zip",
|
||||
"core": "https://wordpress.org/wordpress-7.0.4.zip",
|
||||
"phpVersion": "8.3",
|
||||
"autoPort": false,
|
||||
"port": 8888,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/featured-stories",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Featured Stories",
|
||||
"category": "theme",
|
||||
"description": "A sticky-led selection of topic-diverse stories.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/footer-content",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "CHRNX Footer Content",
|
||||
"category": "theme",
|
||||
"description": "Display translated internal footer navigation and site credit.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/header-tools",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "CHRNX Header Tools",
|
||||
"category": "theme",
|
||||
"description": "Display translated primary navigation and progressive site search.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/journal-link",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Journal Link",
|
||||
"category": "theme",
|
||||
"description": "Display a translated portable link to the full Journal.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/journal-stream",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Journal Stream",
|
||||
"category": "theme",
|
||||
"description": "The filterable chronological journal.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/latest-podcast",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Latest Podcast",
|
||||
"category": "theme",
|
||||
"description": "A linked card for the latest podcast episode.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/mobile-menu-toggle",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "CHRNX Mobile Menu Toggle",
|
||||
"category": "theme",
|
||||
"description": "Progressively reveal the primary navigation on small screens.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/podcast-meta",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Podcast Metadata",
|
||||
"category": "theme",
|
||||
"description": "Safe episode details for the current post.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/reading-time",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Reading Time",
|
||||
"category": "theme",
|
||||
"description": "Display a localized estimate based on the current post content.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/related-posts",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Related Posts",
|
||||
"category": "theme",
|
||||
"description": "Related stories selected by topic, tags, and recency.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/release-detail",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Release Detail",
|
||||
"category": "theme",
|
||||
"description": "Album cover, listening links, and the ordered tracklist.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/release-list",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Release List",
|
||||
"category": "theme",
|
||||
"description": "The No Names releases, each linking to its album page.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/selected-work",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Selected Work",
|
||||
"category": "theme",
|
||||
"description": "Hand-picked projects first, then the most recent ones.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/show-links",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Show Links",
|
||||
"category": "theme",
|
||||
"description": "Where a podcast show can be listened to, rendered only when a URL exists.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/site-brand",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "CHRNX Site Brand",
|
||||
"category": "theme",
|
||||
"description": "Display the local CHRNX wordmark linked to the site home.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/subscribe-cta",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Subscribe CTA",
|
||||
"category": "theme",
|
||||
"description": "A call to action linked to the configured subscribe page.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/subscribe-form",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Subscribe Form",
|
||||
"category": "theme",
|
||||
"description": "The email subscription form, rendered only when a provider endpoint is configured.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/theme-toggle",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Theme Toggle",
|
||||
"category": "theme",
|
||||
"description": "Choose a light, dark, or system color theme.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/topic-hero",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Topic Hero",
|
||||
"category": "theme",
|
||||
"description": "A fixed-art hero for an editorial topic.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/track-meta",
|
||||
"version": "0.4.3",
|
||||
"version": "0.4.4",
|
||||
"title": "Track Meta",
|
||||
"category": "theme",
|
||||
"description": "Player, listening links, and album for one song.",
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
define( 'CHRNX_VERSION', '0.4.3' );
|
||||
define( 'CHRNX_VERSION', '0.4.4' );
|
||||
|
||||
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||
foreach ( array( 'setup', 'assets', 'taxonomies', 'editor', 'podcast-meta', 'project-meta', 'release-meta', 'show-meta', 'track-meta', 'settings', 'queries', 'media', 'blocks', 'theme-preference' ) as $module ) {
|
||||
|
||||
@@ -32,6 +32,62 @@ function chrnx_setup() {
|
||||
add_action( 'after_setup_theme', 'chrnx_setup' );
|
||||
add_filter( 'comments_open', '__return_false' );
|
||||
|
||||
/*
|
||||
* Nothing collects comments, so the head must not advertise a feed for them.
|
||||
* This one filter covers both the site-wide feed printed by feed_links() and
|
||||
* the per-post one from feed_links_extra(), which still fired on old posts
|
||||
* carrying a non-zero comment_count. Topic, author and search feeds stay.
|
||||
*/
|
||||
add_filter( 'feed_links_show_comments_feed', '__return_false' );
|
||||
|
||||
/**
|
||||
* Resolve the document language from the editorial language taxonomy.
|
||||
*
|
||||
* Roughly half the journal is written in Spanish while every route declared
|
||||
* en-US, so screen readers read Spanish with English phonetics and crawlers
|
||||
* indexed those posts as English. chrnx_language already records the answer.
|
||||
*
|
||||
* @return string BCP 47 tag, or an empty string to keep the site language.
|
||||
*/
|
||||
function chrnx_get_document_locale(): string {
|
||||
// ponytail: explicit map, a third language is one more line here.
|
||||
$locales = array(
|
||||
'en' => 'en-US',
|
||||
'es' => 'es-MX',
|
||||
);
|
||||
|
||||
$slug = '';
|
||||
|
||||
if ( is_singular( 'post' ) ) {
|
||||
// A post carries one language; extra terms are an editing mistake.
|
||||
$terms = get_the_terms( get_queried_object_id(), 'chrnx_language' );
|
||||
$slug = ( is_array( $terms ) && isset( $terms[0]->slug ) ) ? $terms[0]->slug : '';
|
||||
} elseif ( is_tax( 'chrnx_language' ) ) {
|
||||
$term = get_queried_object();
|
||||
$slug = $term instanceof WP_Term ? $term->slug : '';
|
||||
}
|
||||
|
||||
return $locales[ $slug ] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the editorial language to the html element.
|
||||
*
|
||||
* @param string $output Attribute string built by core.
|
||||
* @return string Attribute string carrying the editorial language.
|
||||
*/
|
||||
function chrnx_filter_language_attributes( $output ) {
|
||||
$locale = chrnx_get_document_locale();
|
||||
|
||||
if ( '' === $locale ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Replace only the language, so dir and any plugin attribute survive.
|
||||
return preg_replace( '/lang="[^"]*"/', 'lang="' . esc_attr( $locale ) . '"', (string) $output, 1 );
|
||||
}
|
||||
add_filter( 'language_attributes', 'chrnx_filter_language_attributes' );
|
||||
|
||||
/**
|
||||
* Print Open Graph and Twitter card tags only when nothing else does.
|
||||
*
|
||||
|
||||
@@ -3,6 +3,6 @@ Theme Name: CHRNX
|
||||
Description: A native block theme for chrnx.dev.
|
||||
Requires at least: 6.9
|
||||
Requires PHP: 8.1
|
||||
Version: 0.4.3
|
||||
Version: 0.4.4
|
||||
Text Domain: chrnx
|
||||
*/
|
||||
@@ -37,6 +37,83 @@ class ThemeSetupTest extends WP_UnitTestCase {
|
||||
$this->assertContains( 'assets/css/components.css', $editor_styles );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure a Spanish post declares a Spanish document language.
|
||||
*/
|
||||
public function test_language_attributes_follow_a_spanish_post() {
|
||||
$post_id = self::factory()->post->create();
|
||||
wp_set_object_terms( $post_id, 'es', 'chrnx_language' );
|
||||
|
||||
$this->go_to( get_permalink( $post_id ) );
|
||||
|
||||
$this->assertTrue( is_singular( 'post' ) );
|
||||
$this->assertSame( 'lang="es-MX"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure an English post keeps the English document language.
|
||||
*/
|
||||
public function test_language_attributes_follow_an_english_post() {
|
||||
$post_id = self::factory()->post->create();
|
||||
wp_set_object_terms( $post_id, 'en', 'chrnx_language' );
|
||||
|
||||
$this->go_to( get_permalink( $post_id ) );
|
||||
|
||||
$this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the direction attribute survives the language swap.
|
||||
*/
|
||||
public function test_language_attributes_preserve_other_attributes() {
|
||||
$post_id = self::factory()->post->create();
|
||||
wp_set_object_terms( $post_id, 'es', 'chrnx_language' );
|
||||
|
||||
$this->go_to( get_permalink( $post_id ) );
|
||||
|
||||
$this->assertSame( 'lang="es-MX" dir="ltr"', chrnx_filter_language_attributes( 'lang="en-US" dir="ltr"' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure a post without a language term is left untouched.
|
||||
*/
|
||||
public function test_language_attributes_ignore_a_post_without_a_language() {
|
||||
$post_id = self::factory()->post->create();
|
||||
|
||||
$this->go_to( get_permalink( $post_id ) );
|
||||
|
||||
$this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure a language archive declares the language it lists.
|
||||
*/
|
||||
public function test_language_attributes_follow_a_language_archive() {
|
||||
$post_id = self::factory()->post->create();
|
||||
wp_set_object_terms( $post_id, 'es', 'chrnx_language' );
|
||||
|
||||
$this->go_to( get_term_link( 'es', 'chrnx_language' ) );
|
||||
|
||||
$this->assertTrue( is_tax( 'chrnx_language' ) );
|
||||
$this->assertSame( 'lang="es-MX"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the home page keeps the site language.
|
||||
*/
|
||||
public function test_language_attributes_leave_the_home_page_alone() {
|
||||
$this->go_to( home_url( '/' ) );
|
||||
|
||||
$this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the head never advertises a comments feed the theme cannot render.
|
||||
*/
|
||||
public function test_comments_feed_is_not_advertised() {
|
||||
$this->assertFalse( apply_filters( 'feed_links_show_comments_feed', true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the local base stylesheet is enqueued with the theme version.
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@ test('tooling is pinned and wp-env maps this repo as chrnx', async () => {
|
||||
assert.equal(pkg.devDependencies['@wordpress/scripts'], '34.0.0');
|
||||
assert.equal(pkg.devDependencies['@playwright/test'], '1.62.1');
|
||||
assert.equal(pkg.devDependencies.lighthouse, '13.4.1');
|
||||
assert.equal(env.core, 'https://wordpress.org/wordpress-6.9.6.zip');
|
||||
assert.equal(env.core, 'https://wordpress.org/wordpress-7.0.4.zip');
|
||||
assert.equal(env.phpVersion, '8.3');
|
||||
assert.equal(env.autoPort, false);
|
||||
assert.equal(env.port, 8888);
|
||||
|
||||
Reference in new issue
Block a user