Module

content_layer.sources.local

LocalSource - Content source for local filesystem.

This is the default source, reading markdown files from a directory. No external dependencies required.

Classes

LocalSource
Content source for local filesystem. Reads markdown files from a directory, parsing frontmatter an…
7

Content source for local filesystem.

Reads markdown files from a directory, parsing frontmatter and generating content entries.

Configuration:

directory: str - Directory path (relative to site root)
glob: str - Glob pattern for matching files (default: "**/*.md")
exclude: list[str] - Patterns to exclude (default: [])
Inherits from ContentSource

Methods 3

fetch_all async
Fetch all content entries from this directory.
0 AsyncIterator[Conte…
async def fetch_all(self) -> AsyncIterator[ContentEntry]

Fetch all content entries from this directory.

Returns

AsyncIterator[ContentEntry]

fetch_one async
Fetch a single file by relative path.
1 ContentEntry | None
async def fetch_one(self, id: str) -> ContentEntry | None

Fetch a single file by relative path.

Parameters 1
id str

Relative path from directory (e.g., "getting-started.md")

Returns

ContentEntry | None

ContentEntry if found, None otherwise

get_last_modified async
Get most recent modification time of any file.
0 datetime | None
async def get_last_modified(self) -> datetime | None

Get most recent modification time of any file.

Returns

datetime | None

Most recent mtime or None

Internal Methods 4
__init__
Initialize local source.
2 None
def __init__(self, name: str, config: dict[str, Any]) -> None

Initialize local source.

Parameters 2
name str

Source name

config dict[str, Any]

Configuration with 'directory' key required

_load_file async
Load a single file into a ContentEntry.
1 ContentEntry | None
async def _load_file(self, path: Path) -> ContentEntry | None

Load a single file into a ContentEntry.

Parameters 1
path Path

Path to the file

Returns

ContentEntry | None

ContentEntry or None if file can't be read

_should_exclude
Check if path should be excluded.
1 bool
def _should_exclude(self, path: Path) -> bool

Check if path should be excluded.

Parameters 1
path Path

Full path to check

Returns

bool

True if path matches an exclude pattern

_path_to_slug
Convert relative path to URL slug.
1 str
def _path_to_slug(self, rel_path: Path) -> str

Convert relative path to URL slug.

Parameters 1
rel_path Path

Path relative to source directory

Returns

str

URL-friendly slug

Functions

_parse_frontmatter
Parse YAML frontmatter from content.
1 tuple[dict[str, Any…
def _parse_frontmatter(content: str) -> tuple[dict[str, Any], str]

Parse YAML frontmatter from content.

Parameters 1

Name Type Default Description
content str

Raw file content with optional frontmatter

Returns

tuple[dict[str, Any], str]

Tuple of (frontmatter dict, body content)