Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing site.data doesn't work as expected with collections_dir specified #764

Open
robcarruthers opened this issue Jun 3, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@robcarruthers
Copy link

Testing/Dev Environment:

❯ bundle exec bridgetown -v
bridgetown 1.2.0 "Bonny Slope"
❯ ruby -v --yjit
ruby 3.2.2 (2023-03-30 revision e51014f9c0) +YJIT [arm64-darwin22]
❯ sw_vers
ProductName:		macOS
ProductVersion:		13.5
BuildVersion:		22G5038d

Test repo:

git clone git@github.com:robcarruthers/bridgetown_test_site.git

To Reproduce
Testing with a new site:

bridgetown new test_site -t erb

Add the following site data

# src/_data/navbar.yml
title: Brand Title
icon: fa-rocket

Then in the console:

❯ bin/bt console
irb(main):001:0> site.data.navbar
{
  "title" => "Brand Title",                                                         
   "icon" => "fa-rocket"                                                            
}

Add a collections directory as per the docs

# bridgetown.config.yml
collections_dir: my_collections

then in the console:

irb(main):001:0> site.data.navbar
nil
irb(main):002:0> site.data
{}
irb(main):003:0> site.metadata.title
nil

Expected behavior
I guess I expected all of the the navbar dataset and the site metadata to be available under the same accessors. My first attempt to fix this was to copy to the _data folder to my_collections, because that's what the docs say to do with the _posts folder, but unfortunately that gave me more unexpected behaviour

irb(main):001:0> site.data.navbar
nil
irb(main):002:0> site.data
{
  "_data" => {                                  
           "navbar" => {                        
      "title" => "Brand Title",                 
       "icon" => "fa-rocket"                    
    },                                          
    "site_metadata" => {                        
            "title" => "Your awesome title",    
          "tagline" => "This site is totally awesome",
            "email" => "your-email@example.com",
      "description" => "Write an awesome description for your new site here. It will appear in your document head meta (for Google search results) and in your feed.xml site description."
    }                                           
  }                                             
}                                               
irb(main):003:0> site.data._data.navbar
{
  "title" => "Brand Title",                                                               
   "icon" => "fa-rocket"                                                                  
}

Additional context
I have made a few assumptions about how this should work and I'd be happy for someone to point me in the right direction or detail my errors. But I think the docs are a bit ambiguous in this regards too.

Anyway, If this is a bug or just something that needs tidying up, I'd be really happy to contribute a PR to make this more seamless and intuitive. I'll need some guidance on the best implementation and where best place to start.

@robcarruthers robcarruthers added the bug Something isn't working label Jun 3, 2023
@jaredcwhite
Copy link
Member

jaredcwhite commented Jun 3, 2023

@robcarruthers Thanks Rob. Data is a special collection that I would expect would need to be relocated to the custom folder (aka my_collections/_data) along with the other collections. That it then adds in an extra _data key is unexpected, aka a bug. I'd love a PR and am happy to assist.

@robcarruthers
Copy link
Author

No worries, happy to help.

I don't really know where to start looking. I don't expect its something you keep front of mind either, but a high level view of how the site object is created initially and made available to the views would be a good place to start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants