Lea Hayes
Lea Hayes

Reputation: 64236

Copy data file to '_sites" in Jekyll project

I have a data file which is being used inside a Jekyll template:

/{project}/_data/mydata.json

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:

What is the easiest way to maintain a single version of the data file inside both Jekyll templates and JavaScripts?

Upvotes: 2

Views: 370

Answers (1)

David Jacquel
David Jacquel

Reputation: 52829

File /{project}/mydata.json

---
layout: null
---
{{ site.data.mydata | jsonify }}

With jekyll serve or on github, this will be updated each time your /{project}/_data/mydata.json is updated.

Et voilà !

Upvotes: 4

Related Questions