feat: give releases and tracks their own pages
Albums were three hardcoded cards. An album is a chrnx_release term now, with cover, status and listening links; its archive is the album page with an ordered tracklist. A song is a post carrying lyrics and notes, its track number, and the audio. The player is a native audio element, no library and no JavaScript. Platform icons render only when a URL exists, so nothing points at a service the release is not on yet. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
13 files changed
+867
-16
No files matched your search
@@ -0,0 +1,50 @@
|
||||
( function () {
|
||||
'use strict';
|
||||
|
||||
function initialize( doc, media ) {
|
||||
const input = doc.querySelector( '[data-chrnx-release-cover]' );
|
||||
const button = doc.querySelector( '[data-chrnx-release-cover-pick]' );
|
||||
const preview = doc.querySelector( '[data-chrnx-release-cover-preview]' );
|
||||
if ( ! input || ! button || ! preview || typeof media !== 'function' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let frame = null;
|
||||
button.addEventListener( 'click', function () {
|
||||
if ( ! frame ) {
|
||||
frame = media( {
|
||||
title: button.textContent,
|
||||
library: { type: 'image' },
|
||||
multiple: false,
|
||||
} );
|
||||
frame.on( 'select', function () {
|
||||
const attachment = frame.state().get( 'selection' ).first().toJSON();
|
||||
input.value = attachment.id;
|
||||
const source = attachment.sizes?.medium?.url || attachment.url;
|
||||
preview.innerHTML = '';
|
||||
const image = doc.createElement( 'img' );
|
||||
image.src = source;
|
||||
image.alt = attachment.alt || '';
|
||||
image.style.maxWidth = '240px';
|
||||
image.style.height = 'auto';
|
||||
preview.append( image );
|
||||
} );
|
||||
}
|
||||
frame.open();
|
||||
} );
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( typeof module !== 'undefined' && module.exports ) {
|
||||
module.exports = { initialize };
|
||||
} else if ( typeof document !== 'undefined' ) {
|
||||
const start = function () {
|
||||
initialize( document, window.wp && window.wp.media );
|
||||
};
|
||||
if ( document.readyState === 'loading' ) {
|
||||
document.addEventListener( 'DOMContentLoaded', start, { once: true } );
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
}
|
||||
} )();
|
||||
@@ -0,0 +1,165 @@
|
||||
( function ( factory ) {
|
||||
if ( typeof module === 'object' && module.exports ) {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
factory().initialize( window.wp );
|
||||
}
|
||||
} )( function () {
|
||||
'use strict';
|
||||
|
||||
function platformFields( __ ) {
|
||||
return [
|
||||
{ key: 'chrnx_track_url_suno', label: __( 'Suno URL', 'chrnx' ) },
|
||||
{ key: 'chrnx_track_url_spotify', label: __( 'Spotify URL', 'chrnx' ) },
|
||||
{ key: 'chrnx_track_url_apple', label: __( 'Apple Music URL', 'chrnx' ) },
|
||||
];
|
||||
}
|
||||
|
||||
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.TextControl &&
|
||||
wp.components.Button &&
|
||||
wp.blockEditor &&
|
||||
wp.blockEditor.MediaUpload &&
|
||||
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 );
|
||||
const el = wp.element.createElement;
|
||||
|
||||
function TrackPanel() {
|
||||
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 !== 'music' ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const meta = editorState.meta;
|
||||
const setMeta = function ( key, value ) {
|
||||
updateMeta( editorDispatch.editPost, meta, key, value );
|
||||
};
|
||||
|
||||
return el(
|
||||
wp.editPost.PluginDocumentSettingPanel,
|
||||
{ name: 'chrnx-track', title: __( 'Track', 'chrnx' ) },
|
||||
el( wp.components.TextControl, {
|
||||
label: __( 'Track number', 'chrnx' ),
|
||||
type: 'number',
|
||||
min: 0,
|
||||
value: meta.chrnx_track_number ?? '',
|
||||
onChange( value ) {
|
||||
const number = Number.parseInt( value, 10 );
|
||||
setMeta( 'chrnx_track_number', Number.isInteger( number ) ? Math.max( 0, number ) : 0 );
|
||||
},
|
||||
} ),
|
||||
el( wp.blockEditor.MediaUpload, {
|
||||
allowedTypes: [ 'audio' ],
|
||||
value: meta.chrnx_track_audio || 0,
|
||||
onSelect( attachment ) {
|
||||
setMeta( 'chrnx_track_audio', attachment?.id ? Number( attachment.id ) : 0 );
|
||||
},
|
||||
render( { open } ) {
|
||||
return el(
|
||||
wp.components.Button,
|
||||
{ variant: 'secondary', onClick: open },
|
||||
meta.chrnx_track_audio
|
||||
? __( 'Replace audio file', 'chrnx' )
|
||||
: __( 'Select audio file', 'chrnx' ),
|
||||
);
|
||||
},
|
||||
} ),
|
||||
meta.chrnx_track_audio
|
||||
? el(
|
||||
wp.components.Button,
|
||||
{
|
||||
variant: 'link',
|
||||
isDestructive: true,
|
||||
onClick() {
|
||||
setMeta( 'chrnx_track_audio', 0 );
|
||||
},
|
||||
},
|
||||
__( 'Remove audio file', 'chrnx' ),
|
||||
)
|
||||
: null,
|
||||
...platformFields( __ ).map( function ( platform ) {
|
||||
return el( wp.components.TextControl, {
|
||||
key: platform.key,
|
||||
label: platform.label,
|
||||
type: 'url',
|
||||
value: meta[ platform.key ] || '',
|
||||
onChange( value ) {
|
||||
setMeta( platform.key, value );
|
||||
},
|
||||
} );
|
||||
} ),
|
||||
);
|
||||
}
|
||||
|
||||
wp.plugins.registerPlugin( 'chrnx-track-meta', { render: TrackPanel } );
|
||||
return true;
|
||||
}
|
||||
|
||||
return { initialize, updateMeta, platformFields };
|
||||
} );
|
||||
Reference in new issue
Block a user