bridgetown icon indicating copy to clipboard operation
bridgetown copied to clipboard

feat: Ruby configuration format (alternative to YAML)

Open jaredcwhite opened this issue 2 years ago • 2 comments

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 avatar Aug 16 '21 20:08 jaredcwhite

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 avatar May 12 '22 04:05 jaredcwhite

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 avatar Jun 06 '22 15:06 jaredcwhite

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

jaredcwhite avatar Oct 11 '22 17:10 jaredcwhite