我使用Octopress编写帖子,使用markdown文件生成html文件,使用:
rake new_post['my_post']
rake generate
但是如果我需要在帖子中添加一些JavaScript演示,我需要在帖子中写一些代码,这可能是我写的html页面。
我可以通过Octopress实现这一点并保持风格的整体一致性吗?
答案 0 :(得分:4)
您可以将Javascript块放入自己的source/_includes/
目录中的HTML文件中。然后,您可以使用Liquid include标记将其嵌入到帖子中:
---
layout: post
title: "JS Demo"
date: 2015-01-01 01:01:01
categories:
---
{% include myjs.html %}
,myjs.html
的内容为:
<div id="myelement"></div>
<script>
$('div#myelement').text("hello world");
</script>
和myjs.html
位于source/_includes/myjs.html
。然后,您的最终页面源代码将(例如)呈现为:
<div><h1>JS Demo</h1></div>
<div id="myelement">hello world</div>
如果您要构建包含更多内容的Javascript代码,可以在(例如)source/_includes/demo/
中为Javascript文件创建目录,然后将您的Javascript放入source/_includes/demo.html
。然后您的降价将具有以下Liquid包含标签:
{% include demo/demo.html %}