将数据文件复制到"_sites"在Jekyll项目中 [英] Copy data file to '_sites" in Jekyll project
问题描述
我有一个在Jekyll模板中使用的数据文件:
I have a data file which is being used inside a Jekyll template:
/{project}/_data/mydata.json
我还希望可以通过JavaScript在实时网站上获得这些数据:
I also want this data to be available on the live website from a JavaScript:
/{project}/_site/mydata.json
我希望以下列方式之一:
Somehow I want one of the following:
-
每当进行更改时,自动将其自身从"_data"复制到"_sites".
Automatically copy itself from "_data" to "_sites" whenever changes are made.
已使模板从/{project}/mydata.json
读取数据文件,因为该文件已被复制到"_sites"文件夹中.
Have the template read the data file from /{project}/mydata.json
since this file will already get copied to the "_sites" folder.
在Jekyll模板和JavaScript中维护数据文件的单个版本的最简单方法是什么?
What is the easiest way to maintain a single version of the data file inside both Jekyll templates and JavaScripts?
推荐答案
文件/{project}/mydata.json
---
layout: null
---
{{ site.data.mydata | jsonify }}
在jekyll serve
或github上,每次更新/{project}/_data/mydata.json
时都会更新.
With jekyll serve
or on github, this will be updated each time your /{project}/_data/mydata.json
is updated.
等等!
这篇关于将数据文件复制到"_sites"在Jekyll项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!