Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with new Carbon-Guttenberg blocks #5

Open
Boryenko opened this issue Oct 21, 2020 · 1 comment
Open

Does not work with new Carbon-Guttenberg blocks #5

Boryenko opened this issue Oct 21, 2020 · 1 comment

Comments

@Boryenko
Copy link

image
image
No errors in console connected with it

@marktiddy
Copy link

I've just discovered this issue this morning and from the Yoast documentation have put this together which I've put in admin.js instead of the content recommend by this plugin. You can actually just enqueue some admin Javascript yourself and remove the plugin completely with this solution.

This code is my fix. Please note that I give every Carbon Field Gutenberg block wrapper a class of .cf-blocks which is what I've used to grab all the content and feed it into Yoast.

`/* global YoastSEO */

class MyCustomDataPlugin {
constructor() {
// Ensure YoastSEO.js is present and can access the necessary features.
if (
typeof YoastSEO === "undefined" ||
typeof YoastSEO.analysis === "undefined" ||
typeof YoastSEO.analysis.worker === "undefined"
) {
return;
}

YoastSEO.app.registerPlugin("MyCustomDataPlugin", { status: "ready" });

this.registerModifications();

}

/**

  • Registers the addContent modification.
  • @returns {void}
    */
    registerModifications() {
    const callback = this.addContent.bind(this);
// Ensure that the additional data is being seen as a modification to the content.
YoastSEO.app.registerModification(
  "content",
  callback,
  "MyCustomDataPlugin",
  10,
);

}

/**

  • Adds to the content to be analyzed by the analyzer.
  • @param {string} data The current data string.
  • @returns {string} The data string parameter with the added content.
    */
    addContent(data) {
    var $blocks = jQuery(".cf-blocks");
$blocks.each(function () {
  data += jQuery(this).html();
});

return data;

}
}

/**

  • Adds eventlistener to load the plugin.
    */
    if (typeof YoastSEO !== "undefined" && typeof YoastSEO.app !== "undefined") {
    new MyCustomDataPlugin();
    } else {
    jQuery(window).on("YoastSEO:ready", function () {
    new MyCustomDataPlugin();
    });
    }
    `

Developer documentation from Yoast this was based on: https://developer.yoast.com/customization/yoast-seo/adding-custom-data-analysis/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants