BlueGit

timfa 66wiki

Files

66wiki / web / index.php

index.php

c4b8fa75 History
index.php 4.2 KiB Download Raw
1<?php
2require_once("folderNode.php");
3require_once __DIR__ . '/templateRenderer.php';
4require_once __DIR__ . '/templateCssLinker.php';
5require_once __DIR__ . '/search.php';
6
7$renderer = new TemplateRenderer(__DIR__ . DIRECTORY_SEPARATOR . 'templates');
8
9$q = isset($_GET['q']) ? (string) $_GET['q'] : '';
10$q = trim($q);
11
12$searchResults = [];
13if ($q !== '') {
14 $searchResults = searchAllJson(__DIR__ . DIRECTORY_SEPARATOR . 'data', $q);
15} else {
16 if (isset($_GET['path'])) {
17 $html = $renderer->renderFromJsonFile($_GET['path']);
18 } else {
19 $data = loadFolderTree(__DIR__ . DIRECTORY_SEPARATOR . 'data/chapters');
20
21 $chaptersOrdered = $data->jsonRecursive();
22 usort($chaptersOrdered, fn($a, $b) => ($a->number ?? 0) <=> ($b->number ?? 0));
23
24 try {
25 $html = $renderer->renderAll($chaptersOrdered);
26 } catch (Throwable $e) {
27 $html = '<pre class="error">' . htmlspecialchars($e->getMessage()) . '</pre>';
28 }
29 }
30}
31?>
32<!DOCTYPE html>
33<html lang="en">
34
35<head>
36 <meta charset="UTF-8">
37 <title>66 Wiki</title>
38 <link rel="stylesheet" href="main.css">
39 <?php echoTemplateCssLinks(__DIR__ . DIRECTORY_SEPARATOR . 'templates', 'templates'); ?>
40</head>
41
42<body>
43
44 <div class="topBar">
45 <div class="topBarInner">
46
47 <div class="chapterPicker">
48 <button class="menuButton" id="chapterMenuBtn" type="button" aria-expanded="false">
49 Chapters ▾
50 </button>
51
52 <div class="chapterDropdown" id="chapterDropdown" role="menu" aria-label="Chapter list">
53 <?php foreach ($chaptersOrdered as $ch):
54 $num = $ch->number ?? '';
55 $title = $ch->title ?? '';
56 $id = 'chapter-' . $num;
57 ?>
58 <button type="button" data-target="<?= htmlspecialchars($id, ENT_QUOTES) ?>">
59 <?= htmlspecialchars("Chapter $num — $title", ENT_QUOTES) ?>
60 </button>
61 <?php endforeach; ?>
62 </div>
63 </div>
64
65 <form class="searchForm" method="get" action="">
66 <input class="searchInput" type="search" name="q" value="<?= htmlspecialchars($q, ENT_QUOTES) ?>"
67 placeholder="Search rules, items, proficiencies…">
68 <button class="searchSubmit" type="submit">Search</button>
69 </form>
70
71 </div>
72 </div>
73
74 <?php if ($q !== ''): ?>
75 <div class="page">
76 <h2>Search results for “<?= htmlspecialchars($q, ENT_QUOTES) ?>”</h2>
77
78 <?php if (!$searchResults): ?>
79 <p>No matches found.</p>
80 <?php else: ?>
81 <div>
82 <?php foreach ($searchResults as $r): ?>
83 <article
84 style="border:1px solid #ddd; border-radius:12px; padding:1rem; margin:0.75rem 0; background:#fff;">
85 <div style="display:flex; gap:0.75rem; flex-wrap:wrap; align-items:baseline;">
86 <strong><a
87 href="<?= "?path=" . DIRECTORY_SEPARATOR . "data" . htmlspecialchars($r['file'], ENT_QUOTES) ?>"><?= htmlspecialchars($r['name'] ?: '(no name)', ENT_QUOTES) ?></a></strong>
88 <small>type: <?= htmlspecialchars($r['type'], ENT_QUOTES) ?></small>
89 </div>
90
91 <ul>
92 <?php foreach (array_slice($r['hits'], 0, 5) as $hit): ?>
93 <li>
94 <code><?= htmlspecialchars($hit['field'], ENT_QUOTES) ?></code>:
95 <?= htmlspecialchars($hit['snippet'], ENT_QUOTES) ?>
96 </li>
97 <?php endforeach; ?>
98 </ul>
99 </article>
100 <?php endforeach; ?>
101 </div>
102 <?php endif; ?>
103 </div>
104 <?php else: ?>
105 <?= $html ?>
106 <?php endif; ?>
107
108 <script src="chapterScroll.js"></script>
109</body>
110
111</html>