Suppose you need this.js
and that.js
in a message to save them in the newly created directory /javascripts/custom/
.
Than in your default layout, add something like inside the <head>
tag:
{% if page.custom_javascript %} {% for js in page.custom_javascript %} <script type="text/javascript" src="/javascripts/custom/{{ js }}"></script> {% endfor%} {% endif %}
Finally, you can add javascript for each post by simply adding custom_javascript
to the YAML front-matter field:
--- layout: post title: "Insert javascript inside head with Octopress" custom_javascript: [this.js, that.js] ---
Of course, you can use a similar approach for other things that you need to enter in <head>
.
source share