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: Ruby configuration format (alternative to YAML) #367

Closed jaredcwhite closed 2 years ago

jaredcwhite commented 3 years ago

May 2022 Update: See Below


As an alternative (not a replacement!) to Bridgetown's YAML format for the configuration file, we could offer a Ruby-based configuration file (bridgetown.config.rb). It might be something as simple as:

Bridgetown.configure do |config|
  config.url = "https://mydomain.com"
  config.timezone = "UTC"

  config.pagination = {
    enabled: true,
    per_page: 30
  }

  config.environment :production do
    config.some_analytics_key = "UA-12345678"
  end
end

Feedback and further thoughts encouraged!

jaredcwhite commented 2 years ago

After much time reflecting, I'm now leaning in a much more DSL-like direction…something more akin to:

site do
  url "https://jaredwhite.com"
  timezone "America/Los_Angeles"

  environment :development do
    bind "ssl://0.0.0.0:4000"
  end
end

content do
  permalink :simple
  template_engine :serbea
end

collection :now_entries do
  sort direction: :descending
end

collection :newsletters do
  disable_output
  sort direction: :descending
end

collection :events do
  front_matter do
    layout :event
  end
end

pagination :enable do
  title ":title (pg. :num)"
  per_page 15
end

Otherwise if it's just basic key/value hashes sort of style we might as well stick with simple YAML.

ALSO: if we were to go in this direction, I'd deprecate and eventually drop the YAML format. It seems like madness to have two completely different config formats and support both indefinitely.

jaredcwhite commented 2 years ago

Another idea: keep bridgetown.config.yml as a basic entrypoint, but optionally allow any config/*.config.rb files be processed as configuration using a DSL like the above. (Maybe we could support config/*.config.yml too.) The nice thing about this idea is that any automation or plugin gem which needs to generate configuration could create new files in that folder, rather than editing bridgetown.config.yml. In fact it makes sense to "block" that file from ever getting edited by anything other than manually by the site owner.

jaredcwhite commented 2 years ago

Something along these lines is now available as the Initializers format in Bridgetown 1.2!