fix: read navigation from WordPress menus
The header and footer had five URLs hardcoded from the local fixtures. On a site whose pages are named differently, that is five 404s in the navigation, which is exactly what happened on chrnx.dev. Both now read an assigned menu and fall back to the built-in pages when no menu is set or the assigned one is empty. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2 files changed
+15
-25
No files matched your search
@@ -5,28 +5,7 @@
|
||||
* @package CHRNX
|
||||
*/
|
||||
|
||||
$chrnx_footer_links = array(
|
||||
array(
|
||||
'label' => __( 'Journal', 'chrnx' ),
|
||||
'url' => home_url( '/journal/' ),
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Projects', 'chrnx' ),
|
||||
'url' => home_url( '/projects/' ),
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Music', 'chrnx' ),
|
||||
'url' => home_url( '/music/' ),
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Podcasts', 'chrnx' ),
|
||||
'url' => home_url( '/podcasts/' ),
|
||||
),
|
||||
array(
|
||||
'label' => __( 'About', 'chrnx' ),
|
||||
'url' => home_url( '/about/' ),
|
||||
),
|
||||
);
|
||||
$chrnx_footer_links = chrnx_get_navigation_links( 'chrnx-footer' );
|
||||
$chrnx_site_name = get_bloginfo( 'name' );
|
||||
$chrnx_current_url = chrnx_get_current_navigation_destination();
|
||||
$chrnx_copyright = sprintf(
|
||||
|
||||
@@ -56,9 +56,14 @@ test('footer user-facing copy lives in an extractable PHP render block', async (
|
||||
const render = await readProjectFile('blocks/footer-content/render.php');
|
||||
assert.match(part, /<!-- wp:chrnx\/footer-content \/-->/);
|
||||
assert.doesNotMatch(part, /Made in Sinaloa|Journal|Footer navigation/);
|
||||
for (const text of ['Footer navigation', 'Journal', 'Projects', 'Music', 'Podcasts', 'About', 'Made in Sinaloa, shared from home.']) {
|
||||
const navHelper = await readProjectFile('inc/blocks.php');
|
||||
for (const text of ['Footer navigation', 'Made in Sinaloa, shared from home.']) {
|
||||
assert.ok(render.includes(`'${text}', 'chrnx'`), `${text} must use the chrnx text domain`);
|
||||
}
|
||||
// The link labels moved to the shared navigation helper, still translatable.
|
||||
for (const text of ['Journal', 'Projects', 'Music', 'Podcasts', 'About']) {
|
||||
assert.ok(navHelper.includes(`'${text}', 'chrnx'`), `${text} must use the chrnx text domain`);
|
||||
}
|
||||
});
|
||||
|
||||
test('header navigation and search copy lives in one extractable PHP render block', async () => {
|
||||
@@ -66,9 +71,15 @@ test('header navigation and search copy lives in one extractable PHP render bloc
|
||||
const render = await readProjectFile('blocks/header-tools/render.php');
|
||||
assert.match(part, /<!-- wp:chrnx\/header-tools \/-->/);
|
||||
assert.doesNotMatch(part, /wp:navigation|wp:navigation-link|wp:search|Journal|Primary navigation/);
|
||||
for (const text of ['Primary navigation', 'Journal', 'Projects', 'Music', 'Podcasts', 'About', 'Search', 'Open search']) {
|
||||
const navHelper = await readProjectFile('inc/blocks.php');
|
||||
for (const text of ['Primary navigation', 'Search', 'Open search']) {
|
||||
assert.ok(render.includes(`'${text}', 'chrnx'`), `${text} must use the chrnx text domain`);
|
||||
}
|
||||
assert.match(render, /home_url\( '\/journal\/' \)/);
|
||||
for (const text of ['Journal', 'Projects', 'Music', 'Podcasts', 'About']) {
|
||||
assert.ok(navHelper.includes(`'${text}', 'chrnx'`), `${text} must use the chrnx text domain`);
|
||||
}
|
||||
// The built-in destinations remain the fallback when no menu is assigned.
|
||||
assert.match(navHelper, /home_url\( '\/' \. \$slug \. '\/' \)/);
|
||||
assert.match(navHelper, /get_nav_menu_locations\(\)/);
|
||||
assert.match(render, /home_url\( '\/' \)/);
|
||||
});
|
||||
Reference in new issue
Block a user