contentful / contentful_middleman

Contentful Middleman is an extension to use the Middleman static site generator (Ruby) together with the API-driven Contentful CMS.
https://www.contentful.com
MIT License
146 stars 35 forks source link

After implementing locales, middleman config.rb won't allow nested loops. #159

Open frasermarlow opened 4 years ago

frasermarlow commented 4 years ago

We recently implemented locales in Contentful, and are pulling the .yaml files into Middleman just fine. Now we need to rework all of our templates with the localization helpers as every single object in the .yaml file now has a :en-US: level...

But one issue we have encountered is that when we were proxying pages in a nested loop, these are no longer working. We have spent ~16 people hours on this and can't get it to work. I am hoping somebody may have run into something similar and can either sympathize or better still offer up a solution? :-)

Is there possibly a conflict between middleman_contentful and the i18n middleman module?

Here are examples of our previous and new version of the code:

# Build james pages
    data.oursite.alljamess.each do |id, james|
      proxy "vs/#{james.slug}/index.html", "james.html", locals: { james: james }, :ignore => true
      data.oursite.alljamess.each do |id, james2|
        if james.name != james2.name
          proxy "vs/#{james.slug}/#{james2.slug}/index.html", "james_james.html", locals: { james: james, james2: james2 }, :ignore => true
        end
      end
    end

And the new version:

# Build james pages
    data.oursite.alljamess.each do |id, james|
      proxy "vs/#{james['slug']['en-US']}/index.html?l288=true", "james.html", locals: { james: james }, :ignore => true
      data.oursite.alljamess.each do |id, james2|
        if james.name['en-US'] != james2.name['en-US']
          proxy "vs/#{james['slug']['en-US']}/#{james2['slug']['en-US']}/index.html", "james_james.html", locals: { james: james, james2: james2 }, :ignore => true
        end
      end
    end

From testing, we see the pages in the outer loop are generated, but the inner ones don't.

simply put:

# Build james pages
    data.oursite.alljamess.each do |id, james|
      puts "a"
      data.oursite.alljamess.each do |id, james2|
        puts "b"
      end
    End

does not return abbbbbabbbbbabbbb... but returns aaaaaaaaaaaa

frasermarlow commented 4 years ago

I think we found a way to get this working, although either this fix or simply the upgrade to the new Middleman version has caused our site to grind to a halt during middleman build https://stackoverflow.com/questions/62976636/how-to-get-nested-loops-in-config-rb-to-work-in-middleman