VOOZH about

URL: https://deepwiki.com/calevans/staticforge/5-content-management

⇱ Content Management | calevans/staticforge | DeepWiki


Loading...
Last indexed: 11 February 2026 (5f6a2a)
Menu

Content Management

Purpose and Scope

This document covers how content is managed in StaticForge, including supported file formats, frontmatter metadata syntax, file discovery, and URL generation. For detailed information about specific aspects:

Content in StaticForge consists of text files stored in the SOURCE_DIR directory (default: content/). Each file contains two parts: frontmatter (YAML metadata) and content (Markdown or HTML). The FileDiscovery service scans these files, parses their metadata, generates URLs, applies filtering rules, and stores the results in the container for processing.


Supported Content Formats

StaticForge processes two content file formats, both supporting YAML frontmatter:

FormatExtensionFrontmatter SyntaxContent TypeProcessed By
Markdown.md---...---MarkdownMarkdownRenderer
HTML.html<!-- ---...--- -->HTMLHtmlRenderer

Diagram: Content File Structure


Sources:


File Discovery Process

The FileDiscovery class orchestrates content scanning and metadata extraction:

Diagram: FileDiscovery Workflow


Sources:

Key Discovery Steps

  1. Directory Scanning: FileDiscovery uses RecursiveDirectoryIterator to traverse the directory tree starting from directories specified in SCAN_DIRECTORIES (or SOURCE_DIR as fallback) src/Core/FileDiscovery.php56-70

  2. Extension Filtering: Each file is checked against the ExtensionRegistry to determine if it can be processed src/Core/FileDiscovery.php86

  3. Frontmatter Parsing: Depending on file extension, either parseMarkdownFrontmatter() or parseHtmlFrontmatter() extracts YAML metadata using regex patterns src/Core/FileDiscovery.php162-192

  4. Draft Filtering: Files with draft: true metadata are skipped unless SHOW_DRAFTS is enabled src/Core/FileDiscovery.php92-102

  5. Future Date Filtering: Files with a date field containing a future timestamp are excluded from the build src/Core/FileDiscovery.php104-118

  6. URL Generation: generateUrl() calculates the final URL for each file based on path, filename, and category metadata src/Core/FileDiscovery.php222-269

  7. Storage: Discovered files are stored in the container as discovered_files, an array of file metadata src/Core/FileDiscovery.php46


Discovered Files Data Structure

After discovery, each file is represented in the discovered_files array with the following structure:


This structure is accessed by all features during the generation lifecycle, enabling features to:

  • Build navigation menus from the complete file list
  • Generate category indexes
  • Create tag clouds
  • Compile sitemaps and RSS feeds
  • Build search indexes

Sources:


Common Frontmatter Fields

The following table lists standard frontmatter fields and their effects:

FieldTypePurposeExampleUsed By
titlestringPage title"My Post"Templates, Search, Sitemap
descriptionstringPage summary"A guide to..."Meta tags, RSS, Search
categorystringContent categorization"blog"Categories feature, URL routing
tagsarray/stringTopic tags["php", "web"]Tags feature, Search
menustringMenu position"1.5" or "2.1.3"MenuBuilder
datestring/intPublication date"2024-01-15"Date filtering, RSS, Sorting
draftbooleanDraft statustrueFileDiscovery filtering
templatestringTemplate override"custom"TemplateRenderer
typestringContent type"category"CategoryIndex, Special handling
robotsstringCrawler control"no"RobotsTxt generation
search_indexbooleanSearch inclusionfalseSearch feature

Sources:


URL Generation Algorithm

The generateUrl() method transforms source file paths into web URLs following these rules:

Diagram: URL Generation Flow


Sources:

URL Generation Rules

  1. Path Relativization: Strip SOURCE_DIR prefix from absolute path src/Core/FileDiscovery.php237

  2. Extension Transformation: Replace .md or .html with .html using regex src/Core/FileDiscovery.php240

  3. Category Routing: If category metadata exists, calculate category slug and insert as subdirectory src/Core/FileDiscovery.php242-255

  4. Base URL Prepending: Add SITE_BASE_URL with proper slash handling src/Core/FileDiscovery.php258-268

Category URL Example

For a file content/posts/article.md with category: "Web Development":

Source Path: content/posts/article.md
Relative Path: posts/article.md
Extension Change: posts/article.html
Category Applied: web-development/article.html
Final URL: https://example.com/web-development/article.html

The category slug is generated by slugify() which:

  • Converts to lowercase
  • Replaces spaces/underscores with hyphens
  • Removes special characters
  • Trims consecutive hyphens

Sources:


Content Processing Lifecycle

Content files move through multiple processing stages after discovery:

Diagram: Content Processing Pipeline with Code References


Sources:

Processing Stages

  1. Discovery: FileDiscovery scans directories and populates discovered_files
  2. POST_GLOB: Features build site-wide structures (menus, categories, indexes)
  3. Rendering Loop: Each file is individually processed through PRE_RENDER → RENDER → POST_RENDER
  4. POST_LOOP: Aggregate files generated (sitemap.xml, search.json, feed.xml)

Features access content metadata throughout the lifecycle via the discovered_files array stored in the container.

Sources:


Content Filtering Mechanisms

StaticForge provides multiple ways to control which content appears in builds:

Draft Filtering

Files with draft: true in frontmatter are excluded unless SHOW_DRAFTS environment variable is set:


Implementation: src/Core/FileDiscovery.php92-102

Future Date Filtering

Files with date metadata containing a future timestamp are automatically excluded:


Implementation: src/Core/FileDiscovery.php104-118

Search Index Exclusion

Files can opt-out of search indexing via frontmatter or configuration:

Frontmatter exclusion:


Configuration exclusion in siteconfig.yaml:


Implementation: src/Features/Search/Services/SearchIndexService.php191-225

Robots.txt Exclusion

Pages marked with robots: no are added to the site's robots.txt disallow list:


Implementation: src/Features/RobotsTxt/Services/RobotsTxtService.php109-126

Sources:


Extension Registry

The ExtensionRegistry service determines which file extensions can be processed. By default, .md and .html are registered. Features can register additional extensions during initialization.

Registration: Features register extensions by calling ExtensionRegistry::registerExtension() during their register() method.

Checking: FileDiscovery calls ExtensionRegistry::canProcess() for each file to determine if it should be included in the build.

Sources:


Integration with Features

Content metadata drives behavior across multiple features:

FeatureMetadata UsedPurpose
MenuBuildermenuBuilds numbered and static navigation menus
CategoriescategoryRoutes content to category subdirectories
CategoryIndextype: categoryGenerates category landing pages
TagstagsCreates tag clouds and tag pages
Searchtitle, description, tags, search_indexBuilds search index with page sections
RSSFeedtitle, description, date, categoryGenerates RSS feed entries
SitemapAll URLsCreates sitemap.xml
RobotsTxtrobotsControls crawler access
ChapterNavmenuGenerates prev/next navigation

Sources:


Configuration Variables

Content management behavior is controlled by these container variables:

VariableTypePurposeDefault
SOURCE_DIRstringPrimary content directory"content"
SCAN_DIRECTORIESarrayDirectories to scan for content[SOURCE_DIR]
SHOW_DRAFTSbooleanInclude draft files in buildfalse
SITE_BASE_URLstringBase URL prepended to all URLsRequired
site_configarrayParsed siteconfig.yaml[]
discovered_filesarrayAll discovered content files[]

Sources:


This content management system provides the foundation for StaticForge's file-based architecture. For detailed information on specific processing steps, consult the sub-pages listed at the beginning of this document.