简体   繁体   English

是否可以按帖子在Ghost中包含外部javascript?

[英]Is it possible to include external javascript on a per-post basis in Ghost?

I'm running an installation of Ghost and am trying to include a Google Charts chart into a single post. 我正在运行Ghost的安装,并试图将Google Charts图表包含到单个帖子中。 Doing so would however require me to load Google's javascript first. 但是,这样做需要我先加载Google的javascript。

This should of course be possible by adding the <script> tag to /content/themes/casperdefault.hbs , but I'd rather not load it globally, but just if necessary on a per-post basis. 当然应该通过将<script>标记添加到/content/themes/casperdefault.hbs/content/themes/casperdefault.hbs ,但是我宁愿不全局加载它,而是在必要时基于每个帖子。

Is this in any way possible? 这有可能吗? Adding the code directly into the post body at least doesn't seem to have much of an effect. 至少直接将代码添加到帖子正文中似乎没有多大作用。

Thanks! 谢谢!

Adding a script tag in the post body in the editor should in fact work. 实际上,在编辑器的帖子正文中添加脚本标签应该可以。 In Ghost 0.4, the following results in an alert box with object : 在Ghost 0.4中,以下结果将导致带有object的警报框:

<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.min.js"></script>
<script>alert(typeof window.Handlebars)</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM