Bengal's configuration system provides flexible, format-agnostic loading of site configuration with clear architectural boundaries.
Design Philosophy
Bengal's configuration follows the Separation of Concerns principle with three distinct layers:
Three-Layer Architecture
site.yaml- Identity & Metadata- Who you are: title, author, baseurl
- Site structure: menus, taxonomies
- Does NOT control content processing or theme behavior
content.yaml- Processing Pipeline (Bengal's Core API)- How Bengal computes content
- Theme-independent processing:
page.excerpt,page.reading_time,page.toc - Section organization: sorting, filtering, type detection
- This is Bengal's API to theme developers
params.yaml- User Variables- Custom site-specific data
- Accessible in templates/markdown:
{{ site.config.params.product_name }} - Not processed by Bengal, just passed through
Why This Architecture?
Aligns with Design Principles:
- ✅ Single Responsibility: Each config file has one clear purpose
- ✅ Separation of Concerns: Identity vs. Processing vs. Data
- ✅ Theme Independence: Content processing separate from presentation
- ✅ Explicit is Better Than Implicit: Clear what each setting controls
- ✅ Composition Over Inheritance: Content model composes from config
Example: Theme Switch Scenario
1 2 3 4 5 6 7 8 9 | |
Config Loader (bengal/config/loader.py)
Purpose
Load and manage site configuration from TOML, YAML, or directory structures
Features
- Supports TOML and YAML formats
- Supports directory-based config (config/_default/, config/environments/)
- Auto-detects config files
- Provides sensible defaults
- Flattens nested configuration for easy access
- Uses Utilities: Delegates to
bengal.utils.file_iofor robust file loading with error handling
Auto-Detection Order
bengal.tomlbengal.yaml/bengal.ymlconfig.tomlconfig.yaml/config.yml
Configuration Structure (Single File - bengal.toml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
Configuration Structure (Directory - Recommended)
config/
├── _default/
│ ├── site.yaml # Identity: title, author, menus, taxonomies
│ ├── content.yaml # Processing: excerpt_length, toc_depth, sorting
│ ├── params.yaml # Variables: product_name, api_url, custom data
│ ├── build.yaml # Build: parallel, incremental, output_dir
│ └── features.yaml # Features: analytics, search, comments
├── environments/
│ ├── local.yaml # Dev overrides
│ └── production.yaml # Prod overrides
└── profiles/
├── writer.yaml # Workflow: fast builds, no validation
└── dev.yaml # Workflow: full observability
Example: site.yaml (Identity)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Example: content.yaml (Bengal's API)
1 2 3 4 5 6 7 8 9 10 11 | |
Example: params.yaml (User Data)
1 2 3 4 5 6 7 8 | |
Environment-Aware Configuration
Bengal automatically detects deployment environments and applies environment-specific overrides.
Environment Detection Order:
BENGAL_ENV(explicit override, highest priority)- Netlify: Detects
NETLIFY=true+CONTEXT(production/preview) - Vercel: Detects
VERCEL=1+VERCEL_ENV(production/preview/development) - GitHub Actions: Detects
GITHUB_ACTIONS=true(assumes production) - Default: Falls back to
local
Example: environments/production.yaml
1 2 3 4 5 6 | |
Example: environments/local.yaml
1 2 3 4 5 6 | |
Usage:
1 2 3 | |
Build Profiles
Profiles provide persona-based configuration for optimized workflows.
Available Profiles:
writer: Fast builds, quiet output (minimal logging)theme-dev: Template debugging (verbose template errors)dev: Full observability (all logging, validation enabled)
Example: profiles/writer.yaml
1 2 3 4 5 6 | |
Example: profiles/dev.yaml
1 2 3 4 5 6 7 | |
Usage:
1 2 3 | |
Configuration Precedence
Configuration is merged in this order (lowest to highest priority):
config/_default/*.yaml(base configuration)config/environments/<env>.yaml(environment overrides)config/profiles/<profile>.yaml(profile settings)- Environment variable overrides (GitHub Actions, Netlify, Vercel)
Later layers override earlier ones. Feature toggles are expanded after all merges.
Smart Feature Toggles
Feature toggles provide simple flags that expand into detailed configuration.
Example: features.yaml
1 2 3 4 | |
These simple flags are automatically expanded into full configuration viabengal/config/feature_mappings.py, reducing boilerplate while maintaining flexibility.
CLI Introspection
Bengal provides CLI commands for configuration introspection and management:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Default Configuration
If no config file found, Bengal provides sensible defaults:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Usage
1 2 3 4 5 6 7 8 9 10 11 | |
Content Configuration Details
Whatcontent.yamlControls:
These settings configure Bengal's content model, not theme presentation:
| Setting | Affects | Template Access |
|---|---|---|
excerpt_length |
Page.excerptproperty |
{{ page.excerpt }} |
reading_speed |
Page.reading_timeproperty |
{{ page.reading_time }} |
summary_length |
Page.meta_descriptionproperty |
{{ page.meta_description }} |
related_count |
Page.related_postsproperty |
{% for post in page.related_posts %} |
related_threshold |
Related posts algorithm | (internal) |
toc_depth |
Page.tocgeneration |
{{ page.toc \| safe }} |
toc_min_headings |
When TOC is generated | (internal) |
default_type |
Sectioncontent type detection |
(internal) |
sort_pages_by |
Section.pagesordering |
{% for page in section.pages %} |
Key Insight: Bengal computes these properties during build. Themes just display them.
Configuration Validation
The ConfigValidator (part of health check system) validates:
- Required fields present
- Valid values for enums
- Path existence
- Type correctness
- Common misconfigurations
- Separation of concerns (warns if mixing concerns)