v3.6.0
This commit is contained in:
parent
1086e369e3
commit
3cf187303e
2 changed files with 2307 additions and 1000 deletions
|
|
@ -17,6 +17,45 @@
|
|||
initSearch();
|
||||
initStats();
|
||||
initTooltips();
|
||||
initRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the conditional-rules table (add / remove rows)
|
||||
*/
|
||||
function initRules() {
|
||||
// Add rule: clone the last row and clear its inputs.
|
||||
$( '.noindex-seo-rule-add' ).on(
|
||||
'click',
|
||||
function () {
|
||||
const $rows = $( '.noindex-seo-rule-rows' );
|
||||
const max = parseInt( $rows.data( 'max-rules' ) || 20, 10 );
|
||||
|
||||
if ( $rows.find( '.noindex-seo-rule-row' ).length >= max ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const $clone = $rows.find( '.noindex-seo-rule-row' ).last().clone();
|
||||
$clone.find( 'input' ).val( '' );
|
||||
$rows.append( $clone );
|
||||
}
|
||||
);
|
||||
|
||||
// Remove rule: drop the row, or clear it when it is the last one left.
|
||||
$( document ).on(
|
||||
'click',
|
||||
'.noindex-seo-rule-remove',
|
||||
function () {
|
||||
const $row = $( this ).closest( '.noindex-seo-rule-row' );
|
||||
const $rows = $( this ).closest( '.noindex-seo-rule-rows' );
|
||||
|
||||
if ( $rows.find( '.noindex-seo-rule-row' ).length > 1 ) {
|
||||
$row.remove();
|
||||
} else {
|
||||
$row.find( 'input' ).val( '' );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
/**
|
||||
* Noindex SEO - Gutenberg Sidebar Panel
|
||||
* Version: 2.0.0
|
||||
* Version: 3.0.0
|
||||
*
|
||||
* Provides a native Gutenberg sidebar panel for controlling robots directives
|
||||
* on individual posts and pages.
|
||||
* on individual posts and pages: boolean flags plus the value directives
|
||||
* introduced in 3.6.0 (max-snippet, max-image-preview, max-video-preview,
|
||||
* unavailable_after).
|
||||
*
|
||||
* @package noindex-seo
|
||||
*/
|
||||
|
|
@ -11,11 +13,21 @@
|
|||
(function (wp) {
|
||||
const { registerPlugin } = wp.plugins;
|
||||
const { PluginDocumentSettingPanel } = wp.editPost;
|
||||
const { CheckboxControl, PanelRow } = wp.components;
|
||||
const { CheckboxControl, PanelRow, SelectControl, TextControl } = wp.components;
|
||||
const { useSelect, useDispatch } = wp.data;
|
||||
const { createElement: el } = wp.element;
|
||||
const { __ } = wp.i18n;
|
||||
|
||||
/**
|
||||
* Boolean directives: checkbox controls backed by integer meta (0/1).
|
||||
*/
|
||||
const booleanDirectives = ['noindex', 'nofollow', 'noarchive', 'nosnippet', 'noimageindex', 'notranslate'];
|
||||
|
||||
/**
|
||||
* Value directives: inputs backed by string meta ('' = off).
|
||||
*/
|
||||
const valueDirectives = ['max-snippet', 'max-image-preview', 'max-video-preview', 'unavailable_after'];
|
||||
|
||||
/**
|
||||
* Robots Directives Sidebar Panel Component
|
||||
*/
|
||||
|
|
@ -29,34 +41,42 @@
|
|||
|
||||
const { editPost } = useDispatch( 'core/editor' );
|
||||
|
||||
// Current values.
|
||||
const override = Boolean( postMeta._noindex_seo_override );
|
||||
const noindex = Boolean( postMeta._noindex_seo_noindex );
|
||||
const nofollow = Boolean( postMeta._noindex_seo_nofollow );
|
||||
const noarchive = Boolean( postMeta._noindex_seo_noarchive );
|
||||
const nosnippet = Boolean( postMeta._noindex_seo_nosnippet );
|
||||
const noimageindex = Boolean( postMeta._noindex_seo_noimageindex );
|
||||
// Current override state.
|
||||
const override = Boolean( postMeta._noindex_seo_override );
|
||||
|
||||
// Update meta function.
|
||||
const updateMeta = function (key, value) {
|
||||
// Update a boolean meta value (0/1).
|
||||
const updateBoolean = function (key, value) {
|
||||
const newMeta = {};
|
||||
newMeta[key] = value ? 1 : 0;
|
||||
editPost( { meta: newMeta } );
|
||||
};
|
||||
|
||||
// Update a value-directive meta value (string, '' = off).
|
||||
const updateValue = function (key, value) {
|
||||
const newMeta = {};
|
||||
newMeta[key] = value || '';
|
||||
editPost( { meta: newMeta } );
|
||||
};
|
||||
|
||||
// Clear all directive meta values.
|
||||
const clearAllDirectives = function () {
|
||||
const directives = ['noindex', 'nofollow', 'noarchive', 'nosnippet', 'noimageindex'];
|
||||
directives.forEach(
|
||||
const newMeta = {};
|
||||
booleanDirectives.forEach(
|
||||
function (directive) {
|
||||
updateMeta( '_noindex_seo_' + directive, false );
|
||||
newMeta['_noindex_seo_' + directive] = 0;
|
||||
}
|
||||
);
|
||||
valueDirectives.forEach(
|
||||
function (directive) {
|
||||
newMeta['_noindex_seo_' + directive] = '';
|
||||
}
|
||||
);
|
||||
editPost( { meta: newMeta } );
|
||||
};
|
||||
|
||||
// Handle override toggle.
|
||||
const handleOverrideChange = function (value) {
|
||||
updateMeta( '_noindex_seo_override', value );
|
||||
updateBoolean( '_noindex_seo_override', value );
|
||||
|
||||
// If disabling override, clear all directives.
|
||||
if ( ! value) {
|
||||
|
|
@ -64,26 +84,91 @@
|
|||
}
|
||||
};
|
||||
|
||||
// Get active directives for preview.
|
||||
// Build the preview list: names for booleans, name:value for values.
|
||||
const activeDirectives = [];
|
||||
if (override) {
|
||||
if (noindex) {
|
||||
activeDirectives.push( 'noindex' );
|
||||
}
|
||||
if (nofollow) {
|
||||
activeDirectives.push( 'nofollow' );
|
||||
}
|
||||
if (noarchive) {
|
||||
activeDirectives.push( 'noarchive' );
|
||||
}
|
||||
if (nosnippet) {
|
||||
activeDirectives.push( 'nosnippet' );
|
||||
}
|
||||
if (noimageindex) {
|
||||
activeDirectives.push( 'noimageindex' );
|
||||
}
|
||||
booleanDirectives.forEach(
|
||||
function (directive) {
|
||||
if ( Boolean( postMeta['_noindex_seo_' + directive] ) ) {
|
||||
activeDirectives.push( directive );
|
||||
}
|
||||
}
|
||||
);
|
||||
valueDirectives.forEach(
|
||||
function (directive) {
|
||||
const value = postMeta['_noindex_seo_' + directive];
|
||||
if ( value ) {
|
||||
activeDirectives.push( directive + ':' + value );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Boolean directive rows.
|
||||
const booleanRows = booleanDirectives.map(
|
||||
function (directive) {
|
||||
return el(
|
||||
PanelRow,
|
||||
{ key: directive + '-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: __( directive, 'noindex-seo' ),
|
||||
checked: Boolean( postMeta['_noindex_seo_' + directive] ),
|
||||
onChange: function (value) {
|
||||
updateBoolean( '_noindex_seo_' + directive, value ); },
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// Value directive rows.
|
||||
const valueRows = valueDirectives.map(
|
||||
function (directive) {
|
||||
const metaKey = '_noindex_seo_' + directive;
|
||||
|
||||
if ( 'max-image-preview' === directive) {
|
||||
return el(
|
||||
PanelRow,
|
||||
{ key: directive + '-row' },
|
||||
el(
|
||||
SelectControl,
|
||||
{
|
||||
label: __( directive, 'noindex-seo' ),
|
||||
value: postMeta[metaKey] || '',
|
||||
options: [
|
||||
{ value: '', label: __( 'Off', 'noindex-seo' ) },
|
||||
{ value: 'none', label: __( 'none', 'noindex-seo' ) },
|
||||
{ value: 'standard', label: __( 'standard', 'noindex-seo' ) },
|
||||
{ value: 'large', label: __( 'large', 'noindex-seo' ) },
|
||||
],
|
||||
onChange: function (value) {
|
||||
updateValue( metaKey, value ); },
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const inputType = ( 'unavailable_after' === directive) ? 'datetime-local' : 'number';
|
||||
|
||||
return el(
|
||||
PanelRow,
|
||||
{ key: directive + '-row' },
|
||||
el(
|
||||
TextControl,
|
||||
{
|
||||
type: inputType,
|
||||
label: __( directive, 'noindex-seo' ),
|
||||
value: ( postMeta[metaKey] || '' ).toString().replace( ' ', 'T' ),
|
||||
onChange: function (value) {
|
||||
updateValue( metaKey, value ); },
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return el(
|
||||
PluginDocumentSettingPanel,
|
||||
{
|
||||
|
|
@ -119,141 +204,68 @@
|
|||
}
|
||||
},
|
||||
[
|
||||
el(
|
||||
'p',
|
||||
{
|
||||
key: 'directives-label',
|
||||
style: {
|
||||
fontSize: '12px',
|
||||
fontWeight: '600',
|
||||
marginBottom: '12px',
|
||||
color: '#1e1e1e',
|
||||
}
|
||||
},
|
||||
__( 'Robots Directives:', 'noindex-seo' )
|
||||
),
|
||||
|
||||
el(
|
||||
PanelRow,
|
||||
{ key: 'noindex-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: '🔍 ' + __( 'noindex', 'noindex-seo' ),
|
||||
help: __( 'Prevent search engines from indexing', 'noindex-seo' ),
|
||||
checked: noindex,
|
||||
onChange: function (value) {
|
||||
updateMeta( '_noindex_seo_noindex', value ); },
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
el(
|
||||
PanelRow,
|
||||
{ key: 'nofollow-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: '🔗 ' + __( 'nofollow', 'noindex-seo' ),
|
||||
help: __( 'Prevent search engines from following links', 'noindex-seo' ),
|
||||
checked: nofollow,
|
||||
onChange: function (value) {
|
||||
updateMeta( '_noindex_seo_nofollow', value ); },
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
el(
|
||||
PanelRow,
|
||||
{ key: 'noarchive-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: '💾 ' + __( 'noarchive', 'noindex-seo' ),
|
||||
help: __( 'Prevent cached versions in search results', 'noindex-seo' ),
|
||||
checked: noarchive,
|
||||
onChange: function (value) {
|
||||
updateMeta( '_noindex_seo_noarchive', value ); },
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
el(
|
||||
PanelRow,
|
||||
{ key: 'nosnippet-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: '📄 ' + __( 'nosnippet', 'noindex-seo' ),
|
||||
help: __( 'Prevent text snippets in search results', 'noindex-seo' ),
|
||||
checked: nosnippet,
|
||||
onChange: function (value) {
|
||||
updateMeta( '_noindex_seo_nosnippet', value ); },
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
el(
|
||||
PanelRow,
|
||||
{ key: 'noimageindex-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: '🖼️ ' + __( 'noimageindex', 'noindex-seo' ),
|
||||
help: __( 'Prevent image indexing', 'noindex-seo' ),
|
||||
checked: noimageindex,
|
||||
onChange: function (value) {
|
||||
updateMeta( '_noindex_seo_noimageindex', value ); },
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
// Preview section.
|
||||
activeDirectives.length > 0 && el(
|
||||
'div',
|
||||
{
|
||||
key: 'preview-section',
|
||||
style: {
|
||||
marginTop: '16px',
|
||||
padding: '12px',
|
||||
background: '#f0f6fc',
|
||||
border: '1px solid #0969da',
|
||||
borderRadius: '4px',
|
||||
}
|
||||
},
|
||||
[
|
||||
el(
|
||||
'p',
|
||||
{
|
||||
key: 'preview-label',
|
||||
style: {
|
||||
fontSize: '11px',
|
||||
fontWeight: '600',
|
||||
marginBottom: '8px',
|
||||
color: '#0969da',
|
||||
textTransform: 'uppercase',
|
||||
}
|
||||
},
|
||||
__( 'Active Directives:', 'noindex-seo' )
|
||||
),
|
||||
el(
|
||||
'code',
|
||||
{
|
||||
key: 'preview-code',
|
||||
key: 'directives-label',
|
||||
style: {
|
||||
fontSize: '12px',
|
||||
display: 'block',
|
||||
padding: '8px',
|
||||
background: '#fff',
|
||||
border: '1px solid #d0d7de',
|
||||
borderRadius: '3px',
|
||||
wordBreak: 'break-word',
|
||||
fontWeight: '600',
|
||||
marginBottom: '12px',
|
||||
color: '#1e1e1e',
|
||||
}
|
||||
},
|
||||
activeDirectives.join( ', ' )
|
||||
__( 'Robots Directives:', 'noindex-seo' )
|
||||
),
|
||||
booleanRows,
|
||||
valueRows,
|
||||
|
||||
// Preview section.
|
||||
activeDirectives.length > 0 && el(
|
||||
'div',
|
||||
{
|
||||
key: 'preview-section',
|
||||
style: {
|
||||
marginTop: '16px',
|
||||
padding: '12px',
|
||||
background: '#f0f6fc',
|
||||
border: '1px solid #0969da',
|
||||
borderRadius: '4px',
|
||||
}
|
||||
},
|
||||
[
|
||||
el(
|
||||
'p',
|
||||
{
|
||||
key: 'preview-label',
|
||||
style: {
|
||||
fontSize: '11px',
|
||||
fontWeight: '600',
|
||||
marginBottom: '8px',
|
||||
color: '#0969da',
|
||||
textTransform: 'uppercase',
|
||||
}
|
||||
},
|
||||
__( 'Active Directives:', 'noindex-seo' )
|
||||
),
|
||||
el(
|
||||
'code',
|
||||
{
|
||||
key: 'preview-code',
|
||||
style: {
|
||||
fontSize: '12px',
|
||||
display: 'block',
|
||||
padding: '8px',
|
||||
background: '#fff',
|
||||
border: '1px solid #d0d7de',
|
||||
borderRadius: '3px',
|
||||
wordBreak: 'break-word',
|
||||
}
|
||||
},
|
||||
activeDirectives.join( ', ' )
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue