如何将 Yoast wordpress 插件添加到 Laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41415297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to add Yoast wordpress plugin to laravel
提问by soha1410
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 versionof it that can be add to custom sites.
the usage help is not very helpful, so if any body can help me.
我用 Laravel 开发了一个网站,现在我想将 Yoast 插件添加到它的博客部分以改进网站博客。
正如我从 Yoast github 看到的,它有一个javascript 版本,可以添加到自定义站点。
使用帮助不是很有帮助,所以如果有人可以帮助我。
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.
使用帮助是 node.js 但我如何将它添加到 php 后端和 html+js 前端。
感谢您。
采纳答案by soha1410
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
经过几天的搜索,终于找到了答案。这或任何种类的NodeJS库转换成浏览器的JavaScript支持刚才去browserify。首先安装它
npm install -g browserify
then install all the library it needs with
然后安装它需要的所有库
npm install <module_name>
at the end generate single js file with
最后生成单个js文件
browserify <main.js> -o <destination.js>
now you can add script to your html like
现在您可以将脚本添加到您的 html 中,例如
<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.
对于 YOAST 库,示例中有一个 browserify 目录。我将 browserify 用于根目录下的 index.js 文件,并将生成的文件添加到此示例 html 文件中,一切都像魅力一样。