sitemap: skip subdirectories containing .gitignore
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 19 Oct 2019 16:01:05 +0000 (18:01 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sun, 27 Oct 2019 00:36:38 +0000 (02:36 +0200)
Assume html files stored in (partially) untracked directories are not meant
for public distribution.  Fixes unintended inclusion of profile/ pages and
archived documents in data/, and avoids a costly search in thumb/.

article.inc.php

index 6fcb640dc5e8ee2f857999010fc693814a738557..d42e49823c96b2536613c806f5399194b7b6c414 100644 (file)
@@ -157,9 +157,12 @@ class PageSearch
                                        # ignore symlinks, original contents only
                                        return FALSE;
                                }
+                               if ($current->isDir()) {
+                                       # traverse subdirectories unless untracked in any amount
+                                       return !file_exists("$current/.gitignore");
+                               }
                                # match **/*.html
-                               return $current->isDir()
-                                       || preg_match('/(?<!\.inc)\.html$/', $current->getFilename());
+                               return preg_match('/(?<!\.inc)\.html$/', $current->getFilename());
                        }
                );
        }