I develop a website with Laravel and now I'd like to add Yoast plugin to it's blogger section to improve site blogs.
as I can see from Yoast github there is a javascript version of it that can be add to custom sites.
the usage help is not very helpful, so if any body can help me.
var SnippetPreview = require( "yoastseo" ).SnippetPreview;
var App = require( "yoastseo" ).App;
window.onload = function() {
var focusKeywordField = document.getElementById( "focusKeyword" );
var contentField = document.getElementById( "content" );
var snippetPreview = new SnippetPreview({
targetElement: document.getElementById( "snippet" )
});
var app = new App({
snippetPreview: snippetPreview,
targets: {
output: "output"
},
callbacks: {
getData: function() {
return {
keyword: focusKeywordField.value,
text: contentField.value
};
}
}
});
app.refresh();
focusKeywordField.addEventListener( 'change', app.refresh.bind( app ) );
contentField.addEventListener( 'change', app.refresh.bind( app ) );
};
the usage help is with node.js but how can I add it to php backend and html+js front end.
thanks you.
After several days of searching finally find the answer. to convert this or any kind of nodejs library to browser javascript supported just go to browserify . first install it by
npm install -g browserify
then install all the library it needs with
npm install <module_name>
at the end generate single js file with
browserify <main.js> -o <destination.js>
now you can add script to your html like
<script src="destination.js"></script>
for YOAST library there is a browserify directory in example. I use browserify for the index.js file at root directory and add the generated file to this example html file and everything works like a charm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With