Overview
ThePostService handles markdown parsing, HTML rendering, search indexing, and social card generation. Itβs the core service for processing content in Kosh.
Source: builder/services/post_service.go:19-24
Interface
Methods
Process
Processes all markdown posts in the content directory, generating HTML, search indexes, and social cards.Context for cancellation and timeout control
Force rebuild all posts, ignoring cache
Force regeneration of all social card images
Render posts whose HTML files are missing from output directory
Aggregated results containing processed posts, tags, and search data
All non-pinned posts from latest version
Posts marked as pinned (displayed at top)
Map of tag names to posts containing that tag
Posts with BM25 search data (word frequencies, doc length)
Whether any post was modified or rendered
Whether a custom 404.md was found
ProcessSingle
Processes a single markdown file for fast incremental rebuilds during watch mode.Context for cancellation
Absolute path to the markdown file to process
RenderCachedPosts
Re-renders all posts from cache without parsing markdown. Used for template-only changes.This method has no parameters and is called during fast-path rebuilds when only templates/CSS changed.
Implementation
The default implementation ispostServiceImpl, created via dependency injection:
builder/services/post_service.go:49-72
Usage Example
Frombuilder/run/build.go:247-249:
builder/run/build.go:173-174:
Key Features
Cache Invalidation
The service uses body hash tracking (v1.2.1) to detect content changes even when file modification time hasnβt changed:builder/services/post_service.go:216-231
Parallel Processing
Uses worker pools for concurrent markdown parsing:builder/services/post_service.go:173-552
Search Indexing
Generates BM25 data with stemming and stop word removal:builder/services/post_service.go:397-404
Version Support
Handles versioned documentation with proper URL generation:builder/services/post_service.go:188-193
Performance
- Worker Pools: Parallel processing across CPU cores
- Buffer Pooling: Reuses
bytes.Bufferinstances to reduce GC pressure - Batch Operations: Commits cache entries in batches for better throughput
- LRU Cache: Hot post metadata cached in memory (5-minute TTL)
Related
- CacheService - Cache operations
- RenderService - HTML rendering
- AssetService - Static assets