bridgetownrb / bridgetown

A next-generation progressive site generator & fullstack framework, powered by Ruby
https://www.bridgetownrb.com
MIT License
1.16k stars 112 forks source link

Data builder example broken #669

Closed svoop closed 1 year ago

svoop commented 1 year ago

The edge example to add data from API calls appears to be broken.

In my site, I'm building a collection of aeronautical regions:

class Builders::OfmApiResources < SiteBuilder
  RESOURCES = {
    regions: "shortName"
  }

  def build
    RESOURCES.each do |resource, key|
      OfmApi.send(resource).each do |data|
        site.data[resource] = data.last.to_h { [_1[key], _1] }.sort
      end
    end
  end
end

Stripped down, this essentially assigns:

site.data[:region] = { "LF" => { "name" => "France" } }

In the bridgetown console, I'd expect this key to be present in site.data, however, it's not:

site.data.keys   # => ["site_metadata"]

Apparently, either the builder example in the edge docs is out of date or something else is broken on the way to 1.2... or I'm misreading the docs. :wink:

Bridgetown Version:

bridgetown 1.2.0.beta4 "Bonny Slope"

Computing environment (please complete the following information):

jaredcwhite commented 1 year ago

@svoop Hmm, I wonder if that example would need to be wrapped inside of a post_read hook, ala: https://edge.bridgetownrb.com/docs/plugins/external-apis#builder-lifecycle-and-data-files

Can you try that and let me know if it fixes the issue?

svoop commented 1 year ago

@jaredcwhite Indeed, wrapped in a post read hook, the example works, thanks for the hint! (Grmbl, I should read the entire guide page before jumping into the code.) Adding the wrapper in the example might still be a good idea.

jaredcwhite commented 1 year ago

@svoop good call, I've added that to the docs.