fix repos containing supplementary .md files
[mdref/mdref] / mdref / Tree.php
index d9e2b0db2149221b82e99d65fb43c4bddce90adb..8f6c7739f6eaca5fea832fe847ae133ad4657823 100644 (file)
@@ -13,7 +13,7 @@ class Tree implements \RecursiveIterator {
         * List of first level entries
         * @var array
         */
-       private $list;
+       private $list = array();
        
        /**
         * The list iterator
@@ -26,11 +26,15 @@ class Tree implements \RecursiveIterator {
         * @param \mdref\Repo $repo
         */
        public function __construct($path, Repo $repo) {
-               if (!($list = glob("$path/*.md"))) {
+               if (realpath($path)."/" === $repo->getPath()) {
+                       $list = [$path ."/". $repo->getName() .".md"];
+               } elseif (!($list = glob("$path/*.md"))) {
                        $list = glob("$path/*/*.md");
                }
-               $this->list = array_filter($list, $this->generateFilter($list));
-               sort($this->list, SORT_STRING);
+               if ($list) {
+                       $this->list = array_filter($list, $this->generateFilter($list));
+                       sort($this->list, SORT_STRING);
+               }
                $this->repo = $repo;
        }