I got a problem by using d3js within a blog post.
I have successfully done the installation like this
copy d3.min.js to /content/themes/[theme name]/assets/js/
and adding
<script src="{{asset "js/d3.min.js"}}" charset="utf-8"></script>
into
/content/themes/[theme name]/default.hbs
Btw: It was important to add this into the <head>
part!
and
If I am adding a <script>
into my Markdown blog post, I don't get any expected result/action
<script>
var svg = d3.select("#animviz")
.append("svg")
.attr("width", w)
.attr("height", h);
// some additional code you can find below
</script>
<div id="animviz">
</div>
I also tried to write self executing functions surround this JS:
(function(){
// the hole code
})();
No success.
The only thing works, is to include the hole code
in the Ghost-Settings->Code Injection-> Blog Footer:
<script src="https://gist.githubusercontent.com/blablarnab/7621762/raw/0fc10237392911e12c4641c44cdd63066573430b/caterpillar.js"></script>
That works if I add the target <div id="animviz"></div>
into the blog posts Markdown.
Any ideas ? I assume it is a markdown parser problem. A possible solution would be to have a way to append code to the DOM (blog footer) out of a blog post and refresh the code. But how ? location.reload();
will also be dead like d3js I think ?