Dynamic pages with nested json data files?

Hey fellow coders,

I try to achieve the following with middleman (after I was unhappy with Jekyll Collections ;-)):

Collect video data in a file per video publisher (e.g. a channel provider).
So there is a) general publisher information and b) a list of items (videos)

The goal in a template would be:

  • display general publisher information (all the same for the videos)
  • display specific video information

Each video should have it’s own .html file/URL afterwards.

My approach:

data/publisher1.json

{
  "publisher":
  {
    "@type": "Organization",
    "name": "Civil Engineering RWTH Aachen University",
    "description":"Open Educational Resources Initiative by the Faculty of Civil Engineering of the RWTH Aachen University.",
    "url":"https://www.youtube.com/channel/UCMg7OPagfjM_eUYsDw3c4-A/videos"
  },
  "items":[{
    "@context": "https://schema.org",
    "url":"https://youtube.com/watch?v=CKwfCh4xk6A",
    "@type": "VideoObject",
    "name": "ELVA - The Railway Signalling Lab",
    "license": "https://creativecommons.org/licenses/by/4.0/deed.en",
    "description": "Railway safety and operation are two very complex topics. The interaction of safety systems and operation is a major field of education & research at the Institute of Transport Science. For this purpose all generations of interlocking systems are in operation at the railway lab 'ELVA'.",
    "thumbnailUrl": "http://i3.ytimg.com/vi/CKwfCh4xk6A/maxresdefault.jpg",
    "uploadDate": "2019-09-06",
    "learningResourceType": "video"
  },
  {
    "@context": "https://schema.org",
    "url":"https://www.youtube.com/watch?v=u8yFPm8Y6cc",
    "@type": "VideoObject",
    "name": "Dike Breach (long version)",
    "license": "https://creativecommons.org/licenses/by/4.0/deed.en",
    "description": "Flood polders are used to improve water retention and thus attenuate flood peaks in the course of small-scale and average flood events. Breach formation processes and its influencing factors are still subject to a number of uncertainties. In that context, physical model tests of dike breaches were performed in the hydraulic laboratory in Aachen to quantify the targeted filling of flood polders.",
    "thumbnailUrl": "http://i3.ytimg.com/vi/u8yFPm8Y6cc/maxresdefault.jpg",
    "uploadDate": "2019-08-15",
    "learningResourceType": "video",
  }]
}

Now i want to create subpages and also create a slug with .paramaterize (found via https://cobwwweb.com/dynamic-routing-in-middleman):

config.rb

data.publisher1.items.each do |item|
  proxy "/videos/{item.name.parameterize}.html", "/templates/video-detail-page.html",
  #vars only for templates?
  locals: { current_video: item, publisher:data.publisher1.publisher},
  ignore: true
end

Unfortunately this is not working right now, output is:

create  public/videos/{item.name.parameterize}.html
 identical  public/videos/{item.name.parameterize}.html

Source code: https://gitlab.com/programmieraffe/oerhoernchen-simple-metadata-registry-middleman

Is this use-case even supported by data files?

Thanks in advance! Cheers!

Use "#{}" for snippet injections (you don’t have the hashtag in your code example)

1 Like

Thanks very much!

(I deleted the # because i thought it was an html anchor :man_facepalming: :man_facepalming:)