docs.php
<?php
// ------------------------------------------------------------
// CONFIG
// ------------------------------------------------------------
$docsDir = __DIR__;
$jsonFile = $docsDir . '/docs.index.json';
// Load JSON index
$index = json_decode(file_get_contents($jsonFile), true);
$docs = $index['docs'] ?? [];
$config = $index['config'] ?? [];
// Allowed/excluded types
$allowedTypes = $config['allowed_types'] ?? ['md'];
$excludedTypes = $config['excluded_types'] ?? [];
// ------------------------------------------------------------
// SCAN DIRECTORY
// ------------------------------------------------------------
$allFiles = array_values(array_filter(scandir($docsDir), function($f) {
return !in_array($f, ['.', '..']);
}));
// Build file list with type filtering
function fileAllowed($file, $allowedTypes, $excludedTypes) {
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (in_array($ext, $excludedTypes)) return false;
if (!empty($allowedTypes) && !in_array($ext, $allowedTypes)) return false;
return true;
}
$filteredFiles = array_values(array_filter($allFiles, function($f) use ($allowedTypes, $excludedTypes) {
return fileAllowed($f, $allowedTypes, $excludedTypes);
}));
// ------------------------------------------------------------
// ORGANIZE BY GROUP
// ------------------------------------------------------------
$groups = [];
foreach ($docs as $doc) {
$filename = $doc['filename'];
if (in_array($filename, $filteredFiles)) {
$groups[$doc['group']][] = $doc;
}
}
// ------------------------------------------------------------
// LOAD MARKDOWN IF REQUESTED
// ------------------------------------------------------------
$selectedFile = $_GET['file'] ?? null;
$markdownContent = '';
if ($selectedFile && file_exists($docsDir . '/' . $selectedFile)) {
$markdownContent = file_get_contents($docsDir . '/' . $selectedFile);
}
// Simple Markdown → HTML converter (minimal)
function md($text) {
$text = htmlspecialchars($text);
// headings
$text = preg_replace('/^# (.*)$/m', '<h1>$1</h1>', $text);
$text = preg_replace('/^## (.*)$/m', '<h2>$1</h2>', $text);
$text = preg_replace('/^### (.*)$/m', '<h3>$1</h3>', $text);
// bold
$text = preg_replace('/\\(.?)\\*/', '<strong>$1</strong>', $text);
// italics
$text = preg_replace('/\(.?)\*/', '<em>$1</em>', $text);
// line breaks
return nl2br($text);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DefApp Documentation</title>
<!-- AdminLTE -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/admin-lte@4.0.0/dist/css/adminlte.min.css">
<style>
.navbar-nav .dropdown-menu a:hover {
background-color: #f0f0f0;
}
.doc-content {
background: #fff;
padding: 20px;
border-radius: 6px;
}
</style>
</head>
<body class="hold-transition layout-top-nav">
<div class="wrapper">
<!-- NAVBAR -->
<nav class="main-header navbar navbar-expand navbar-dark bg-primary">
<div class="container-fluid">
<a href="docs.php" class="navbar-brand">
<span class="brand-text font-weight-light">DefApp Docs</span>
</a>
<ul class="navbar-nav">
<!-- GROUP DROPDOWNS -->
<?php foreach ($groups as $group => $items): ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#">
<?= htmlspecialchars($group) ?>
</a>
<ul class="dropdown-menu">
<?php foreach ($items as $doc): ?>
<li>
<a class="dropdown-item"
href="?file=<?= urlencode($doc['filename']) ?>"
title="<?= htmlspecialchars($doc['purpose']) ?>">
<?= htmlspecialchars($doc['short_name']) ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
<!-- ALL FILES -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#">
All Files
</a>
<ul class="dropdown-menu">
<?php foreach ($allFiles as $f): ?>
<li>
<a class="dropdown-item"
href="?file=<?= urlencode($f) ?>">
<?= htmlspecialchars($f) ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</li>
<!-- FILTERED FILES -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#">
Allowed Types
</a>
<ul class="dropdown-menu">
<?php foreach ($filteredFiles as $f): ?>
<li>
<a class="dropdown-item"
href="?file=<?= urlencode($f) ?>">
<?= htmlspecialchars($f) ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</li>
</ul>
</div>
</nav>
<!-- CONTENT AREA -->
<div class="content-wrapper">
<div class="container p-4">
<?php if ($selectedFile): ?>
<h2><?= htmlspecialchars($selectedFile) ?></h2>
<div class="doc-content">
<?= md($markdownContent) ?>
</div>
<?php else: ?>
<div class="doc-content">
<h3>Select a document from the navbar</h3>
</div>
<?php endif; ?>
</div>
</div>
</div>
<!-- AdminLTE JS -->
<script src="https://cdn.jsdelivr.net/npm/admin-lte@4.0.0/dist/js/adminlte.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>