Data files in the same directory as my source files?


#1

I want to keep page-specific datafiles next to the source files which are going to use them, for clarity. So I want to end up with something like this:

_pages
  my-page
    index.md
    _data.yaml

…becoming:

_site
  my-page
    index.html

Then I’ll have a custom tag in the markdown file actually use the yaml file to generate text.

Is there any way to achieve this?


#2

not that I know of, data files go in the _data folder.


#3

Just remember that the whole philosophy of Jekyll is to have conventions to avoid configuration. So most of the time, you don’t have configuration options for that kind of things.

FWIW you can change the default data folder but it’s a global setting, there’s no per page settings.

data_dir:        _pages/my-page/

#4

The trouble with ‘convention over configuration’ is that it completely falls down when faced with, e.g., the kind of external requirements I have here. I really can’t rearrange the source files.

I think I can work around this by creating a _data.yaml file, so that it’s ignored by the generator, and then manually loading it in Ruby code. It’s really ugly, but it at least lets me make progress.


#5

What prevents you from having a script moving the yaml files in the _data folder?


#6

Nothing, of course, but it seems like a waste to add a whole other moving part for something which should be so simple…


#7

If the data file is small, you could put it in the front matter.


#8

@davidgiven I too see a need for data file next the the source files.

  1. All the source file in that same folder can make use of just one datafile, without front matter on each of the source file.
  2. Individual source file that need to overide the data can have individual front matter.

Will be perfect if the datafile can also be inherited from top-level folder(s)