Module

core.site.factories

Factory methods for Site creation.

Provides classmethod factories for creating Site instances from configuration files or for testing purposes.

Related Modules:

  • bengal.core.site.core: Main Site dataclass
  • bengal.config.loader: Configuration loading
  • bengal.config.directory_loader: Directory-based config loading

Classes

SiteFactoriesMixin
Mixin providing factory methods for Site creation. This is a classmethod mixin - methods here are …
2

Mixin providing factory methods for Site creation.

This is a classmethod mixin - methods here are called on the class, not instances.

Methods 2

from_config classmethod
Create a Site instance from configuration. This is the PREFERRED way to create…
4 Self
def from_config(cls, root_path: Path, config_path: Path | None = None, environment: str | None = None, profile: str | None = None) -> Self

Create a Site instance from configuration.

This is the PREFERRED way to create a Site - it loads configuration from config/ directory or single config file and applies all settings.

Config Loading (Priority): 1. config/ directory (if exists) - Environment-aware, profile-native 2. bengal.yaml / bengal.toml (single file) - Traditional 3. Auto-detect environment from platform (Netlify, Vercel, GitHub Actions)

Directory Structure (Recommended): config/ ├── _default/ # Base config │ ├── site.yaml │ ├── build.yaml │ └── features.yaml ├── environments/ # Environment overrides │ ├── local.yaml │ ├── preview.yaml │ └── production.yaml └── profiles/ # Build profiles ├── writer.yaml ├── theme-dev.yaml └── dev.yaml

Important Config Sections:

  • [site]: title, baseurl, author, etc.
  • [build]: parallel, max_workers, incremental, etc.
  • [markdown]: parser selection ('mistune' recommended)
  • [features]: rss, sitemap, search, json, etc.
  • [taxonomies]: tags, categories, series
Parameters 4
root_path Path

Root directory of the site (Path object)

config_path Path | None

Optional explicit path to config file (Path object) Only used for single-file configs, ignored if config/ exists

environment str | None

Environment name (e.g., 'production', 'local') Auto-detected if not specified (Netlify, Vercel, GitHub)

profile str | None

Profile name (e.g., 'writer', 'dev') Optional, only applies if config/ directory exists

Returns

Self

Configured Site instance with all settings loaded

for_testing classmethod
Create a Site instance for testing without requiring a config file. This is a …
2 Self
def for_testing(cls, root_path: Path | None = None, config: dict[str, Any] | None = None) -> Self

Create a Site instance for testing without requiring a config file.

This is a convenience factory for unit tests and integration tests that need a Site object with custom configuration.

Parameters 2
root_path Path | None

Root directory of the test site (defaults to current dir)

config dict[str, Any] | None

Configuration dictionary (defaults to minimal config)

Returns

Self

Configured Site instance ready for testing