From 64c71cfe437df914accd2b8997b2e3b4269df2f3 Mon Sep 17 00:00:00 2001 From: Rasmy Nguyen Date: Mon, 13 Jan 2025 18:06:03 -0500 Subject: [PATCH] fix: handle author link --- src/bylines/index.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/bylines/index.js b/src/bylines/index.js index a65d8b2e4d..fe785d5ef9 100644 --- a/src/bylines/index.js +++ b/src/bylines/index.js @@ -20,6 +20,16 @@ const BYLINE_ID = 'newspack-byline'; const META_KEY_ACTIVE = '_newspack_byline_active'; const META_KEY_BYLINE = '_newspack_byline'; +/** + * Get author url given the author id. + * + * @param {number} authorId The author ID. + * + * @return {string} The author URL. + */ +const getAuthorUrl = authorId => { + return `/author/${ authorId }`; +} /** * Prepend byline to content in the Editor. @@ -35,6 +45,11 @@ const prependBylineToContent = byline => { bylineEl.id = BYLINE_ID; contentEl.insertBefore( bylineEl, contentEl.firstChild ); } + // Search for tag and replace it with a link to the author page. + byline = byline.replace( //g, ( match, authorId ) => { + return ``; + } ); + byline = byline.replace( /<\/Author>/g, '' ); bylineEl.innerHTML = byline; } }; @@ -56,6 +71,11 @@ const BylinesSettingsPanel = () => { } // Byline change handler. const handleBylineChange = value => { + const tags = value.match( /<[^>]+>/g ); + if ( tags && tags.some( tag => ! tag.startsWith( ' tag is allowed.', 'newspack-plugin' ) ); // eslint-disable-line no-alert + return; + } editPost( { meta: { [ META_KEY_BYLINE ]: value } } ); setByline( value ); } @@ -88,4 +108,3 @@ registerPlugin( 'newspack-bylines-sidebar', { render: BylinesSettingsPanel, icon: false, } ); -