search: grep contents in repository for 404 suggestions
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 16 Oct 2018 16:48:07 +0000 (18:48 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 16 Oct 2018 16:52:17 +0000 (18:52 +0200)
Report 10 random matches as minimal typo solver.

404.html
nieuws.inc.php
search.php [new file with mode: 0644]

index a7cf3ac0008eb792658a87727be5a24dfbe72c8c..04acb33958c9b7e2baa4bb8a79fd3ec6d952b995 100644 (file)
--- a/404.html
+++ b/404.html
@@ -1,3 +1,7 @@
 <h2>Pagina niet gevonden</h2>
 
 <p>De gevraagde pagina <em>[[url]]</em> bestaat niet.</p>
 <h2>Pagina niet gevonden</h2>
 
 <p>De gevraagde pagina <em>[[url]]</em> bestaat niet.</p>
+
+<p>Misschien is de gewenste inhoud hier te vinden:</p>
+
+[[search]]
index 54853158a6a18ea14514757469d470d9bb4c8f34..35ae0925b87d443ccf1d6e722330599a692abe39 100644 (file)
@@ -19,7 +19,7 @@ class ArchiveArticle
        function __construct($path)
        {
                $this->page = $path;
        function __construct($path)
        {
                $this->page = $path;
-               $this->link = preg_replace('/\.html$/', '', $path);
+               $this->link = preg_replace('{(?:/index)?\.html$}', '', $path);
        }
 
        function __get($col)
        }
 
        function __get($col)
@@ -40,7 +40,12 @@ class ArchiveArticle
 
        function safetitle()
        {
 
        function safetitle()
        {
-               return strip_tags($this->title);
+               return trim(strip_tags($this->title));
+       }
+
+       function name()
+       {
+               return $this->safetitle ?: $this->link;
        }
 
        function last()
        }
 
        function last()
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";