search: grep contents in repository for 404 suggestions
[minimedit.git] / search.php
diff --git a/search.php b/search.php
new file mode 100644 (file)
index 0000000..e1da846
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+$path = ' '.escapeshellarg('*.html');
+$cmd = "git grep -li -- ".escapeshellarg($Page).$path;
+$cmd .= ' |sort -R |head -n 10'; # random selection
+exec($cmd, $results);
+
+if (!$results) {
+       $results = ['index.html'];
+}
+
+require_once('nieuws.inc.php');
+print '<ul>';
+foreach ($results as $result) {
+       $page = new ArchiveArticle($result);
+       printf('<li><a href="/%s">%s</a></li>'."\n", $page->link, $page->name);
+}
+print "</ul>\n";