avillafiorita / jekyll-datapage_gen

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

Request in a remote json file #76

Closed omarciovsena closed 4 years ago

omarciovsena commented 4 years ago

is it possible to make a request in a remote json file?

page_gen-dirs: true
page_gen:
  - data: 'https://run.mocky.io/v3/49577d59-864d-452e-8226-d2abbdf04988'
    template: 'pet'
    name: 'pet_name'
    dir: 'pets'
avillafiorita commented 4 years ago

Hi, no it is not possible, but you can achieve the same result by downloading the json file first, for instance using curl. Notice that the data would be read, in any case, at build time, so I am not sure whether there is a use case which I am missing, here.

omarciovsena commented 4 years ago

Thanks for the answer. I solved it with a script that generates the files in the build in the application.

 data = JSON.load(URI.open('https://example.json'))
 array = data["members"]
 path = './members/'

if array && !array.empty?
  array.each do |entry|
    File.open(File.join(path + entry['username'].to_s + ".md"), 'wb') do |opp|
        opp.puts("---")
        opp.puts("layout: opportunity")
        opp.puts("id: #{entry["id"]}")
        opp.puts("name: #{entry["name"]}")
        opp.puts("stacks: #{entry["stacks"]}")
        opp.puts("description: #{entry["description"]}")
        opp.puts("\n---")
      end
    end
  end
albertvolkman commented 4 years ago

@marciovsena https://github.com/brockfanning/jekyll-get-json