API
The DocumentationRenderer class is part of Uchū Docs namespace and provides core logic for rendering and managing Markdown-based documentation.
Diagram
Constructor
__construct(string $docsDirectory, ?PluginManager $pluginManager = null, string $basePath = '', ?string $contentDirectory = null)
Initializes the renderer.
docsDirectory: Path to the base documentation directory.pluginManager: Optional plugin manager.basePath: Base path used to generate links.contentDirectory: Optional path to the content subdirectory.
Public Methods
getAvailablePages
getAvailablePages(): array
Returns a hierarchical array of available pages with unique identifiers.
renderPagesHierarchy
renderPagesHierarchy(array $hierarchy, int $depth = 0): string
Renders the documentation structure as an HTML menu.
hierarchy: Hierarchical array returned bygetAvailablePages().depth: Current depth level for nested rendering.
renderPage
renderPage(string $pageIdentifier): string
Renders a single documentation page from Markdown to HTML.
pageIdentifier: Unique identifier of the page.
getMarkdownFiles
getMarkdownFiles(): array
Recursively fetches all .md files in the content directory.
findMarkdownFileByIdentifier
findMarkdownFileByIdentifier(string $identifier): string
Finds a Markdown file by its identifier. Searches the content and docs directories.
findMarkdownFile
findMarkdownFile(string $pageName): string
Tries to locate a Markdown file by its name (or path-like identifier).
getPageTitle
getPageTitle(string $filePath): string
Extracts the first Markdown heading from a file to use as its title.
searchPages
searchPages(string $query): array
Searches all Markdown titles for the given query string.
renderSidebar
renderSidebar(): string
Renders the sidebar (documentation menu) using getAvailablePages and renderPagesHierarchy.
Example Usage
$renderer = new DocumentationRenderer(__DIR__ . '/docs');
echo $renderer->renderSidebar();
echo $renderer->renderPage('getting_started');
Notes
- The class assumes the use of
.mdfiles organized in folders to represent documentation structure. - All rendered paths include basePath and are URL-safe.