diff --git a/README.md b/README.md index 41a8622..4280327 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ 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 76 generated files: 62 binary derivatives and 14 manifests. +byte-compares all 81 generated files: 66 binary derivatives and 15 manifests. The inventory has eleven portrait families at 384 px and 768 px, plus three landscape background families (Podcast, About, and Projects) at 384 px, 768 px, and 1536 px. Every 384/768 derivative is diff --git a/assets/css/components.css b/assets/css/components.css index 0a797d0..0f28a4b 100644 --- a/assets/css/components.css +++ b/assets/css/components.css @@ -267,7 +267,8 @@ footer a { .chrnx-journal-card, .chrnx-podcast-card, .chrnx-related-card, -.chrnx-release-card { +.chrnx-release-card, +.chrnx-project-card { position: relative; overflow: hidden; border: 1px solid var(--chrnx-line); @@ -342,7 +343,9 @@ footer a { .chrnx-podcast-card__link > .chrnx-responsive-portrait, .chrnx-related-card__link > .chrnx-responsive-portrait, .chrnx-release-card__art > .chrnx-responsive-portrait, -.chrnx-release-detail__art > .chrnx-responsive-portrait { +.chrnx-release-detail__art > .chrnx-responsive-portrait, +.chrnx-project-card__art > .chrnx-responsive-portrait, +.chrnx-project-detail__art > .chrnx-responsive-portrait { display: block; width: 100%; height: 100%; @@ -538,40 +541,6 @@ footer a { position: relative; } -.chrnx-selected-work__list { - display: grid; - gap: 0; - grid-template-columns: 1fr; - margin: 0; - padding: 0; - border-top: 1px solid var(--chrnx-line); - list-style: none; -} - -.chrnx-selected-work__item { - padding-block: 1.25rem; - border-bottom: 1px solid var(--chrnx-line); -} - -.chrnx-selected-work__title { - margin: 0; - overflow-wrap: anywhere; -} - -.chrnx-selected-work__title a { - color: inherit; - text-decoration: none; -} - -.chrnx-selected-work__title a:hover { - text-decoration: underline; -} - -.chrnx-selected-work__empty { - margin: 0; - color: var(--chrnx-muted); -} - .chrnx-responsive-portrait { display: block; } @@ -876,14 +845,16 @@ html[data-theme="light"] .chrnx-home-music p { pointer-events: none; } -.chrnx-release-list { +.chrnx-release-list, +.chrnx-project-list { display: grid; gap: 1rem; grid-template-columns: repeat(3, minmax(0, 1fr)); } /* Grunge release cards: torn light, heavy rule, dirt in the corners. */ -.chrnx-release-card { +.chrnx-release-card, +.chrnx-project-card { position: relative; isolation: isolate; overflow: hidden; @@ -899,7 +870,8 @@ html[data-theme="light"] .chrnx-home-music p { transition: transform 160ms ease, border-color 160ms ease; } -.chrnx-release-card::after { +.chrnx-release-card::after, +.chrnx-project-card::after { position: absolute; z-index: -1; inset: 0; @@ -909,18 +881,21 @@ html[data-theme="light"] .chrnx-home-music p { pointer-events: none; } -.chrnx-release-card:hover { +.chrnx-release-card:hover, +.chrnx-project-card:hover { border-top-color: var(--chrnx-green); transform: translateY(-3px); } -.chrnx-release-card__link { +.chrnx-release-card__link, +.chrnx-project-card__link { display: block; color: inherit; text-decoration: none; } -.chrnx-release-card__art { +.chrnx-release-card__art, +.chrnx-project-card__art { display: block; overflow: hidden; margin-bottom: 1rem; @@ -930,7 +905,9 @@ html[data-theme="light"] .chrnx-home-music p { } .chrnx-release-card__cover, -.chrnx-release-card__fallback { +.chrnx-release-card__fallback, +.chrnx-project-card__cover, +.chrnx-project-card__fallback { display: block; width: 100%; height: 100%; @@ -938,7 +915,9 @@ html[data-theme="light"] .chrnx-home-music p { } .chrnx-release-card__fallback, -.chrnx-release-detail__fallback { +.chrnx-release-detail__fallback, +.chrnx-project-card__fallback, +.chrnx-project-detail__fallback { background-color: var(--chrnx-surface); background-image: linear-gradient(132deg, transparent 0 46%, color-mix(in srgb, var(--chrnx-accent) 42%, transparent) 47% 50%, transparent 51%), @@ -946,17 +925,21 @@ html[data-theme="light"] .chrnx-home-music p { radial-gradient(circle at 70% 28%, color-mix(in srgb, var(--chrnx-accent) 34%, transparent), transparent 52%); } -.chrnx-release-card__title { +.chrnx-release-card__title, +.chrnx-project-card__title { margin: 0 0 0.4rem; text-wrap: balance; } -.chrnx-release-card__link:hover .chrnx-release-card__title { +.chrnx-release-card__link:hover .chrnx-release-card__title, +.chrnx-project-card__link:hover .chrnx-project-card__title { color: var(--chrnx-green); } .chrnx-release-card__status, -.chrnx-release-detail__status { +.chrnx-release-detail__status, +.chrnx-project-card__status, +.chrnx-project-detail__status { margin: 0; color: var(--chrnx-muted); font-family: var(--wp--preset--font-family--metadata); @@ -992,7 +975,8 @@ html[data-theme="light"] .chrnx-home-music p { } /* Album page. */ -.chrnx-release-detail__head { +.chrnx-release-detail__head, +.chrnx-project-detail__head { display: grid; gap: clamp(1.5rem, 4vw, 3rem); grid-template-columns: minmax(0, 20rem) minmax(0, 1fr); @@ -1000,11 +984,13 @@ html[data-theme="light"] .chrnx-home-music p { margin-bottom: clamp(2rem, 5vw, 3.5rem); } -.chrnx-release-detail__head.is-bare { +.chrnx-release-detail__head.is-bare, +.chrnx-project-detail__head.is-bare { grid-template-columns: minmax(0, 22rem); } -.chrnx-release-detail__art { +.chrnx-release-detail__art, +.chrnx-project-detail__art { position: relative; overflow: hidden; border: 1px solid color-mix(in srgb, var(--chrnx-accent) 34%, var(--chrnx-line)); @@ -1014,14 +1000,22 @@ html[data-theme="light"] .chrnx-home-music p { } .chrnx-release-detail__cover, -.chrnx-release-detail__fallback { +.chrnx-release-detail__fallback, +.chrnx-project-detail__cover, +.chrnx-project-detail__fallback { display: block; width: 100%; height: 100%; object-fit: cover; } -.chrnx-release-detail__description { +.chrnx-release-detail__intro, +.chrnx-project-detail__intro { + min-width: 0; +} + +.chrnx-release-detail__description, +.chrnx-project-detail__description { margin: 0.75rem 0 0; color: var(--chrnx-text); } @@ -1134,6 +1128,7 @@ html[data-theme="light"] .chrnx-home-music p { @media (max-width: 720px) { .chrnx-release-detail__head, + .chrnx-project-detail__head, .chrnx-track-meta { grid-template-columns: minmax(0, 1fr); } @@ -1215,7 +1210,8 @@ html[data-theme="light"] .chrnx-home-music p { @media (max-width: 900px) { .chrnx-journal-stream__list, - .chrnx-release-list { + .chrnx-release-list, + .chrnx-project-list { grid-template-columns: 1fr; } diff --git a/assets/images/generated/placeholder-project-384.avif b/assets/images/generated/placeholder-project-384.avif new file mode 100644 index 0000000..40d8d80 Binary files /dev/null and b/assets/images/generated/placeholder-project-384.avif differ diff --git a/assets/images/generated/placeholder-project-384.webp b/assets/images/generated/placeholder-project-384.webp new file mode 100644 index 0000000..3721cb0 Binary files /dev/null and b/assets/images/generated/placeholder-project-384.webp differ diff --git a/assets/images/generated/placeholder-project-768.avif b/assets/images/generated/placeholder-project-768.avif new file mode 100644 index 0000000..1c2bf4c Binary files /dev/null and b/assets/images/generated/placeholder-project-768.avif differ diff --git a/assets/images/generated/placeholder-project-768.webp b/assets/images/generated/placeholder-project-768.webp new file mode 100644 index 0000000..d277463 Binary files /dev/null and b/assets/images/generated/placeholder-project-768.webp differ diff --git a/assets/images/generated/placeholder-project.json b/assets/images/generated/placeholder-project.json new file mode 100644 index 0000000..093f7a5 --- /dev/null +++ b/assets/images/generated/placeholder-project.json @@ -0,0 +1,5 @@ +{ + "source": "placeholder-project.png", + "formats": [ "avif", "webp" ], + "widths": [ 384, 768 ] +} diff --git a/assets/images/placeholder-project.png b/assets/images/placeholder-project.png new file mode 100644 index 0000000..9b8944a Binary files /dev/null and b/assets/images/placeholder-project.png differ diff --git a/assets/js/editor-project.js b/assets/js/editor-project.js deleted file mode 100644 index fb14215..0000000 --- a/assets/js/editor-project.js +++ /dev/null @@ -1,111 +0,0 @@ -( function ( factory ) { - if ( typeof module === 'object' && module.exports ) { - module.exports = factory(); - } else { - factory().initialize( window.wp ); - } -} )( function () { - 'use strict'; - - function getTranslator( wp ) { - return wp.i18n && typeof wp.i18n.__ === 'function' - ? wp.i18n.__ - : function ( text ) { - return text; - }; - } - - function updateMeta( editPost, currentMeta, key, value ) { - if ( typeof editPost !== 'function' ) { - return; - } - - editPost( { meta: { ...( currentMeta || {} ), [ key ]: value } } ); - } - - function hasRequiredGlobals( wp ) { - return Boolean( - wp && - wp.components && - wp.components.ToggleControl && - wp.data && - typeof wp.data.useDispatch === 'function' && - typeof wp.data.useSelect === 'function' && - wp.editPost && - wp.editPost.PluginDocumentSettingPanel && - wp.element && - typeof wp.element.createElement === 'function' && - wp.plugins && - typeof wp.plugins.registerPlugin === 'function', - ); - } - - function initialize( wp ) { - if ( ! hasRequiredGlobals( wp ) ) { - return false; - } - - const __ = getTranslator( wp ); - - function ProjectPanel() { - const editorState = wp.data.useSelect( function ( select ) { - if ( typeof select !== 'function' ) { - return null; - } - - const currentEditor = select( 'core/editor' ); - const core = select( 'core' ); - if ( - ! currentEditor || - typeof currentEditor.getCurrentPostType !== 'function' || - typeof currentEditor.getEditedPostAttribute !== 'function' || - ! core || - typeof core.getEntityRecord !== 'function' - ) { - return null; - } - - const topicIds = currentEditor.getEditedPostAttribute( 'topic' ); - return { - meta: currentEditor.getEditedPostAttribute( 'meta' ) || {}, - postType: currentEditor.getCurrentPostType(), - topic: - Array.isArray( topicIds ) && topicIds.length === 1 - ? core.getEntityRecord( 'taxonomy', 'chrnx_topic', topicIds[ 0 ] ) - : null, - }; - }, [] ); - const editorDispatch = wp.data.useDispatch( 'core/editor' ); - if ( ! editorState || editorState.postType !== 'post' || ! editorDispatch?.editPost ) { - return null; - } - - if ( ! editorState.topic || editorState.topic.slug !== 'projects' ) { - return null; - } - - const meta = editorState.meta; - - return wp.element.createElement( - wp.editPost.PluginDocumentSettingPanel, - { name: 'chrnx-project', title: __( 'Project', 'chrnx' ) }, - wp.element.createElement( wp.components.ToggleControl, { - label: __( 'Show in Selected work', 'chrnx' ), - help: __( - 'Selected work lists these first, then fills the rest with the most recent projects.', - 'chrnx', - ), - checked: Boolean( meta.chrnx_project_featured ), - onChange( value ) { - updateMeta( editorDispatch.editPost, meta, 'chrnx_project_featured', Boolean( value ) ); - }, - } ), - ); - } - - wp.plugins.registerPlugin( 'chrnx-project-meta', { render: ProjectPanel } ); - return true; - } - - return { initialize, updateMeta }; -} ); diff --git a/blocks/featured-stories/block.json b/blocks/featured-stories/block.json index b38c9a5..724decf 100644 --- a/blocks/featured-stories/block.json +++ b/blocks/featured-stories/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/featured-stories", - "version": "0.4.4", + "version": "0.4.5", "title": "Featured Stories", "category": "theme", "description": "A sticky-led selection of topic-diverse stories.", diff --git a/blocks/footer-content/block.json b/blocks/footer-content/block.json index d7cc2db..80847c9 100644 --- a/blocks/footer-content/block.json +++ b/blocks/footer-content/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/footer-content", - "version": "0.4.4", + "version": "0.4.5", "title": "CHRNX Footer Content", "category": "theme", "description": "Display translated internal footer navigation and site credit.", diff --git a/blocks/header-tools/block.json b/blocks/header-tools/block.json index 46bda30..1f981b3 100644 --- a/blocks/header-tools/block.json +++ b/blocks/header-tools/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/header-tools", - "version": "0.4.4", + "version": "0.4.5", "title": "CHRNX Header Tools", "category": "theme", "description": "Display translated primary navigation and progressive site search.", diff --git a/blocks/journal-link/block.json b/blocks/journal-link/block.json index 64c4f9c..d52d98e 100644 --- a/blocks/journal-link/block.json +++ b/blocks/journal-link/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/journal-link", - "version": "0.4.4", + "version": "0.4.5", "title": "Journal Link", "category": "theme", "description": "Display a translated portable link to the full Journal.", diff --git a/blocks/journal-stream/block.json b/blocks/journal-stream/block.json index 7c2f728..6b7f6a3 100644 --- a/blocks/journal-stream/block.json +++ b/blocks/journal-stream/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/journal-stream", - "version": "0.4.4", + "version": "0.4.5", "title": "Journal Stream", "category": "theme", "description": "The filterable chronological journal.", diff --git a/blocks/latest-podcast/block.json b/blocks/latest-podcast/block.json index aa67bd1..99447d9 100644 --- a/blocks/latest-podcast/block.json +++ b/blocks/latest-podcast/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/latest-podcast", - "version": "0.4.4", + "version": "0.4.5", "title": "Latest Podcast", "category": "theme", "description": "A linked card for the latest podcast episode.", diff --git a/blocks/mobile-menu-toggle/block.json b/blocks/mobile-menu-toggle/block.json index e5c6e30..d4d8375 100644 --- a/blocks/mobile-menu-toggle/block.json +++ b/blocks/mobile-menu-toggle/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/mobile-menu-toggle", - "version": "0.4.4", + "version": "0.4.5", "title": "CHRNX Mobile Menu Toggle", "category": "theme", "description": "Progressively reveal the primary navigation on small screens.", diff --git a/blocks/podcast-meta/block.json b/blocks/podcast-meta/block.json index 5693ccd..9c32074 100644 --- a/blocks/podcast-meta/block.json +++ b/blocks/podcast-meta/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/podcast-meta", - "version": "0.4.4", + "version": "0.4.5", "title": "Podcast Metadata", "category": "theme", "description": "Safe episode details for the current post.", diff --git a/blocks/project-detail/block.json b/blocks/project-detail/block.json new file mode 100644 index 0000000..69d0b20 --- /dev/null +++ b/blocks/project-detail/block.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "chrnx/project-detail", + "version": "0.4.5", + "title": "Project Detail", + "category": "theme", + "description": "Cover, status, description and links for the queried project.", + "textdomain": "chrnx", + "attributes": {}, + "supports": { "html": false }, + "render": "file:./render.php" +} diff --git a/blocks/project-detail/render.php b/blocks/project-detail/render.php new file mode 100644 index 0000000..ffa5c44 --- /dev/null +++ b/blocks/project-detail/render.php @@ -0,0 +1,40 @@ +taxonomy ) { + return; +} + +$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_project_status', true ); +$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_project_cover', true ) ); +$chrnx_links = chrnx_get_project_links( $chrnx_term->term_id ); +$chrnx_cover_markup = $chrnx_cover > 0 ? wp_get_attachment_image( $chrnx_cover, 'large', false, array( 'class' => 'chrnx-project-detail__cover' ) ) : ''; +// Without status, description or links there is no second column to fill. +$chrnx_has_intro = '' !== $chrnx_status || '' !== $chrnx_term->description || ! empty( $chrnx_links ); +$chrnx_head_class = 'chrnx-project-detail__head' . ( $chrnx_has_intro ? '' : ' is-bare' ); +?> +
'chrnx-project-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> +
+
+ + + + + +
+
+ +

+ + description ) : ?> +

description ); ?>

+ + +
+
+
diff --git a/blocks/project-list/block.json b/blocks/project-list/block.json new file mode 100644 index 0000000..f0a4a7e --- /dev/null +++ b/blocks/project-list/block.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "chrnx/project-list", + "version": "0.4.5", + "title": "Project List", + "category": "theme", + "description": "Every project, each linking to its own page.", + "textdomain": "chrnx", + "attributes": { + "headingLevel": { "type": "integer", "default": 4, "enum": [2, 3, 4, 5, 6] } + }, + "supports": { "html": false }, + "render": "file:./render.php" +} diff --git a/blocks/project-list/render.php b/blocks/project-list/render.php new file mode 100644 index 0000000..40c8699 --- /dev/null +++ b/blocks/project-list/render.php @@ -0,0 +1,51 @@ + 'chrnx_project', + 'hide_empty' => false, + ) +); +if ( is_wp_error( $chrnx_terms ) || empty( $chrnx_terms ) ) { + return; +} +?> +
'chrnx-project-list' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> + term_id, 'chrnx_project_status', true ); + $chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_project_cover', true ) ); + $chrnx_links = chrnx_get_project_links( $chrnx_term->term_id ); + ?> +
+ + + + + 0 ? wp_get_attachment_image( $chrnx_cover, 'chrnx-card', false, array( 'class' => 'chrnx-project-card__cover' ) ) : ''; + ?> + + + + + + + class="chrnx-project-card__title">name ); ?>> + +

+ + +
+ + +
+ +
diff --git a/blocks/reading-time/block.json b/blocks/reading-time/block.json index 0872e15..990aa42 100644 --- a/blocks/reading-time/block.json +++ b/blocks/reading-time/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/reading-time", - "version": "0.4.4", + "version": "0.4.5", "title": "Reading Time", "category": "theme", "description": "Display a localized estimate based on the current post content.", diff --git a/blocks/related-posts/block.json b/blocks/related-posts/block.json index d9430c4..2b4cb32 100644 --- a/blocks/related-posts/block.json +++ b/blocks/related-posts/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/related-posts", - "version": "0.4.4", + "version": "0.4.5", "title": "Related Posts", "category": "theme", "description": "Related stories selected by topic, tags, and recency.", diff --git a/blocks/release-detail/block.json b/blocks/release-detail/block.json index 20eabf4..738e190 100644 --- a/blocks/release-detail/block.json +++ b/blocks/release-detail/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/release-detail", - "version": "0.4.4", + "version": "0.4.5", "title": "Release Detail", "category": "theme", "description": "Album cover, listening links, and the ordered tracklist.", diff --git a/blocks/release-detail/render.php b/blocks/release-detail/render.php index d3f60e7..98e19c4 100644 --- a/blocks/release-detail/render.php +++ b/blocks/release-detail/render.php @@ -10,12 +10,13 @@ if ( ! $chrnx_term instanceof WP_Term || 'chrnx_release' !== $chrnx_term->taxono return; } -$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 ); -$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_release_status', true ); -$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_release_cover', true ) ); -$chrnx_links = chrnx_get_release_links( $chrnx_term->term_id ); -$chrnx_tracks = chrnx_get_release_track_ids( $chrnx_term->slug ); -$chrnx_track_h = min( 6, $chrnx_heading + 1 ); +$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 ); +$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_release_status', true ); +$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_release_cover', true ) ); +$chrnx_links = chrnx_get_release_links( $chrnx_term->term_id ); +$chrnx_cover_markup = $chrnx_cover > 0 ? wp_get_attachment_image( $chrnx_cover, 'large', false, array( 'class' => 'chrnx-release-detail__cover' ) ) : ''; +$chrnx_tracks = chrnx_get_release_track_ids( $chrnx_term->slug ); +$chrnx_track_h = min( 6, $chrnx_heading + 1 ); // Without status, description or links there is no second column to fill. $chrnx_has_intro = '' !== $chrnx_status || '' !== $chrnx_term->description || ! empty( $chrnx_links ); $chrnx_head_class = 'chrnx-release-detail__head' . ( $chrnx_has_intro ? '' : ' is-bare' ); @@ -23,8 +24,8 @@ $chrnx_head_class = 'chrnx-release-detail__head' . ( $chrnx_has_intro ? '' : ' i
'chrnx-release-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
- 0 ) : ?> - 'chrnx-release-detail__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> + + diff --git a/blocks/release-list/block.json b/blocks/release-list/block.json index 048027d..ed792dc 100644 --- a/blocks/release-list/block.json +++ b/blocks/release-list/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/release-list", - "version": "0.4.4", + "version": "0.4.5", "title": "Release List", "category": "theme", "description": "The No Names releases, each linking to its album page.", diff --git a/blocks/release-list/render.php b/blocks/release-list/render.php index cc9f9d9..0349737 100644 --- a/blocks/release-list/render.php +++ b/blocks/release-list/render.php @@ -29,8 +29,11 @@ if ( is_wp_error( $chrnx_terms ) || empty( $chrnx_terms ) ) { - 0 ) : ?> - 'chrnx-release-card__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> + 0 ? wp_get_attachment_image( $chrnx_cover, 'chrnx-card', false, array( 'class' => 'chrnx-release-card__cover' ) ) : ''; + ?> + + diff --git a/blocks/selected-work/block.json b/blocks/selected-work/block.json deleted file mode 100644 index 19a0deb..0000000 --- a/blocks/selected-work/block.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 3, - "name": "chrnx/selected-work", - "version": "0.4.4", - "title": "Selected Work", - "category": "theme", - "description": "Hand-picked projects first, then the most recent ones.", - "textdomain": "chrnx", - "attributes": { - "limit": { "type": "integer", "default": 3, "minimum": 1, "maximum": 12 }, - "headingLevel": { "type": "integer", "default": 3, "enum": [2, 3, 4, 5, 6] } - }, - "supports": { "html": false }, - "render": "file:./render.php" -} diff --git a/blocks/selected-work/render.php b/blocks/selected-work/render.php deleted file mode 100644 index 7291587..0000000 --- a/blocks/selected-work/render.php +++ /dev/null @@ -1,26 +0,0 @@ - -
'chrnx-selected-work' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> - -

- -
- -
diff --git a/blocks/show-links/block.json b/blocks/show-links/block.json index ef1a218..7487811 100644 --- a/blocks/show-links/block.json +++ b/blocks/show-links/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/show-links", - "version": "0.4.4", + "version": "0.4.5", "title": "Show Links", "category": "theme", "description": "Where a podcast show can be listened to, rendered only when a URL exists.", diff --git a/blocks/site-brand/block.json b/blocks/site-brand/block.json index fad54b0..94af8a2 100644 --- a/blocks/site-brand/block.json +++ b/blocks/site-brand/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/site-brand", - "version": "0.4.4", + "version": "0.4.5", "title": "CHRNX Site Brand", "category": "theme", "description": "Display the local CHRNX wordmark linked to the site home.", diff --git a/blocks/subscribe-cta/block.json b/blocks/subscribe-cta/block.json index 03b0feb..0638dfd 100644 --- a/blocks/subscribe-cta/block.json +++ b/blocks/subscribe-cta/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/subscribe-cta", - "version": "0.4.4", + "version": "0.4.5", "title": "Subscribe CTA", "category": "theme", "description": "A call to action linked to the configured subscribe page.", diff --git a/blocks/subscribe-form/block.json b/blocks/subscribe-form/block.json index fb3269c..3e4ebc1 100644 --- a/blocks/subscribe-form/block.json +++ b/blocks/subscribe-form/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/subscribe-form", - "version": "0.4.4", + "version": "0.4.5", "title": "Subscribe Form", "category": "theme", "description": "The email subscription form, rendered only when a provider endpoint is configured.", diff --git a/blocks/theme-toggle/block.json b/blocks/theme-toggle/block.json index ce574c5..1e088b0 100644 --- a/blocks/theme-toggle/block.json +++ b/blocks/theme-toggle/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/theme-toggle", - "version": "0.4.4", + "version": "0.4.5", "title": "Theme Toggle", "category": "theme", "description": "Choose a light, dark, or system color theme.", diff --git a/blocks/topic-hero/block.json b/blocks/topic-hero/block.json index 9746f35..f8afbcf 100644 --- a/blocks/topic-hero/block.json +++ b/blocks/topic-hero/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/topic-hero", - "version": "0.4.4", + "version": "0.4.5", "title": "Topic Hero", "category": "theme", "description": "A fixed-art hero for an editorial topic.", diff --git a/blocks/track-meta/block.json b/blocks/track-meta/block.json index 3c18c18..105e542 100644 --- a/blocks/track-meta/block.json +++ b/blocks/track-meta/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "chrnx/track-meta", - "version": "0.4.4", + "version": "0.4.5", "title": "Track Meta", "category": "theme", "description": "Player, listening links, and album for one song.", diff --git a/docs/superpowers/plans/2026-08-15-projects-as-entities.md b/docs/superpowers/plans/2026-08-15-projects-as-entities.md new file mode 100644 index 0000000..c373d87 --- /dev/null +++ b/docs/superpowers/plans/2026-08-15-projects-as-entities.md @@ -0,0 +1,1070 @@ +# CHRNX Projects as First-Class Entities Implementation Plan + + + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Promote projects from a topic term to an entity taxonomy with its own term meta, landing page, and archive, modelled exactly on the existing `chrnx_release` pattern. + +**Architecture:** Register `chrnx_project` through the shared editorial taxonomy contract, give it term meta mirroring `chrnx_release` (cover, status, and three URLs), and render it through two new dynamic blocks cloned from `release-list` and `release-detail`. Retire the `chrnx_project_featured` post meta and the `selected-work` block, because music already proves a landing does not need a featured picker. Repair the missing `taxonomy-chrnx_show.html` while the same template shape is fresh. + +**Tech Stack:** WordPress 7.0.4 block theme, PHP 8.3, dynamic blocks with `render.php`, term meta on term edit screens, PHPUnit, Node smoke tests, Playwright on Chromium/Firefox/WebKit, PHPCS, WordPress Scripts linting. + +**Spec:** `docs/superpowers/specs/2026-08-15-projects-as-entities-design.md` + +## Global Constraints + +- Theme version is `0.4.4`. Any release bump updates `style.css`, `functions.php` (`CHRNX_VERSION`), and all 20 `blocks/*/block.json` together, or `npm run package` refuses to build. +- New block `block.json` files use `"apiVersion": 3` and `"version": "0.4.4"` to match every existing block. +- All PHP follows the theme's PHPCS ruleset; run `npm run phpcs` before every commit. +- Term meta sanitizers reuse existing helpers: `chrnx_sanitize_https_url`, `absint`, `sanitize_text_field`. +- Term meta auth reuses `chrnx_auth_release_meta`, as `show-meta.php` already does. +- Never invent project metadata. Repository, site, package URLs, and status come from the author. +- Do not push, deploy, or mutate production content. Production migration is Task 9 and is executed only after the author confirms the post-to-project mapping. +- Work on a branch off `main`. `main` is at the merge commit for `fix/document-language`. + +--- + +## File map + +| File | Responsibility | +|---|---| +| `inc/taxonomies.php` | Add the `chrnx_project` definition to the shared contract | +| `inc/project-meta.php` | Rewritten: project term meta, edit fields, save handler | +| `inc/queries.php` | Remove `chrnx_get_selected_project_ids()` | +| `blocks/project-list/` | New: lists every project as a card | +| `blocks/project-detail/` | New: renders one project's header on its archive | +| `blocks/selected-work/` | Deleted | +| `templates/taxonomy-chrnx_project.html` | New: project archive | +| `templates/taxonomy-chrnx_show.html` | New: repairs the podcast archive gap | +| `patterns/projects-landing.php` | New: banner plus project list | +| `patterns/home-projects.php` | Banner copy only, no list | +| `tests/php/TaxonomiesTest.php` | Extend definitions with `chrnx_project` | +| `tests/php/ProjectMetaTest.php` | New: term meta contract | +| `tests/smoke/templates.test.mjs` | Assert both new templates exist | + +--- + +### Task 1: Register the project taxonomy + +**Files:** + +- Modify: `inc/taxonomies.php:14-56` +- Test: `tests/php/TaxonomiesTest.php:24-60` + +**Interfaces:** + +- Consumes: `chrnx_register_editorial_taxonomy( $name, $definition )`, already defined at `inc/taxonomies.php:66`. +- Produces: taxonomy `chrnx_project` with `rest_base` `project` and seeded terms `green-tea`, `ailed`. + +- [ ] **Step 1: Write the failing test** + +In `tests/php/TaxonomiesTest.php`, add to the `$this->definitions` array in `set_up()`, after the `chrnx_release` entry: + +```php +'chrnx_project' => array( + 'rest_base' => 'project', + 'terms' => array( + 'green-tea' => 'Green Tea', + 'ailed' => 'Ailed', + ), +), +``` + +- [ ] **Step 2: Run the test to verify it fails** + +Run: `npm run test:php` +Expected: FAIL. The existing loop over `$this->definitions` asserts `taxonomy_exists()` and term presence, so `chrnx_project` reports as missing. + +- [ ] **Step 3: Add the taxonomy definition** + +In `inc/taxonomies.php`, inside `chrnx_get_editorial_taxonomies()`, add after the `chrnx_release` entry: + +```php +'chrnx_project' => array( + 'singular' => __( 'Project', 'chrnx' ), + 'plural' => __( 'Projects', 'chrnx' ), + 'rest_base' => 'project', + 'terms' => array( + 'green-tea' => __( 'Green Tea', 'chrnx' ), + 'ailed' => __( 'Ailed', 'chrnx' ), + ), +), +``` + +- [ ] **Step 4: Run the test to verify it passes** + +Run: `npm run test:php` +Expected: PASS. + +- [ ] **Step 5: Commit** + +```bash +git add inc/taxonomies.php tests/php/TaxonomiesTest.php +git commit -m "feat: model projects as their own editorial taxonomy" +``` + +--- + +### Task 2: Project term metadata + +**Files:** + +- Modify: `inc/project-meta.php` (replace the whole file, currently 37 lines of post meta) +- Test: `tests/php/ProjectMetaTest.php` (create) + +**Interfaces:** + +- Consumes: `chrnx_sanitize_https_url()` from `inc/release-meta.php`, `chrnx_auth_release_meta()`, `chrnx_print_release_field( $name, $label, $value, $type, $description )`. +- Produces: `chrnx_get_project_meta_definitions(): array`, `chrnx_get_project_links( int $term_id ): array`. + +- [ ] **Step 1: Write the failing test** + +Create `tests/php/ProjectMetaTest.php`: + +```php +assertArrayHasKey( $meta_key, $registered ); + } + } + + /** + * Ensure a plain http repository URL is rejected. + */ + public function test_project_links_reject_insecure_urls() { + $term_id = self::factory()->term->create( array( 'taxonomy' => 'chrnx_project' ) ); + update_term_meta( $term_id, 'chrnx_project_repo', 'http://example.com/repo' ); + + $this->assertArrayNotHasKey( 'repo', chrnx_get_project_links( $term_id ) ); + } + + /** + * Ensure stored https links come back keyed by their slot. + */ + public function test_project_links_return_stored_https_urls() { + $term_id = self::factory()->term->create( array( 'taxonomy' => 'chrnx_project' ) ); + update_term_meta( $term_id, 'chrnx_project_repo', 'https://github.com/Expressive-Tea/green-tea' ); + update_term_meta( $term_id, 'chrnx_project_package', 'https://www.npmjs.com/package/@green-tea/core' ); + + $links = chrnx_get_project_links( $term_id ); + + $this->assertSame( 'https://github.com/Expressive-Tea/green-tea', $links['repo'] ); + $this->assertSame( 'https://www.npmjs.com/package/@green-tea/core', $links['package'] ); + $this->assertArrayNotHasKey( 'site', $links ); + } +} +``` + +- [ ] **Step 2: Run the test to verify it fails** + +Run: `npm run test:php` +Expected: FAIL with "Call to undefined function chrnx_get_project_meta_definitions()". + +- [ ] **Step 3: Replace `inc/project-meta.php`** + +```php +> Slot key to label and icon. + */ +function chrnx_get_project_link_slots() { + return array( + 'repo' => array( + 'label' => __( 'Repository', 'chrnx' ), + 'icon' => '', + ), + 'package' => array( + 'label' => __( 'Package', 'chrnx' ), + 'icon' => '', + ), + 'site' => array( + 'label' => __( 'Website', 'chrnx' ), + 'icon' => '', + ), + ); +} + +/** + * Return the project term meta keys and their sanitizers. + * + * @return array Meta key to sanitize callback. + */ +function chrnx_get_project_meta_definitions() { + $definitions = array( + 'chrnx_project_cover' => 'absint', + 'chrnx_project_status' => 'sanitize_text_field', + ); + foreach ( array_keys( chrnx_get_project_link_slots() ) as $slot ) { + $definitions[ 'chrnx_project_' . $slot ] = 'chrnx_sanitize_https_url'; + } + return $definitions; +} + +/** + * Register project term metadata. + */ +function chrnx_register_project_meta() { + foreach ( chrnx_get_project_meta_definitions() as $meta_key => $sanitize ) { + register_term_meta( + 'chrnx_project', + $meta_key, + array( + 'type' => 'chrnx_project_cover' === $meta_key ? 'integer' : 'string', + 'single' => true, + 'show_in_rest' => true, + 'sanitize_callback' => $sanitize, + 'auth_callback' => 'chrnx_auth_release_meta', + ) + ); + } +} +add_action( 'init', 'chrnx_register_project_meta' ); + +/** + * Return the stored outbound links for one project. + * + * @param int $term_id Project term ID. + * @return array Slot key to URL, omitting empty ones. + */ +function chrnx_get_project_links( $term_id ) { + $links = array(); + foreach ( array_keys( chrnx_get_project_link_slots() ) as $slot ) { + $url = chrnx_sanitize_https_url( get_term_meta( $term_id, 'chrnx_project_' . $slot, true ) ); + if ( '' !== $url ) { + $links[ $slot ] = $url; + } + } + return $links; +} + +/** + * Render the project metadata fields on the term edit screen. + * + * @param WP_Term $term Project term. + */ +function chrnx_render_project_edit_fields( $term ) { + chrnx_print_release_field( + 'chrnx_project_status', + __( 'Status', 'chrnx' ), + (string) get_term_meta( $term->term_id, 'chrnx_project_status', true ), + 'text', + __( 'Short and honest, for example Beta, Activo or Archivado.', 'chrnx' ) + ); + + foreach ( chrnx_get_project_link_slots() as $slot => $definition ) { + chrnx_print_release_field( + 'chrnx_project_' . $slot, + $definition['label'], + (string) get_term_meta( $term->term_id, 'chrnx_project_' . $slot, true ), + 'url', + __( 'HTTPS only. Leave empty to hide this icon.', 'chrnx' ) + ); + } + + chrnx_print_release_field( + 'chrnx_project_cover', + __( 'Cover attachment ID', 'chrnx' ), + (string) absint( get_term_meta( $term->term_id, 'chrnx_project_cover', true ) ), + 'text', + __( 'Leave empty to use the shared placeholder art.', 'chrnx' ) + ); +} +add_action( 'chrnx_project_edit_form_fields', 'chrnx_render_project_edit_fields' ); + +/** + * Persist project term metadata from the term edit screen. + * + * @param int $term_id Project term ID. + */ +function chrnx_save_project_meta( $term_id ) { + if ( ! chrnx_auth_release_meta() ) { + return; + } + // Core supplies and verifies the add/update term nonce on these screens. + $nonce = isset( $_POST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ) : ''; + if ( ! wp_verify_nonce( $nonce, 'update-tag_' . $term_id ) && ! wp_verify_nonce( $nonce, 'add-tag' ) ) { + return; + } + + foreach ( chrnx_get_project_meta_definitions() as $meta_key => $sanitize ) { + if ( ! isset( $_POST[ $meta_key ] ) ) { + continue; + } + $value = call_user_func( $sanitize, wp_unslash( $_POST[ $meta_key ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized by the mapped callback. + if ( '' === $value || 0 === $value ) { + delete_term_meta( $term_id, $meta_key ); + continue; + } + update_term_meta( $term_id, $meta_key, $value ); + } +} +add_action( 'edited_chrnx_project', 'chrnx_save_project_meta' ); +add_action( 'created_chrnx_project', 'chrnx_save_project_meta' ); +``` + +- [ ] **Step 4: Confirm the term edit hook fires** + +Resolved before dispatch, no theme code needed. `{$taxonomy}_edit_form_fields` is a WordPress core hook fired by `wp-admin/edit-tag-form.php`, which is why `inc/show-meta.php` hooks `chrnx_show_edit_form_fields` without any dispatcher of its own. Hooking `chrnx_project_edit_form_fields` is enough. Confirm the fields appear by loading `/wp-admin/term.php?taxonomy=chrnx_project&tag_ID=`. + +- [ ] **Step 5: Run the tests to verify they pass** + +Run: `npm run test:php && npm run phpcs` +Expected: PASS, no PHPCS output. + +- [ ] **Step 6: Commit** + +```bash +git add inc/project-meta.php tests/php/ProjectMetaTest.php +git commit -m "feat: give projects a repository, package and status" +``` + +--- + +### Task 3: Placeholder cover art + +**Files:** + +- Create: `assets/images/generated/placeholder-project-384.{webp,avif}`, `-768.{webp,avif}`, `placeholder-project.json` +- Modify: `inc/media.php` allowlist + +**Interfaces:** + +- Produces: art slug `placeholder-project`, consumed by `chrnx_get_topic_portrait_markup( 'placeholder-project', ... )`. + +- [ ] **Step 1: Read how `placeholder-release` is allowlisted** + +Run: `grep -n "placeholder-release" inc/media.php` +The art slug must appear in the same allowlist, or `chrnx_get_topic_art_asset()` returns an empty string and the helper renders nothing. + +- [ ] **Step 2: Generate the master image** + +Ask the author for the master PNG. Do not substitute CSS art, an SVG, or a stock image. Stop here until the author approves the generated master. + +- [ ] **Step 3: Build the derivatives** + +Run: `./scripts/build-responsive-images.sh ` +Expected: `384` and `768` variants in both webp and avif, plus the JSON dimensions sidecar. + +- [ ] **Step 4: Add the slug to the allowlist** + +Mirror the `placeholder-release` entry in `inc/media.php` exactly, changing only the slug. + +- [ ] **Step 5: Verify the helper returns markup** + +Run: `npx wp-env run cli wp eval 'echo chrnx_get_topic_portrait_markup( "placeholder-project", "", "test" ) === "" ? "VACIO" : "OK";'` +Expected: `OK`. + +- [ ] **Step 6: Commit** + +```bash +git add assets/images/generated/placeholder-project* inc/media.php +git commit -m "feat: add shared placeholder art for projects without a cover" +``` + +--- + +### Task 4: The project list block + +**Files:** + +- Create: `blocks/project-list/block.json`, `blocks/project-list/render.php` +- Modify: `inc/blocks.php:235` — add `'project-list'` to the `$blocks` array +- Test: `tests/php/ProjectBlocksTest.php` (create) + +**Registration is not automatic.** `chrnx_register_editorial_blocks()` iterates an explicit allowlist array and only then calls `register_block_type()` on the matching directory. Creating `blocks/project-list/` without adding its name to that array leaves the block unregistered, and `do_blocks()` returns the raw comment, so the test fails with no useful message. + +**Interfaces:** + +- Consumes: `chrnx_get_project_links()`, `chrnx_get_heading_level()`, `chrnx_get_topic_portrait_markup()`, `chrnx_get_platform_links_markup()`. +- Produces: block `chrnx/project-list`, consumed by `patterns/projects-landing.php`. + +- [ ] **Step 1: Write the failing test** + +Create `tests/php/ProjectBlocksTest.php`: + +```php +term->create( + array( + 'taxonomy' => 'chrnx_project', + 'name' => 'Green Tea', + 'slug' => 'green-tea-test', + ) + ); + update_term_meta( $term_id, 'chrnx_project_status', 'Beta' ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'chrnx-project-card', $markup ); + $this->assertStringContainsString( 'Green Tea', $markup ); + $this->assertStringContainsString( 'Beta', $markup ); + } + + /** + * Ensure a project without a cover still renders art. + */ + public function test_project_without_cover_uses_placeholder_art() { + self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'slug' => 'coverless-test', + ) + ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'chrnx-project-card__fallback', $markup ); + } +} +``` + +- [ ] **Step 2: Run the test to verify it fails** + +Run: `npm run test:php` +Expected: FAIL. `do_blocks()` returns the unrendered comment because `chrnx/project-list` is not registered. + +- [ ] **Step 3: Create `blocks/project-list/block.json`** + +```json +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "chrnx/project-list", + "version": "0.4.4", + "title": "Project List", + "category": "theme", + "description": "Every project, each linking to its own page.", + "textdomain": "chrnx", + "attributes": { + "headingLevel": { "type": "integer", "default": 4, "enum": [2, 3, 4, 5, 6] } + }, + "supports": { "html": false }, + "render": "file:./render.php" +} +``` + +- [ ] **Step 3b: Register the block** + +Add `'project-list'` to the `$blocks` array in `chrnx_register_editorial_blocks()` at `inc/blocks.php:235`, keeping the existing single-line array format. + +- [ ] **Step 4: Create `blocks/project-list/render.php`** + +```php + 'chrnx_project', + 'hide_empty' => false, + ) +); +if ( is_wp_error( $chrnx_terms ) || empty( $chrnx_terms ) ) { + return; +} +?> +
'chrnx-project-list' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> + term_id, 'chrnx_project_status', true ); + $chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_project_cover', true ) ); + $chrnx_links = chrnx_get_project_links( $chrnx_term->term_id ); + ?> + + +
+``` + +- [ ] **Step 5: Confirm the icon lookup** + +Resolved before dispatch, no change needed to the helper. `chrnx_get_platform_links_markup( array $links, $class_name, $platforms = null )` at `inc/release-meta.php:120` already takes an explicit slot-definition array as its third argument and falls back to `chrnx_get_release_platforms()` only when that argument is omitted. Its loop skips any slot missing from `$platforms`, so omitting the third argument would silently render no links at all for projects. The render code above passes `chrnx_get_project_link_slots()` explicitly. Verify that argument is present. + +- [ ] **Step 6: Run the tests to verify they pass** + +Run: `npm run test:php && npm run phpcs` +Expected: PASS. + +- [ ] **Step 7: Commit** + +```bash +git add blocks/project-list tests/php/ProjectBlocksTest.php +git commit -m "feat: list every project with its status and links" +``` + +--- + +### Task 5: The project detail block + +**Files:** + +- Create: `blocks/project-detail/block.json`, `blocks/project-detail/render.php` +- Modify: `inc/blocks.php:235` — add `'project-detail'` to the `$blocks` array, exactly as Task 4 added `'project-list'` +- Modify: `inc/blocks.php:32` — add `'chrnx_project'` to the `is_tax()` list +- Modify: `inc/queries.php` lines 377, 434, 489, 529 — add `'chrnx_project'` to each taxonomy list. NOT line 404: see below +- Test: `tests/php/ProjectBlocksTest.php` (extend) + +**This block renders a HEADER ONLY. It does not list posts.** `blocks/release-detail/render.php` also renders a tracklist, and the first draft of this plan said to clone it line for line. That was wrong twice over: projects have no track numbers, and the posts belonging to a project are ordinary reverse-chronological editorial posts — which is exactly what `chrnx/journal-stream` already renders on an archive. + +The correct model is `chrnx_show`, not `chrnx_release`. Podcast programmes list their episodes through `journal-stream` on the archive, because `chrnx_show` appears in the taxonomy lists inside `inc/queries.php`. `chrnx_project` appears in none of them, so without those five edits a project archive would render the whole unfiltered journal — the wrong posts, with no error. + +**Interfaces:** + +- Consumes: `chrnx_get_project_links()`, `chrnx_get_project_link_slots()`, `chrnx_get_topic_portrait_markup()`. +- Produces: block `chrnx/project-detail`, consumed by `templates/taxonomy-chrnx_project.html`. + +- [ ] **Step 1: Add `chrnx_project` to the archive taxonomy lists** + +Four in `inc/queries.php` (377, 434, 489, 529) and one in `inc/blocks.php:32`. Read each before editing. + +```bash +grep -n "chrnx_topic', 'chrnx_language'" inc/queries.php inc/blocks.php +``` + +**Do NOT add it to `inc/queries.php:404`.** That list belongs to `chrnx_get_journal_request_context()` and governs which taxonomies are accepted as user-supplied query parameters. `chrnx_show` is deliberately absent from it, and project must follow show: `chrnx_get_journal_archive_filter()` force-injects the queried term into the context at lines 415-418 regardless of that loop, so the archive works without it. Adding it would accept `?chrnx_project=slug` on page one and then lose it, because `blocks/journal-stream/render.php:125-133` builds its pagination filter arguments from topic, language, show and search only. A filter that survives one page and then forgets itself is worse than no filter. + +- [ ] **Step 2: Write the failing test** + +Append to `tests/php/ProjectBlocksTest.php`: + +```php + /** + * Ensure the detail block renders the queried project header. + */ + public function test_project_detail_renders_the_queried_term() { + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'name' => 'Ailed', + 'slug' => 'ailed-test', + 'description' => 'A chess engine that feels.', + ) + ); + update_term_meta( $term_id, 'chrnx_project_repo', 'https://github.com/example/ailed' ); + update_term_meta( $term_id, 'chrnx_project_status', 'Activo' ); + + $this->go_to( get_term_link( $term_id ) ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'A chess engine that feels.', $markup ); + $this->assertStringContainsString( 'https://github.com/example/ailed', $markup ); + $this->assertStringContainsString( 'Activo', $markup ); + } + + /** + * Ensure the detail block renders nothing outside a project archive. + */ + public function test_project_detail_is_silent_off_its_archive() { + $this->go_to( home_url( '/' ) ); + + $this->assertSame( '', trim( do_blocks( '' ) ) ); + } + + /** + * Ensure a project archive filters the journal to that project. + */ + public function test_project_archive_filters_the_journal() { + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'slug' => 'filter-test', + ) + ); + $mine = self::factory()->post->create( array( 'post_title' => 'Belongs to the project' ) ); + self::factory()->post->create( array( 'post_title' => 'Unrelated post' ) ); + wp_set_object_terms( $mine, array( $term_id ), 'chrnx_project' ); + + $this->go_to( get_term_link( $term_id ) ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'Belongs to the project', $markup ); + $this->assertStringNotContainsString( 'Unrelated post', $markup ); + } +``` + +- [ ] **Step 3: Run the tests to verify they fail** + +Run: `npm run test:php` +Expected: FAIL — the block is unregistered, and the archive filter test shows the unrelated post. + +- [ ] **Step 4: Create the block** + +`blocks/project-detail/block.json` mirrors Task 4's JSON with `"name": "chrnx/project-detail"`, `"title": "Project Detail"`, and `"description": "Cover, status, description and links for the queried project."`. + +Give it `"attributes": {}`. Do NOT copy Task 4's `headingLevel` attribute: the render below emits no heading — the archive's `

` comes from `wp:query-title` in the template, and status and description are paragraphs. An attribute nothing reads is dead configuration. + +`blocks/project-detail/render.php` follows the HEAD section of `blocks/release-detail/render.php` only — its guard, its art column, and its intro column. Stop before the tracklist; do not port it. + +```php +taxonomy ) { + return; +} + +$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_project_status', true ); +$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_project_cover', true ) ); +$chrnx_links = chrnx_get_project_links( $chrnx_term->term_id ); +// Without status, description or links there is no second column to fill. +$chrnx_has_intro = '' !== $chrnx_status || '' !== $chrnx_term->description || ! empty( $chrnx_links ); +$chrnx_head_class = 'chrnx-project-detail__head' . ( $chrnx_has_intro ? '' : ' is-bare' ); +?> +
'chrnx-project-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> +
+
+ 0 ) : ?> + 'chrnx-project-detail__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> + + + +
+
+ +

+ + description ) : ?> +

description ); ?>

+ + +
+
+
+``` + +- [ ] **Step 5: Register the block** + +Add `'project-detail'` to the `$blocks` array at `inc/blocks.php:235`. + +- [ ] **Step 6: Run the tests to verify they pass** + +Run: `npm run test:php && npm run phpcs` +Expected: PASS. + +- [ ] **Step 7: Commit** + +```bash +git add blocks/project-detail inc/blocks.php inc/queries.php tests/php/ProjectBlocksTest.php +git commit -m "feat: give each project its own page header and post stream" +``` + +--- + +### Task 6: Archive templates for projects and shows + +**Files:** + +- Create: `templates/taxonomy-chrnx_project.html` +- Create: `templates/taxonomy-chrnx_show.html` +- Test: `tests/smoke/templates.test.mjs` + +**Interfaces:** + +- Consumes: blocks `chrnx/project-detail` (Task 5) and `chrnx/show-links` (existing). + +- [ ] **Step 1: Write the failing test** + +Read `tests/smoke/templates.test.mjs` first to match its existing assertion style, then add both filenames to whatever list it checks. + +- [ ] **Step 2: Run the test to verify it fails** + +Run: `npm run test:smoke` +Expected: FAIL, both templates missing. + +- [ ] **Step 3: Create `templates/taxonomy-chrnx_project.html`** + +```html + + + +
+ + + + +
+ + + +``` + +- [ ] **Step 4: Create `templates/taxonomy-chrnx_show.html`** + +This repairs the gap named in the spec: shows currently fall through to the generic archive and never render their own detail. + +`journal-stream` and `subscribe-cta` are NOT optional here. The fallback this template overrides is `templates/archive.html`, which contains both, so a show archive today does list its episodes. A dedicated template carrying only `show-links` would render a title and whitespace whenever a show has no platform URLs — strictly worse than the fallback it replaces. A template that renders less than what it overrides is a regression, not a repair. + +```html + + + +
+ + + + +
+ + + +``` + +- [ ] **Step 5: Verify both archives render** + +Run: `npx wp-env run cli wp eval 'echo get_term_link( "green-tea", "chrnx_project" );'` then curl that URL and confirm HTTP 200 with the project title in the output. Repeat for `silicon-ranch` in `chrnx_show`. + +- [ ] **Step 6: Run the tests to verify they pass** + +Run: `npm run test:smoke && npm run test:php` +Expected: PASS. + +- [ ] **Step 7: Commit** + +```bash +git add templates/taxonomy-chrnx_project.html templates/taxonomy-chrnx_show.html tests/smoke/templates.test.mjs +git commit -m "feat: give project and show archives their own templates" +``` + +--- + +### Task 7: The projects landing + +**Files:** + +- Create: `patterns/projects-landing.php` +- Modify: `patterns/home-projects.php` +- Modify: `assets/css/components.css` — styles for BOTH `chrnx-project-card*` (Task 4) and `chrnx-project-detail*` (Task 5); neither shipped with any rules + +**Interfaces:** + +- Consumes: `chrnx/project-list` (Task 4), `chrnx_get_atmosphere_markup()`, `chrnx_get_topic_portrait_markup()`. +- Produces: pattern slug `chrnx/projects-landing`, referenced by production page 740 in Task 9. + +- [ ] **Step 1: Create `patterns/projects-landing.php`** + +Mirrors `patterns/music-landing.php` exactly: a `chrnx-character-stage` with atmosphere, content, and art layers, then the list block. Copy is the author's, approved in the spec. + +```php + + +
+ +
+ + +
+

+

+

+
+ +
+
+ +

+ +
+ +``` + +- [ ] **Step 2: Strip the list out of `patterns/home-projects.php`** + +Replace the `` line with a paragraph, so the home section becomes banner copy only, matching `home-music.php`: + +```php +

+``` + +- [ ] **Step 3: Add styles for BOTH new components** + +Task 5 shipped `blocks/project-detail/render.php` with `chrnx-project-detail__*` class names and no stylesheet rules, so the project archive header is currently unstyled. Task 4 shipped `chrnx-project-card*` in the same state. Both are fixed here. + +In `assets/css/components.css`, extend the existing selectors rather than duplicating rule bodies — the project components are structurally identical to their release counterparts: + +- `.chrnx-release-card*` rules appear in two separate places, around lines 270 and 886. Add the matching `.chrnx-project-card*` selector to every one of them, including `__art`, `__cover`, `__fallback`, `__link`, `__title`, the `::after`, and the `:hover`. +- `.chrnx-release-list` gains `.chrnx-project-list`. +- The eleven `.chrnx-release-detail*` rules gain their `.chrnx-project-detail*` counterparts, including `__head`, `__head.is-bare`, `__art`, `__cover`, `__fallback`, `__intro`, `__status`, and `__description`. + +Verify with a grep afterwards that no `chrnx-project-` class emitted by either render file lacks a rule: + +```bash +grep -oh "chrnx-project-[a-z-]*\(__[a-z-]*\)\?" blocks/project-*/render.php | sort -u +grep -oh "\.chrnx-project-[a-z-]*\(__[a-z-]*\)\?" assets/css/components.css | sort -u +``` + +The second list must cover the first. + +- [ ] **Step 4: Verify the landing renders locally** + +Create a local page containing only ``, then curl it and confirm the heading, both paragraphs, and one `chrnx-project-card` per seeded term. + +- [ ] **Step 5: Run the full local suite** + +Run: `npm run test:smoke && npm run test:php && npm run lint:css && npm run phpcs` +Expected: PASS. + +- [ ] **Step 6: Commit** + +```bash +git add patterns/projects-landing.php patterns/home-projects.php assets/css/components.css +git commit -m "feat: give projects a landing of their own" +``` + +--- + +### Task 8: Retire the featured picker + +**Files:** the surface is wider than a block deletion. Every one of these was verified to reference the retired feature. + +- Delete: `blocks/selected-work/` (block.json + render.php) +- Delete: `assets/js/editor-project.js` — the editor sidebar panel exists only to toggle `chrnx_project_featured`, and it self-hides unless the post carries the `projects` topic, which Task 9 retires +- Delete: `tests/js/editor-project.test.js` — four references, all covering the deleted panel +- Modify: `inc/queries.php:274` remove `chrnx_get_selected_project_ids()` and its docblock +- Modify: `inc/blocks.php:235` remove `'selected-work'` from the registration list +- Modify: `inc/editor.php:49-50` remove the `chrnx-editor-project` enqueue, and `:66` its `wp_set_script_translations()` call +- Modify: `scripts/seed-test-content.php:143,147` remove `chrnx_project_featured` from the seeded meta keys and the `update_post_meta()` call +- Modify: `assets/css/components.css` remove `.chrnx-selected-work*` rules +- Modify: `tests/php/EditorAssetsTest.php` — four real assertions on the `chrnx-editor-project` handle at lines 48, 86, 93 and 126. These FAIL the moment the script is unenqueued, so they must be updated in the same commit as the deletion, not afterwards +- Modify: `tests/php/PatternsTest.php:209` and `tests/e2e/music-podcast-stages.spec.mjs:560` — comments only, no assertions, but both state that project names come from `chrnx/selected-work`. Leaving them makes the tests lie about a block that no longer exists +- NOT `tests/php/EditorialQueriesTest.php`: an earlier draft of this plan said to drop coverage of `chrnx_get_selected_project_ids()` there. That function has NO test coverage anywhere — it appears only in `inc/queries.php` and `blocks/selected-work/render.php`. Do not go looking for tests that do not exist + +**Interfaces:** + +- Removes: `chrnx_get_selected_project_ids()`, post meta `chrnx_project_featured`, block `chrnx/selected-work`. + +- [ ] **Step 1: Confirm nothing else references them** + +```bash +grep -rn "selected-work\|selected_project\|chrnx_project_featured\|chrnx-editor-project" \ + --include="*.php" --include="*.js" --include="*.json" --include="*.html" --include="*.mjs" \ + --include="*.css" inc blocks patterns templates assets tests scripts +``` + +Note `scripts` in the search path and `--include="*.css"` in the filters: the first pass of this plan omitted both and missed four real references. Every hit must be one of the files listed above. A hit anywhere else means this task is incomplete; handle it before deleting. Re-run this grep after the deletions and expect zero output. + +- [ ] **Step 2: Confirm production stores no copy of the block** + +Already verified on 2026-08-15: pages hold `wp:pattern` references, and page 740 holds `chrnx/home-projects` plus `chrnx/journal-stream`, not `chrnx/selected-work`. Re-run the check before deleting: + +```bash +WP_PASS=$(pass show personal/chrnx-dev | head -1) +WP_USER=$(pass show personal/chrnx-dev | sed -n 's/^user:[[:space:]]*//p' | head -1) +curl -s -u "$WP_USER:$WP_PASS" "https://chrnx.dev/wp-json/wp/v2/pages?per_page=50&context=edit&_fields=id,slug,content" \ + | grep -c "chrnx/selected-work" +``` + +Expected: `0`. If it is not zero, stop and migrate that page's content first. + +- [ ] **Step 3: Delete the block and the query** + +```bash +git rm -r blocks/selected-work +``` + +Then remove `chrnx_get_selected_project_ids()` from `inc/queries.php` along with its docblock, and drop the tests covering it from `tests/php/EditorialQueriesTest.php`. + +- [ ] **Step 4: Confirm the post meta registration is gone** + +Task 2 replaced `inc/project-meta.php` wholesale, so the `register_post_meta()` call for `chrnx_project_featured` no longer exists. What survives is every CONSUMER of that meta, listed in this task's file map. Confirm with the grep from Step 1 that none remain. + +- [ ] **Step 4b: Run the JavaScript suite** + +Deleting an editor script and its test file changes the JS surface, which the PHP suite does not cover. + +Run: `npm run test:js && npm run lint:js` +Expected: PASS, with one fewer suite than before. + +- [ ] **Step 5: Run the full local suite** + +Run: `npm test` +Expected: PASS across smoke, lint, phpcs, php, js, and e2e. + +- [ ] **Step 6: Commit** + +```bash +git add -A +git commit -m "refactor: drop the featured-project picker in favour of the project list" +``` + +--- + +### Task 9: Production migration + +**Files:** none in the repository. This task mutates production content and runs only after the author confirms the mapping. + +**Interfaces:** + +- Consumes: taxonomy `chrnx_project` and its terms, live after the theme ZIP is uploaded. + +- [ ] **Step 1: Get the mapping from the author** + +Do not infer it. Ask for the project term and the corrected topic for each of these six posts: + +| ID | Title | Topic today | +|---|---|---| +| 730 | I Built a Framework on Express. Then I Had to Rebuild It From Scratch. | code | +| 838 | req.user no existe, tú nomás rezas | projects | +| 695 | What's New in Expressive Tea 2.0: The Full Breakdown | code | +| 692 | Expressive Tea 2.0 Is Here | projects | +| 678 | Ailed: A Chess Engine That Feels | projects | +| 716 | Processing 1M Chess Games in 15 Seconds with Rust | code | + +Note that Expressive Tea is a separate project from Green Tea, so it likely needs a third term that Task 1 does not seed. + +- [ ] **Step 2: Release and upload the theme** + +The version bump is not optional here, and not only for cache-busting. WordPress caches theme pattern discovery in the site transient `wp_theme_files_patterns-`, and `WP_Theme::get_pattern_cache()` returns the cached list only when the stored version matches the theme's current `Version` header. Ship `patterns/projects-landing.php` without bumping the version and the pattern silently never registers — page 740 would then reference a pattern slug WordPress does not know, and render nothing. This was hit for real in the worktree, where the version stayed pinned while a pattern was added. + +Bump `style.css`, `functions.php`, and all `blocks/*/block.json` to the new version together, then: + +```bash +npm run package +``` + +The author uploads `dist/chrnx-.zip` through Appearance then Themes. Do not attempt to deploy. + +- [ ] **Step 3: Fill in each project's term meta** + +Through the term edit screen or REST, set status, repository, package, and site for `green-tea`, `ailed`, and any term added in Step 1. Values come from the author. + +- [ ] **Step 4: Assign project terms and correct topics** + +Apply the Step 1 mapping through REST, one post at a time, verifying each response before moving on. + +- [ ] **Step 5: Repoint page 740** + +Replace the page content with a single pattern reference: + +```text + +``` + +This drops the `chrnx/journal-stream {"topic":"projects"}` block, which breaks once the `projects` topic is retired. + +- [ ] **Step 6: Retire the projects topic term** + +Only after Step 4 shows every post rehomed. Delete the `projects` term from `chrnx_topic` and remove it from the seeded definitions in `inc/taxonomies.php` and `tests/php/TaxonomiesTest.php`. + +- [ ] **Step 7: Verify production** + +```bash +for u in / /projects/ /project/green-tea/ /project/ailed/ /topic/code/; do + printf "%-4s %s\n" "$(curl -sL -o /dev/null -w '%{http_code}' "https://chrnx.dev$u")" "$u" +done +``` + +Expected: `200` on every route. Then confirm each project page lists its posts, and that no route leaks a PHP notice. + +- [ ] **Step 8: Regenerate the critical CSS** + +After the theme upload, never before. The author regenerates Jetpack Boost's critical CSS from the plugin settings. + +--- + +## Self-review + +**Spec coverage.** Content model is Tasks 1 and 2. The generic package field is Task 2. Cover fallback is Tasks 3 and 4. Retiring the featured picker is Task 8. The landing and its copy are Task 7. Project and show archives are Task 6. Migration and the retirement of the `projects` topic are Task 9. + +**Open item carried into execution.** Task 4 Step 5 and Task 2 Step 4 both depend on how `inc/release-meta.php` dispatches term-edit hooks and resolves platform icons. Both steps read the file first and adapt. These are the only places where the release code may not generalise without a small change, and both are flagged rather than assumed. + +**Naming consistency.** `chrnx_get_project_link_slots()`, `chrnx_get_project_meta_definitions()`, and `chrnx_get_project_links()` are defined in Task 2 and used under those exact names in Tasks 4 and 5. Meta keys are `chrnx_project_cover`, `chrnx_project_status`, `chrnx_project_repo`, `chrnx_project_package`, `chrnx_project_site` throughout. CSS classes use the `chrnx-project-` prefix throughout. diff --git a/docs/superpowers/specs/2026-08-15-projects-as-entities-design.md b/docs/superpowers/specs/2026-08-15-projects-as-entities-design.md new file mode 100644 index 0000000..5c3ccbd --- /dev/null +++ b/docs/superpowers/specs/2026-08-15-projects-as-entities-design.md @@ -0,0 +1,119 @@ +# CHRNX Projects as First-Class Entities — Design + + + +**Status:** Approved 2026-08-15 +**Supersedes:** the `projects` topic term as a grouping mechanism + +## Problem + +`projects` is a topic term, so it cannot separate the thing from the writing about it. +Green Tea is a project with a repository, a published package, and a release status. +The posts about Green Tea are a different kind of object. Today both collapse into one +term, and the term cannot hold a repository URL or a cover. + +That collapse already produced an inconsistency. Announcement posts landed in +`projects` while deep dives on the same product landed in `code`: + +| Product | Announcement | Deep dive | +|---|---|---| +| Expressive Tea | 692 (`projects`) | 695 (`code`) | +| Ailed | 678 (`projects`) | 716 (`code`) | +| Green Tea | 838 (`projects`) | 730 (`code`) | + +A reader browsing Green Tea finds half its material. The split exists only because one +term was doing two jobs. + +Music and podcasts already solved this. `chrnx_release` is the album, `chrnx_show` is the +programme, and posts reference them. Projects never got the same treatment. + +## Solution + +Promote projects to an entity taxonomy modelled on `chrnx_release`, and return `code` +to being a general topic about writing code. + +### Content model + +New taxonomy `chrnx_project`, registered through the existing +`chrnx_register_editorial_taxonomy` contract with `rest_base` `project`. + +Seeded terms: `green-tea` (Green Tea), `ailed` (Ailed). + +Term meta, mirroring `chrnx_release`: + +| Meta key | Type | Sanitizer | Purpose | +|---|---|---|---| +| `chrnx_project_cover` | integer | `absint` | Attachment ID for the project cover | +| `chrnx_project_status` | string | `sanitize_text_field` | Free text, e.g. `Beta`, `Activo`, `Archivado` | +| `chrnx_project_repo` | string | `chrnx_sanitize_https_url` | Source repository | +| `chrnx_project_site` | string | `chrnx_sanitize_https_url` | Documentation or product site | +| `chrnx_project_package` | string | `chrnx_sanitize_https_url` | Where the package lives | + +`chrnx_project_package` is deliberately one generic URL rather than an npm-specific +field. Green Tea publishes to npm, a Rust project would publish to crates.io, a Python +one to PyPI. One URL covers all three; a per-registry field list would need editing +every time a new language shows up. + +Cover falls back to shared placeholder art when unset, exactly as +`chrnx_release_cover` falls back to `placeholder-release`. + +### Retired + +`chrnx_project_featured` (post meta), `chrnx_get_selected_project_ids()`, and the +`chrnx/selected-work` block are removed. + +Music proves they are unnecessary. `music-landing` lists every release through +`chrnx/release-list` with no notion of a featured release, and `home-music` carries no +list at all. With two or three projects, picking a favourite is ceremony, not curation. + +The `projects` topic term is retired. Posts that carried it move to `code`, and grouping +moves to their project term. + +### Surfaces + +| Surface | Today | After | +|---|---|---| +| `/projects/` page (740) | `chrnx/home-projects` pattern + `journal-stream {"topic":"projects"}` | `chrnx/projects-landing` pattern | +| Project archive | none | `templates/taxonomy-chrnx_project.html` | +| Home section | `chrnx/selected-work` inside `home-projects` | banner copy only, mirroring `home-music` | + +The landing gets a character-stage banner in the established three-layer shape +(atmosphere, content, art), followed by `chrnx/project-list`. + +Landing copy, in the author's voice: + +> **Proyectos** +> Aquí va lo que mi cerebro tira en formato de código. +> Una noche me agarra la loquera y sale código. A veces sirve, a veces nomás me deja +> dormir. Lo que sobrevive lo dejo aquí, con su repo y su estado real, sin adornos. + +### Debt repaid alongside + +`chrnx_show` has no `taxonomy-chrnx_show.html` and falls through to the generic archive, +so a podcast programme page never renders its own detail block. Adding +`templates/taxonomy-chrnx_show.html` alongside the project template closes that gap +while the same shape is fresh. + +## Migration + +Pages store pattern references rather than expanded markup, so theme changes propagate +without touching stored content. Verified on production: + +```text +740 /projects/ + +743 /music/ +``` + +One stored block breaks: `journal-stream {"topic":"projects"}` on page 740, because its +topic disappears. Page 740 becomes a single `chrnx/projects-landing` pattern reference. + +Six published posts need project terms assigned and their topic corrected. The exact +post-to-project mapping is supplied by the author, not inferred. + +## Non-goals + +- No custom post type. Projects are terms, like releases and shows. +- No per-registry package fields. +- No project-level prose page beyond the term description. +- No changes to `chrnx_release`, `chrnx_show`, Related Stories, or theme preference. diff --git a/functions.php b/functions.php index 6bc4749..6c1dcd3 100644 --- a/functions.php +++ b/functions.php @@ -1,5 +1,5 @@ is_registered( $name ) ) { diff --git a/inc/editor.php b/inc/editor.php index f185611..4d5c6a3 100644 --- a/inc/editor.php +++ b/inc/editor.php @@ -45,14 +45,6 @@ function chrnx_enqueue_editor_assets() { true ); - wp_enqueue_script( - 'chrnx-editor-project', - get_theme_file_uri( 'assets/js/editor-project.js' ), - array( 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins' ), - CHRNX_VERSION, - true - ); - wp_enqueue_script( 'chrnx-editor-track', get_theme_file_uri( 'assets/js/editor-track.js' ), @@ -63,7 +55,6 @@ function chrnx_enqueue_editor_assets() { wp_set_script_translations( 'chrnx-editor-taxonomies', 'chrnx', get_theme_file_path( 'languages' ) ); wp_set_script_translations( 'chrnx-editor-podcast', 'chrnx', get_theme_file_path( 'languages' ) ); - wp_set_script_translations( 'chrnx-editor-project', 'chrnx', get_theme_file_path( 'languages' ) ); wp_set_script_translations( 'chrnx-editor-track', 'chrnx', get_theme_file_path( 'languages' ) ); } add_action( 'enqueue_block_editor_assets', 'chrnx_enqueue_editor_assets' ); diff --git a/inc/project-meta.php b/inc/project-meta.php index 86c7141..dcf23b4 100644 --- a/inc/project-meta.php +++ b/inc/project-meta.php @@ -1,37 +1,149 @@ > Slot key to label and icon. */ -function chrnx_auth_project_meta( $allowed, $meta_key, $post_id ) { - return current_user_can( 'edit_post', $post_id ); +function chrnx_get_project_link_slots() { + return array( + 'repo' => array( + 'label' => __( 'Repository', 'chrnx' ), + 'icon' => '', + ), + 'package' => array( + 'label' => __( 'Package', 'chrnx' ), + 'icon' => '', + ), + 'site' => array( + 'label' => __( 'Website', 'chrnx' ), + 'icon' => '', + ), + ); } /** - * Register project metadata for posts. + * Return the project term meta keys and their sanitizers. + * + * @return array Meta key to sanitize callback. + */ +function chrnx_get_project_meta_definitions() { + $definitions = array( + 'chrnx_project_cover' => 'absint', + 'chrnx_project_status' => 'sanitize_text_field', + ); + foreach ( array_keys( chrnx_get_project_link_slots() ) as $slot ) { + $definitions[ 'chrnx_project_' . $slot ] = 'chrnx_sanitize_https_url'; + } + return $definitions; +} + +/** + * Register project term metadata. */ function chrnx_register_project_meta() { - register_post_meta( - 'post', - 'chrnx_project_featured', - array( - 'type' => 'boolean', - 'single' => true, - 'default' => false, - 'show_in_rest' => array( 'schema' => array( 'type' => 'boolean' ) ), - 'sanitize_callback' => 'rest_sanitize_boolean', - 'auth_callback' => 'chrnx_auth_project_meta', - ) - ); + foreach ( chrnx_get_project_meta_definitions() as $meta_key => $sanitize ) { + register_term_meta( + 'chrnx_project', + $meta_key, + array( + 'type' => 'chrnx_project_cover' === $meta_key ? 'integer' : 'string', + 'single' => true, + 'show_in_rest' => true, + 'sanitize_callback' => $sanitize, + 'auth_callback' => 'chrnx_auth_release_meta', + ) + ); + } } add_action( 'init', 'chrnx_register_project_meta' ); + +/** + * Return the stored outbound links for one project. + * + * @param int $term_id Project term ID. + * @return array Slot key to URL, omitting empty ones. + */ +function chrnx_get_project_links( $term_id ) { + $links = array(); + foreach ( array_keys( chrnx_get_project_link_slots() ) as $slot ) { + $url = chrnx_sanitize_https_url( get_term_meta( $term_id, 'chrnx_project_' . $slot, true ) ); + if ( '' !== $url ) { + $links[ $slot ] = $url; + } + } + return $links; +} + +/** + * Render the project metadata fields on the term edit screen. + * + * @param WP_Term $term Project term. + */ +function chrnx_render_project_edit_fields( $term ) { + chrnx_print_release_field( + 'chrnx_project_status', + __( 'Status', 'chrnx' ), + (string) get_term_meta( $term->term_id, 'chrnx_project_status', true ), + 'text', + __( 'Short and honest, for example Beta, Activo or Archivado.', 'chrnx' ) + ); + + foreach ( chrnx_get_project_link_slots() as $slot => $definition ) { + chrnx_print_release_field( + 'chrnx_project_' . $slot, + $definition['label'], + (string) get_term_meta( $term->term_id, 'chrnx_project_' . $slot, true ), + 'url', + __( 'HTTPS only. Leave empty to hide this icon.', 'chrnx' ) + ); + } + + chrnx_print_release_field( + 'chrnx_project_cover', + __( 'Cover attachment ID', 'chrnx' ), + (string) absint( get_term_meta( $term->term_id, 'chrnx_project_cover', true ) ), + 'text', + __( 'Leave empty to use the shared placeholder art.', 'chrnx' ) + ); +} +add_action( 'chrnx_project_edit_form_fields', 'chrnx_render_project_edit_fields' ); + +/** + * Persist project term metadata from the term edit screen. + * + * @param int $term_id Project term ID. + */ +function chrnx_save_project_meta( $term_id ) { + if ( ! chrnx_auth_release_meta() ) { + return; + } + // Core supplies and verifies the add/update term nonce on these screens. + $nonce = isset( $_POST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ) : ''; + if ( ! wp_verify_nonce( $nonce, 'update-tag_' . $term_id ) && ! wp_verify_nonce( $nonce, 'add-tag' ) ) { + return; + } + + foreach ( chrnx_get_project_meta_definitions() as $meta_key => $sanitize ) { + if ( ! isset( $_POST[ $meta_key ] ) ) { + continue; + } + $value = call_user_func( $sanitize, wp_unslash( $_POST[ $meta_key ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized by the mapped callback. + if ( '' === $value || 0 === $value ) { + delete_term_meta( $term_id, $meta_key ); + continue; + } + update_term_meta( $term_id, $meta_key, $value ); + } +} +add_action( 'edited_chrnx_project', 'chrnx_save_project_meta' ); +add_action( 'created_chrnx_project', 'chrnx_save_project_meta' ); diff --git a/inc/queries.php b/inc/queries.php index 66eb20a..6b22315 100644 --- a/inc/queries.php +++ b/inc/queries.php @@ -262,59 +262,6 @@ function chrnx_get_featured_story_ids( int $limit = 3 ): array { return $selected; } -/** - * Select projects for the Selected work stage: hand-picked first, then recent. - * - * Sticky already belongs to the home featured stories, so the editorial choice - * lives in its own per-post flag instead of competing for the same signal. - * - * @param int $limit Maximum projects, bounded to 12. - * @return int[] Selected project post IDs. - */ -function chrnx_get_selected_project_ids( int $limit = 3 ): array { - $limit = min( 12, max( 0, $limit ) ); - if ( 0 === $limit ) { - return array(); - } - - $topic_query = array( - array( - 'taxonomy' => 'chrnx_topic', - 'field' => 'slug', - 'terms' => 'projects', - ), - ); - - $selected = chrnx_get_eligible_editorial_post_ids( - array( - 'posts_per_page' => $limit, - 'tax_query' => $topic_query, - 'meta_query' => array( - array( - 'key' => 'chrnx_project_featured', - 'value' => '1', - ), - ), - ) - ); - - $remaining = $limit - count( $selected ); - if ( $remaining > 0 ) { - $selected = array_merge( - $selected, - chrnx_get_eligible_editorial_post_ids( - array( - 'posts_per_page' => $remaining, - 'post__not_in' => $selected, - 'tax_query' => $topic_query, - ) - ) - ); - } - - return $selected; -} - /** * Validate a request taxonomy slug against an existing editorial term. * @@ -374,7 +321,7 @@ function chrnx_sanitize_journal_search( $value ) { */ function chrnx_get_journal_archive_filter( $queried_object = null ): array { $queried_object = null === $queried_object ? get_queried_object() : $queried_object; - if ( ! $queried_object instanceof WP_Term || ! in_array( $queried_object->taxonomy, array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ), true ) ) { + if ( ! $queried_object instanceof WP_Term || ! in_array( $queried_object->taxonomy, array( 'chrnx_topic', 'chrnx_language', 'chrnx_show', 'chrnx_project' ), true ) ) { return array(); } @@ -431,7 +378,7 @@ function chrnx_get_journal_base_url() { $url = get_permalink( $queried ); return is_string( $url ) ? $url : ''; } - if ( $queried instanceof WP_Term && in_array( $queried->taxonomy, array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ), true ) ) { + if ( $queried instanceof WP_Term && in_array( $queried->taxonomy, array( 'chrnx_topic', 'chrnx_language', 'chrnx_show', 'chrnx_project' ), true ) ) { $url = get_term_link( $queried ); return is_wp_error( $url ) ? '' : $url; } @@ -486,7 +433,7 @@ function chrnx_get_full_journal_url() { function chrnx_get_journal_page_url( int $page, array $filters ) { $base_url = chrnx_get_journal_base_url(); $args = array(); - foreach ( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ) as $taxonomy ) { + foreach ( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show', 'chrnx_project' ) as $taxonomy ) { $slug = chrnx_validate_editorial_term_slug( $filters[ $taxonomy ] ?? '', $taxonomy ); if ( '' !== $slug ) { $args[ $taxonomy ] = $slug; @@ -526,7 +473,7 @@ function chrnx_get_journal_query_args( array $request ): array { ); $tax_query = array(); - foreach ( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ) as $taxonomy ) { + foreach ( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show', 'chrnx_project' ) as $taxonomy ) { $value = $request[ $taxonomy ] ?? ''; $slug = chrnx_validate_editorial_term_slug( $value, $taxonomy ); if ( '' !== $slug ) { @@ -687,6 +634,7 @@ function chrnx_get_topic_art_asset( string $topic_slug ): string { 'about-grunge' => 'about-grunge.png', 'placeholder-post' => 'placeholder-post.png', 'placeholder-release' => 'placeholder-release.png', + 'placeholder-project' => 'placeholder-project.png', 'projects-grunge' => 'projects-grunge.png', 'podcasts' => 'alter-ego-podcasts.png', 'life' => 'alter-ego-life.png', @@ -719,5 +667,9 @@ function chrnx_get_topic_art_dimensions( string $topic_slug ): array { return array( 1536, 1536 ); } + if ( 'placeholder-project' === $topic_slug ) { + return array( 1534, 1025 ); + } + return 'gaming' === $topic_slug ? array( 1024, 1536 ) : array( 1122, 1402 ); } diff --git a/inc/taxonomies.php b/inc/taxonomies.php index 1c4ec51..d3b1e88 100644 --- a/inc/taxonomies.php +++ b/inc/taxonomies.php @@ -54,6 +54,15 @@ function chrnx_get_editorial_taxonomies() { 'aqui-se-rompio-una-jerga' => __( 'Aquí se Rompió una Jerga', 'chrnx' ), ), ), + 'chrnx_project' => array( + 'singular' => __( 'Project', 'chrnx' ), + 'plural' => __( 'Projects', 'chrnx' ), + 'rest_base' => 'project', + 'terms' => array( + 'green-tea' => __( 'Green Tea', 'chrnx' ), + 'ailed' => __( 'Ailed', 'chrnx' ), + ), + ), ); } diff --git a/patterns/home-projects.php b/patterns/home-projects.php index be87743..60be292 100644 --- a/patterns/home-projects.php +++ b/patterns/home-projects.php @@ -16,8 +16,8 @@
-

- +

+

diff --git a/patterns/projects-landing.php b/patterns/projects-landing.php new file mode 100644 index 0000000..80c9ca1 --- /dev/null +++ b/patterns/projects-landing.php @@ -0,0 +1,30 @@ + + +
+ +
+ + +
+

+

+

+
+ +
+
+ +

+ +
+ diff --git a/scripts/build-responsive-images.sh b/scripts/build-responsive-images.sh index cdb209c..bf9039f 100755 --- a/scripts/build-responsive-images.sh +++ b/scripts/build-responsive-images.sh @@ -178,7 +178,7 @@ done chrnx_build_responsive_image "alter-ego-gaming-half-body" "alter-ego-gaming-half-body.png" printf '{\n\t"source": "alter-ego-gaming-half-body.png",\n\t"formats": [ "avif", "webp" ],\n\t"widths": [ 384, 768 ]\n}\n' > "$chrnx_image_build_output/alter-ego-gaming-half-body.json" -for chrnx_image_placeholder in placeholder-post placeholder-release; do +for chrnx_image_placeholder in placeholder-post placeholder-release placeholder-project; do # Placeholders sit at half opacity behind text; they do not need full quality. chrnx_build_responsive_image "$chrnx_image_placeholder" "$chrnx_image_placeholder.png" 48 40 printf '{\n\t"source": "%s.png",\n\t"formats": [ "avif", "webp" ],\n\t"widths": [ 384, 768 ]\n}\n' "$chrnx_image_placeholder" > "$chrnx_image_build_output/$chrnx_image_placeholder.json" @@ -228,14 +228,15 @@ chrnx_validate_staged_family "alter-ego-gaming-half-body" 384 768 chrnx_validate_staged_family "the-no-names-musician-cutout" 384 768 chrnx_validate_staged_family "placeholder-post" 384 768 chrnx_validate_staged_family "placeholder-release" 384 768 +chrnx_validate_staged_family "placeholder-project" 384 768 chrnx_validate_staged_family "the-no-names-collage" 384 768 chrnx_validate_staged_family "podcast-frequency-grunge" 384 768 1536 chrnx_validate_staged_family "about-grunge" 384 768 1536 chrnx_validate_staged_family "projects-grunge" 384 768 1536 set -- "$chrnx_image_stage"/* -if [ "$#" -ne 76 ]; then - echo "Responsive image staging expected 76 files, got $#." >&2 +if [ "$#" -ne 81 ]; then + echo "Responsive image staging expected 81 files, got $#." >&2 exit 1 fi for chrnx_image_staged in "$@"; do diff --git a/scripts/seed-test-content.php b/scripts/seed-test-content.php index 2a33069..7175b37 100644 --- a/scripts/seed-test-content.php +++ b/scripts/seed-test-content.php @@ -140,12 +140,9 @@ foreach ( $chrnx_seed_posts as $chrnx_seed_index => $chrnx_seed_post ) { wp_set_object_terms( $chrnx_seed_post_id, array(), 'chrnx_release', false ); } - foreach ( array( 'chrnx_episode_number', 'chrnx_episode_duration', 'canonical_episode_url', 'chrnx_project_featured' ) as $chrnx_seed_meta_key ) { + foreach ( array( 'chrnx_episode_number', 'chrnx_episode_duration', 'canonical_episode_url' ) as $chrnx_seed_meta_key ) { delete_post_meta( $chrnx_seed_post_id, $chrnx_seed_meta_key ); } - if ( ! empty( $chrnx_seed_post['projectFeatured'] ) ) { - update_post_meta( $chrnx_seed_post_id, 'chrnx_project_featured', true ); - } delete_post_meta( $chrnx_seed_post_id, 'chrnx_track_number' ); if ( isset( $chrnx_seed_post['trackNumber'] ) ) { update_post_meta( $chrnx_seed_post_id, 'chrnx_track_number', absint( $chrnx_seed_post['trackNumber'] ) ); diff --git a/style.css b/style.css index 353d4e3..b0ab40f 100644 --- a/style.css +++ b/style.css @@ -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.4 +Version: 0.4.5 Text Domain: chrnx */ diff --git a/templates/taxonomy-chrnx_project.html b/templates/taxonomy-chrnx_project.html new file mode 100644 index 0000000..501f2e3 --- /dev/null +++ b/templates/taxonomy-chrnx_project.html @@ -0,0 +1,12 @@ + + + +
+ + + + +
+ + + diff --git a/templates/taxonomy-chrnx_show.html b/templates/taxonomy-chrnx_show.html new file mode 100644 index 0000000..2a9d071 --- /dev/null +++ b/templates/taxonomy-chrnx_show.html @@ -0,0 +1,12 @@ + + + +
+ + + + +
+ + + diff --git a/tests/e2e/editorial-editor.spec.mjs b/tests/e2e/editorial-editor.spec.mjs index 80e7252..dc81e97 100644 --- a/tests/e2e/editorial-editor.spec.mjs +++ b/tests/e2e/editorial-editor.spec.mjs @@ -47,6 +47,4 @@ test( 'editorial and podcast controls initialize in the real post editor', async await openPanel( 'Topic' ); await page.getByRole( 'radio', { name: 'Projects', exact: true } ).check(); await expect( page.getByLabel( 'Episode number', { exact: true } ) ).toBeHidden(); - await openPanel( 'Project' ); - await expect( page.getByLabel( 'Show in Selected work', { exact: true } ) ).toBeVisible(); } ); diff --git a/tests/e2e/music-podcast-stages.spec.mjs b/tests/e2e/music-podcast-stages.spec.mjs index f129796..2cda062 100644 --- a/tests/e2e/music-podcast-stages.spec.mjs +++ b/tests/e2e/music-podcast-stages.spec.mjs @@ -557,11 +557,9 @@ const immutableSurfaces = [ 'alter-ego-research-768.webp', 'alter-ego-code-768.webp', ], - // Project names come from chrnx/selected-work: picked projects newest-first, - // then the most recent ones. This is the seeded order, not a frozen string. - headings: [ 'Selected work', 'Ailed', 'Expressive Tea', 'Published research' ], - paragraphs: [], - contentText: 'Selected work Ailed Expressive Tea Published research', + headings: [ 'Proyectos' ], + paragraphs: [ 'Lo que sobrevive a la loquera nocturna, con su repo y su estado real.' ], + contentText: 'Proyectos Lo que sobrevive a la loquera nocturna, con su repo y su estado real.', }, { name: 'About', diff --git a/tests/e2e/visual-states.spec.mjs b/tests/e2e/visual-states.spec.mjs index 2f33df4..6103147 100644 --- a/tests/e2e/visual-states.spec.mjs +++ b/tests/e2e/visual-states.spec.mjs @@ -193,7 +193,7 @@ test( 'home remains coherent at all approved review viewports', async ( { page } await expect( page.locator( 'main#chrnx-main' ) ).toBeVisible(); await expect( page.getByRole( 'contentinfo' ) ).toBeVisible(); await expect( page.getByRole( 'heading', { level: 1 } ) ).toHaveCount( 1 ); - await expect( page.getByText( 'Selected work', { exact: true } ) ).toBeVisible(); + await expect( page.getByText( 'Proyectos', { exact: true } ) ).toBeVisible(); await expect( page.getByText( 'The No Names', { exact: true } ).first() ).toBeVisible(); await expect( page.locator( 'picture source[type="image/avif"]' ).first() ).toHaveAttribute( 'srcset', @@ -516,7 +516,8 @@ test( 'lower home panels survive missing media and reduced motion', async ( { pa expect( musicFallback.stageOverflow ).toBeLessThanOrEqual( 1 ); 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-projects h2' ) ).toHaveText( 'Proyectos' ); + await expect( page.locator( '.chrnx-home-projects p' ) ).toHaveCount( 1 ); await expect( page.locator( '.chrnx-home-about-preview p' ) ).not.toBeEmpty(); await expect( page.locator( '.chrnx-subscribe-cta__link' ) ).toBeVisible(); diff --git a/tests/js/editor-project.test.js b/tests/js/editor-project.test.js deleted file mode 100644 index 590d160..0000000 --- a/tests/js/editor-project.test.js +++ /dev/null @@ -1,102 +0,0 @@ -const modulePath = '../../assets/js/editor-project.js'; - -function flatten( node ) { - if ( ! node || typeof node !== 'object' ) { - return []; - } - return [ node ].concat( ( node.children || [] ).flatMap( flatten ) ); -} - -function createWp( topicSlug = 'projects', meta = { unrelated: 'keep' } ) { - const editPost = jest.fn(); - const registerPlugin = jest.fn(); - const state = { meta, topic: [ 12 ] }; - const wp = { - components: { ToggleControl: 'ToggleControl' }, - i18n: { __: jest.fn( ( text ) => text ) }, - data: { - select: ( store ) => { - if ( store === 'core/editor' ) { - return { - getCurrentPostType: () => 'post', - getEditedPostAttribute: ( key ) => state[ key ], - }; - } - return { - getEntityRecord: () => ( topicSlug ? { id: 12, slug: topicSlug } : undefined ), - }; - }, - dispatch: () => ( { editPost } ), - useDispatch: ( store ) => wp.data.dispatch( store ), - useSelect: ( mapper ) => mapper( wp.data.select ), - }, - editPost: { PluginDocumentSettingPanel: 'PluginDocumentSettingPanel' }, - element: { - createElement: ( type, props, ...children ) => ( { type, props: props || {}, children } ), - }, - plugins: { registerPlugin }, - }; - return { wp, editPost, registerPlugin }; -} - -function renderPanel( context ) { - const { initialize } = require( modulePath ); - expect( initialize( context.wp ) ).toBe( true ); - const [ , plugin ] = context.registerPlugin.mock.calls[ 0 ]; - return plugin.render(); -} - -describe( 'project editor panel', () => { - beforeEach( () => { - jest.resetModules(); - } ); - - test( 'refuses to initialize without the required editor globals', () => { - const { initialize } = require( modulePath ); - expect( initialize( undefined ) ).toBe( false ); - expect( initialize( {} ) ).toBe( false ); - } ); - - test( 'renders the Selected work toggle only for the projects topic', () => { - const context = createWp( 'projects' ); - const toggles = flatten( renderPanel( context ) ).filter( - ( node ) => node.type === 'ToggleControl', - ); - expect( toggles ).toHaveLength( 1 ); - expect( toggles[ 0 ].props.checked ).toBe( false ); - } ); - - test.each( [ 'podcasts', 'code', null ] )( 'renders nothing for the %s topic', ( slug ) => { - expect( renderPanel( createWp( slug ) ) ).toBeNull(); - } ); - - test( 'reflects an existing flag and preserves unrelated meta when toggling', () => { - const context = createWp( 'projects', { unrelated: 'keep', chrnx_project_featured: true } ); - const toggle = flatten( renderPanel( context ) ).find( - ( node ) => node.type === 'ToggleControl', - ); - expect( toggle.props.checked ).toBe( true ); - - toggle.props.onChange( false ); - expect( context.editPost ).toHaveBeenCalledWith( { - meta: { unrelated: 'keep', chrnx_project_featured: false }, - } ); - } ); - - test( 'coerces the toggle value to a boolean', () => { - const context = createWp( 'projects' ); - const toggle = flatten( renderPanel( context ) ).find( - ( node ) => node.type === 'ToggleControl', - ); - - toggle.props.onChange( 'yes' ); - expect( context.editPost ).toHaveBeenCalledWith( { - meta: { unrelated: 'keep', chrnx_project_featured: true }, - } ); - } ); - - test( 'updateMeta ignores a missing dispatcher', () => { - const { updateMeta } = require( modulePath ); - expect( () => updateMeta( undefined, {}, 'chrnx_project_featured', true ) ).not.toThrow(); - } ); -} ); diff --git a/tests/php/EditorAssetsTest.php b/tests/php/EditorAssetsTest.php index 2002ca3..b78be22 100644 --- a/tests/php/EditorAssetsTest.php +++ b/tests/php/EditorAssetsTest.php @@ -45,7 +45,7 @@ class EditorAssetsTest extends WP_UnitTestCase { * Clear only the CHRNX editor script state. */ private function reset_editor_scripts() { - foreach ( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-project', 'chrnx-editor-track' ) as $handle ) { + foreach ( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-track' ) as $handle ) { wp_dequeue_script( $handle ); wp_deregister_script( $handle ); } @@ -83,14 +83,13 @@ class EditorAssetsTest extends WP_UnitTestCase { ) ); - $this->assertSame( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-project', 'chrnx-editor-track' ), $handles ); + $this->assertSame( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-track' ), $handles ); $expected_dependencies = array( 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins' ); foreach ( array( 'chrnx-editor-taxonomies' => 'assets/js/editor-taxonomies.js', 'chrnx-editor-podcast' => 'assets/js/editor-podcast.js', - 'chrnx-editor-project' => 'assets/js/editor-project.js', ) as $handle => $asset ) { $this->assertArrayHasKey( $handle, $scripts->registered ); @@ -123,7 +122,6 @@ class EditorAssetsTest extends WP_UnitTestCase { do_action( 'enqueue_block_editor_assets' ); $this->assertFalse( wp_script_is( 'chrnx-editor-taxonomies', 'enqueued' ) ); $this->assertFalse( wp_script_is( 'chrnx-editor-podcast', 'enqueued' ) ); - $this->assertFalse( wp_script_is( 'chrnx-editor-project', 'enqueued' ) ); $this->assertFalse( wp_script_is( 'chrnx-editor-track', 'enqueued' ) ); } } diff --git a/tests/php/PatternsTest.php b/tests/php/PatternsTest.php index c6dc526..db63f89 100644 --- a/tests/php/PatternsTest.php +++ b/tests/php/PatternsTest.php @@ -205,9 +205,9 @@ class PatternsTest extends WP_UnitTestCase { public function test_character_led_patterns_use_the_exact_shared_stage_api() { $contracts = array( 'home-projects' => array( - 'heading' => 'Selected work', - // The project names come from chrnx/selected-work now, not the pattern. - 'order' => array( 'Selected work' ), + 'heading' => 'Proyectos', + // The project names come from the project list query now, not the pattern. + 'order' => array( 'Proyectos' ), 'art' => 'alter-ego-code-768.webp', 'art_alt' => '', 'atmosphere' => 'chrnx-character-stage__secondary-art', diff --git a/tests/php/ProjectBlocksTest.php b/tests/php/ProjectBlocksTest.php new file mode 100644 index 0000000..8a995d3 --- /dev/null +++ b/tests/php/ProjectBlocksTest.php @@ -0,0 +1,180 @@ +term->create( + array( + 'taxonomy' => 'chrnx_project', + 'name' => 'Green Tea', + 'slug' => 'green-tea-test', + ) + ); + update_term_meta( $term_id, 'chrnx_project_status', 'Beta' ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'chrnx-project-card', $markup ); + $this->assertStringContainsString( 'Green Tea', $markup ); + $this->assertStringContainsString( 'Beta', $markup ); + } + + /** + * Ensure stored project links render with their platform icons. + */ + public function test_project_list_renders_stored_links() { + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'name' => 'Matcha CLI', + 'slug' => 'matcha-cli-test', + ) + ); + update_term_meta( $term_id, 'chrnx_project_repo', 'https://example.com/repo' ); + update_term_meta( $term_id, 'chrnx_project_package', 'https://example.com/package' ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'chrnx-platform-links', $markup ); + $this->assertStringContainsString( 'https://example.com/repo', $markup ); + $this->assertStringContainsString( 'https://example.com/package', $markup ); + } + + /** + * Ensure a project without a cover still renders art. + */ + public function test_project_without_cover_uses_placeholder_art() { + self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'slug' => 'coverless-test', + ) + ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'chrnx-project-card__fallback', $markup ); + } + + /** + * Ensure the detail block renders the queried project header. + */ + public function test_project_detail_renders_the_queried_term() { + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'name' => 'Ailed', + 'slug' => 'ailed-test', + 'description' => 'A chess engine that feels.', + ) + ); + update_term_meta( $term_id, 'chrnx_project_repo', 'https://github.com/example/ailed' ); + update_term_meta( $term_id, 'chrnx_project_status', 'Activo' ); + + $this->go_to( get_term_link( $term_id ) ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'A chess engine that feels.', $markup ); + $this->assertStringContainsString( 'https://github.com/example/ailed', $markup ); + $this->assertStringContainsString( 'Activo', $markup ); + } + + /** + * Ensure the detail block renders nothing outside a project archive. + */ + public function test_project_detail_is_silent_off_its_archive() { + $this->go_to( home_url( '/' ) ); + + $this->assertSame( '', trim( do_blocks( '' ) ) ); + } + + /** + * Ensure a list card falls back to placeholder art when the stored cover + * attachment no longer exists, instead of rendering a blank art column. + */ + public function test_project_list_with_deleted_cover_uses_placeholder_art() { + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'slug' => 'deleted-cover-list-test', + ) + ); + update_term_meta( $term_id, 'chrnx_project_cover', 999999 ); + + $markup = do_blocks( '' ); + + // Scope the assertion to this term's own card: the taxonomy query is + // unfiltered, so other projects' cards must not mask a broken one. + $needle = 'chrnx_project=deleted-cover-list-test'; + $link_offset = strpos( $markup, $needle ); + $this->assertNotFalse( $link_offset, 'Expected a card linking to the test project.' ); + $card_start = strrpos( substr( $markup, 0, $link_offset ), '', $link_offset ); + $card = substr( $markup, $card_start, $card_end - $card_start ); + + $this->assertStringContainsString( 'chrnx-project-card__fallback', $card ); + $this->assertStringNotContainsString( 'chrnx-project-card__cover', $card ); + } + + /** + * Ensure the detail block falls back to placeholder art when the stored + * cover attachment no longer exists, instead of rendering a blank art column. + */ + public function test_project_detail_with_deleted_cover_uses_placeholder_art() { + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'slug' => 'deleted-cover-detail-test', + ) + ); + update_term_meta( $term_id, 'chrnx_project_cover', 999999 ); + + $this->go_to( get_term_link( $term_id ) ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'chrnx-project-detail__fallback', $markup ); + $this->assertStringNotContainsString( 'chrnx-project-detail__cover', $markup ); + } + + /** + * Ensure a project archive filters the journal to that project. + */ + public function test_project_archive_filters_the_journal() { + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'slug' => 'filter-test', + ) + ); + $mine = self::factory()->post->create( array( 'post_title' => 'Belongs to the project' ) ); + self::factory()->post->create( array( 'post_title' => 'Unrelated post' ) ); + wp_set_object_terms( $mine, array( $term_id ), 'chrnx_project' ); + + $this->go_to( get_term_link( $term_id ) ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'Belongs to the project', $markup ); + $this->assertStringNotContainsString( 'Unrelated post', $markup ); + } +} diff --git a/tests/php/ProjectMetaTest.php b/tests/php/ProjectMetaTest.php new file mode 100644 index 0000000..d47e38f --- /dev/null +++ b/tests/php/ProjectMetaTest.php @@ -0,0 +1,55 @@ +assertArrayHasKey( $meta_key, $registered ); + } + } + + /** + * Ensure a plain http repository URL is rejected. + */ + public function test_project_links_reject_insecure_urls() { + $term_id = self::factory()->term->create( array( 'taxonomy' => 'chrnx_project' ) ); + update_term_meta( $term_id, 'chrnx_project_repo', 'http://example.com/repo' ); + + $this->assertArrayNotHasKey( 'repo', chrnx_get_project_links( $term_id ) ); + } + + /** + * Ensure stored https links come back keyed by their slot. + */ + public function test_project_links_return_stored_https_urls() { + $term_id = self::factory()->term->create( array( 'taxonomy' => 'chrnx_project' ) ); + update_term_meta( $term_id, 'chrnx_project_repo', 'https://github.com/Expressive-Tea/green-tea' ); + update_term_meta( $term_id, 'chrnx_project_package', 'https://www.npmjs.com/package/@green-tea/core' ); + + $links = chrnx_get_project_links( $term_id ); + + $this->assertSame( 'https://github.com/Expressive-Tea/green-tea', $links['repo'] ); + $this->assertSame( 'https://www.npmjs.com/package/@green-tea/core', $links['package'] ); + $this->assertArrayNotHasKey( 'site', $links ); + } +} diff --git a/tests/php/TaxonomiesTest.php b/tests/php/TaxonomiesTest.php index 9161cad..2274fff 100644 --- a/tests/php/TaxonomiesTest.php +++ b/tests/php/TaxonomiesTest.php @@ -50,6 +50,13 @@ class TaxonomiesTest extends WP_UnitTestCase { 'silicon-ranch' => 'Silicon Ranch', ), ), + 'chrnx_project' => array( + 'rest_base' => 'project', + 'terms' => array( + 'green-tea' => 'Green Tea', + 'ailed' => 'Ailed', + ), + ), ); } diff --git a/tests/smoke/templates.test.mjs b/tests/smoke/templates.test.mjs index f22053e..e073025 100644 --- a/tests/smoke/templates.test.mjs +++ b/tests/smoke/templates.test.mjs @@ -2,7 +2,7 @@ import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import test from 'node:test'; -const templates = [ 'home', 'single', 'page', 'archive', 'search', '404' ]; +const templates = [ 'home', 'single', 'page', 'archive', 'search', '404', 'taxonomy-chrnx_project', 'taxonomy-chrnx_show', 'taxonomy-chrnx_release' ]; const readTemplate = (name) => readFile(new URL(`../../templates/${name}.html`, import.meta.url), 'utf8'); function assertBalancedBlockMarkup(markup, name) { @@ -104,3 +104,15 @@ test('404 offers concise recovery with search, Journal, and home links', async ( assert.match(markup, /wp:chrnx\/journal-link/); assert.doesNotMatch(markup, /"url":"\//); }); + +test('taxonomy-chrnx_project surfaces the project detail and its post stream', async () => { + const markup = await readTemplate('taxonomy-chrnx_project'); + assert.match(markup, /wp:chrnx\/project-detail/); + assert.match(markup, /wp:chrnx\/journal-stream/); +}); + +test('taxonomy-chrnx_show surfaces show links and its episode stream', async () => { + const markup = await readTemplate('taxonomy-chrnx_show'); + assert.match(markup, /wp:chrnx\/show-links/); + assert.match(markup, /wp:chrnx\/journal-stream/); +}); diff --git a/tests/smoke/visual-integration.test.mjs b/tests/smoke/visual-integration.test.mjs index 89335db..0282564 100644 --- a/tests/smoke/visual-integration.test.mjs +++ b/tests/smoke/visual-integration.test.mjs @@ -140,7 +140,7 @@ test( 'media and review documentation matches the current inventory and cleanup const readme = read( 'README.md' ); const plan = read( 'docs/superpowers/plans/2026-08-13-music-podcast-grunge-stages.md' ); - assert.match( readme, /76 generated files: 62 binary derivatives and 14 manifests/ ); + assert.match( readme, /81 generated files: 66 binary derivatives and 15 manifests/ ); assert.match( readme, /eleven portrait families at 384 px and 768 px/ ); assert.match( readme, /three\s+landscape background families \(Podcast, About, and Projects\) at 384 px, 768 px,\s+and 1536 px/ ); for ( const budget of [ '160 KiB', '260 KiB', '400 KiB', '340 KiB', '620 KiB', '3 MiB' ] ) { @@ -469,7 +469,7 @@ test( 'all approved responsive media rebuild byte-identically within payload bou 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, 76 ); + assert.equal( names.length, 81 ); for ( const name of [ 'alter-ego-gaming-half-body-384.avif', 'alter-ego-gaming-half-body-384.webp', @@ -684,7 +684,7 @@ printf 'partial-build-%s\n' "$count" > "$output" } } ); -test( 'responsive promotion failure restores all 76 prior files', () => { +test( 'responsive promotion failure restores all 81 prior files', () => { const output = mkdtempSync( join( tmpdir(), 'chrnx-promotion-output-' ) ); const fakeBin = mkdtempSync( join( tmpdir(), 'chrnx-promotion-bin-' ) ); const external = mkdtempSync( join( tmpdir(), 'chrnx-promotion-external-' ) ); @@ -697,7 +697,7 @@ test( 'responsive promotion failure restores all 76 prior files', () => { try { execFileSync( './scripts/build-responsive-images.sh', [ output ], { cwd: projectRoot } ); const published = new Map( readdirSync( output ).map( ( name ) => [ name, sha256( join( output, name ) ) ] ) ); - assert.equal( published.size, 76 ); + assert.equal( published.size, 81 ); writeFileSync( sentinel, 'external-sentinel' ); const sentinelHash = sha256( sentinel ); const realMv = execFileSync( '/bin/sh', [ '-c', 'command -v mv' ], { encoding: 'utf8' } ).trim();