avillafiorita / jekyll-datapage_gen

Generate one page per yaml record in Jekyll sites.
369 stars 80 forks source link

non array yaml files #67

Closed eldemcan closed 4 years ago

eldemcan commented 4 years ago

Thank you so much for making this plugin. I have simple question. I have lot of yaml files but they are not arrays.

They are something like this

first.yml, second.yml, third.yml

title: 
description:
year:

Is it possible for this plugin working with non array entities ?

avillafiorita commented 4 years ago

Hi, thank you very much for your question.

The plugin does not work with records stored in different files, but there are other solutions you can try.

  1. Make the data into an array and then use the plugin. The following script does the job on a simple test case. It takes all yaml files in the current directory and makes them into an Yaml array, stored in array.yml
for file in *.yaml; do
  echo -n "- " >> array.yml
  head -1 $file >> array.yml
  sed -e '2,$s/^/  /' $file | tail -1 >> array.yml
done;

(There some corner case you might need to take into account, but the script might be good enough for your purposes.)

  1. Make your Yaml files into files Jekyll can process (e.g, by surrounding the Yaml matter with ---) and then use a layout which references the Yaml variables. E.g, you need to transform each yaml file into something like:
---
title: 
description: 
year:
layout: my_layout
---

Notice that you can also automate this transformation, if you want.

I hope it helps!