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

feat: Allow ERB tags in configuration YAML files #517

Closed existentialmutt closed 2 years ago

existentialmutt commented 2 years ago

Summary

Allow ERB tags in configuration YAML files.

Motivation

Embedding ERB in configuration YAML is a handy feature many Rails devs are familiar with. This allows individual developers to customize their configuration with ENV vars while also embedding sane defaults in the config. For instance, it would be really slick to be able to have this in my site.metadata.yml

api_url: <%= ENV.fetch("API_URL") { "http://localhost:3000" } %>

Guide-level explanation

site.metadata.yml may include ERB tags. For instance:

api_url: <%= ENV.fetch("API_URL") { "http://localhost:3000" } %>

Reference-level explanation

Run configuration through an ERB processor before loading the YAML file.

Drawbacks

Slight impact on build performance?

Unresolved Questions

jaredcwhite commented 2 years ago

@existentialmutt It's an intriguing thought, but as the metadata file (and all YAML files) in src/_data is processed through the same resource engine as all other content folders, might need a bit of consideration. In the meantime, I wonder if switching to a Ruby file/hash would do the trick for you? https://www.bridgetownrb.com/docs/datafiles#the-metadata-file

existentialmutt commented 2 years ago

Sure, writing a ruby file directly should take care of what I need to do. Thanks Jared!

jaredcwhite commented 2 years ago

Cool, I think for the time being we can close this.