Skip to content

Commit

Permalink
Merge branch 'release/2.29.20'
Browse files Browse the repository at this point in the history
  • Loading branch information
Misplon committed Aug 8, 2024
2 parents 4f1b40c + 51ff379 commit 039cbeb
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 47 deletions.
5 changes: 4 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
== Changelog ==

= 2.29.19 – 21 July June 2024 =
= 2.29.20 – 08 August 2024 =
* Rank Math: Resolved content analysis issue when multiple blocks in use.

= 2.29.19 – 21 July 2024 =
* Further improvements for attribute name handling.
* Layout Directory: Resolved an issue with fetching page two.

Expand Down
129 changes: 84 additions & 45 deletions js/seo-compat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global jQuery, YoastSEO, _, panelsOptions */

jQuery(function($){
jQuery( function( $ ) {


var SiteOriginSeoCompat = function() {
Expand All @@ -11,57 +11,96 @@ jQuery(function($){
}

if ( typeof rankMathEditor !== 'undefined' ) {
wp.hooks.addFilter( 'rank_math_content', 'SiteOriginSeoCompat', this.contentModification );
wp.hooks.addFilter( 'rank_math_content', 'SiteOriginSeoCompat', this.rankMath );
}

};

SiteOriginSeoCompat.prototype.contentModification = function( data ) {
function isBlockEditorPanelsEnabled() {
return typeof window.soPanelsBuilderView !== 'undefined' && $( '.block-editor-page' ).length;
}

function isClassicEditorPanelsEnabled() {
return $( '#so-panels-panels.attached-to-editor' ).is( ':visible' );
}

SiteOriginSeoCompat.prototype.rankMath = function( data ) {
if ( ! data ) {
return data;
}

var isBlockEditorPanelsEnabled = $( '.block-editor-page' ).length && typeof window.soPanelsBuilderView !== 'undefined';
var isClassicEditorPanelsEnabled = $( '#so-panels-panels.attached-to-editor' ).is( ':visible' );
if ( isClassicEditorPanelsEnabled() && ! isBlockEditorPanelsEnabled() ) {
data = SiteOriginSeoCompat.prototype.contentModification( data );
return data;
}

if ( ! isBlockEditorPanelsEnabled() ) {
return data;
}

const soBlock = data.match(
/<!--\s*wp:siteorigin-panels\/layout-block[\s\S]*?\/-->/g
);

// Replace any found SO Layout blocks with the rendered contents.
if ( soBlock ) {
soBlock.forEach( function( block ) {
data = data.replace( block, SiteOriginSeoCompat.prototype.contentModification( block ) );
} );
}

return data;
}

SiteOriginSeoCompat.prototype.contentModification = function( data ) {
const isBlockEditor = isBlockEditorPanelsEnabled();
// Check if the editor has Page Builder Enabled before proceeding.
if ( isClassicEditorPanelsEnabled || isBlockEditorPanelsEnabled ) {

var whitelist = [
'p', 'a', 'img', 'caption', 'br',
'blockquote', 'cite',
'em', 'strong', 'i', 'b',
'q',
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
'ul', 'ol', 'li',
'table', 'tr', 'th', 'td'
].join( ',' );

var extractContent = function( data ) {
var $data = $( data );

if ( $data.find( '.so-panel' ).length === 0 ) {
// Skip this for empty pages
return data;
}

// Remove elements that have no content analysis value.
$data.find( 'iframe, script, style, link' ).remove();

$data.find( "*") .not( whitelist ).each( function() {
var content = $( this ).contents();
$( this ).replaceWith( content );
} );

return $data.html();
};

if ( ! Array.isArray( window.soPanelsBuilderView ) ) {
data = extractContent( window.soPanelsBuilderView.contentPreview );
} else {
var $this = this;
data = null;
window.soPanelsBuilderView.forEach( function( panel ) {
data += extractContent( panel.contentPreview );
} );
if (
window.soPanelsBuilderView === undefined ||
(
! isClassicEditorPanelsEnabled() &&
! isBlockEditor
)
) {
return;
}

var whitelist = [
'p', 'a', 'img', 'caption', 'br',
'blockquote', 'cite',
'em', 'strong', 'i', 'b',
'q',
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
'ul', 'ol', 'li',
'table', 'tr', 'th', 'td'
].join( ',' );

var extractContent = function( data ) {
var $data = $( data );

if ( $data.find( '.so-panel' ).length === 0 ) {
// Skip this for empty pages
return data;
}

// Remove elements that have no content analysis value.
$data.find( 'iframe, script, style, link' ).remove();

$data.find( "*") .not( whitelist ).each( function() {
var content = $( this ).contents();
$( this ).replaceWith( content );
} );

return $data.html();
};

if ( ! Array.isArray( window.soPanelsBuilderView ) ) {
data = extractContent( window.soPanelsBuilderView.contentPreview );
} else {
data = null;
window.soPanelsBuilderView.forEach( function( panel ) {
data += extractContent( panel.contentPreview );
} );
}

return data;
Expand All @@ -77,4 +116,4 @@ jQuery(function($){
}
);
}
});
} );
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ SiteOrigin offers a single premium plugin that enhances and extends Page Builder

== Changelog ==

= 2.29.19 – 21 July June 2024 =
= 2.29.20 – 08 August 2024 =
* Rank Math: Resolved content analysis issue when multiple blocks in use.

= 2.29.19 – 21 July 2024 =
* Further improvements for attribute name handling.
* Layout Directory: Resolved an issue with fetching page two.

Expand Down

0 comments on commit 039cbeb

Please sign in to comment.