simplify
[mdref/mdref] / index.php
index 7ae8e478efa5eac7432ab39c0d68dd2e4b524cd4..9bdeceaaccb438c086de2c55882072f6dbe43125 100644 (file)
--- a/index.php
+++ b/index.php
@@ -154,15 +154,12 @@ function ml($file) {
                if (is_dir($dir)) {
                        printf("<h2>Functions:</h2>\n");
                        printf("<ul>\n");
-                       foreach (scandir($dir) as $file) {
-                               if ($file{0} === "." || !is_file("$dir/$file") || ctype_upper($file{0})) {
-                                       continue;
-                               }
+                       foreach (glob("$dir/[_a-z]*.md") as $file) {
                                printf("<li><h3><a href=\"%s\">%s</a></h3><p>%s</p><p>%s</p></li>\n",
                                        urlpath($dir, $file),
                                        basename($file, ".md"),
-                                       @end(head("$dir/$file", 3)),
-                                       join(" ", cut(head("$dir/$file"), ["f"=>"1-"]))
+                                       @end(head($file, 3)),
+                                       join(" ", cut(head($file), ["f"=>"1-"]))
                                );
                        }
                        printf("</ul>\n");
@@ -173,15 +170,12 @@ function ml($file) {
                if (is_dir($dir)) {
                        printf("<h2>Methods:</h2>\n");
                        printf("<ul>\n");
-                       foreach (scandir($dir) as $file) {
-                               if ($file{0} === "." || !is_file("$dir/$file") || ctype_upper($file{0})) {
-                                       continue;
-                               }
+                       foreach (glob("$dir/[_a-z]*.md") as $file) {
                                printf("<li><h3><a href=\"%s\">%s</a></h3><p>%s</p><p>%s</p></li>\n",
                                        urlpath($dir, $file),
                                        basename($file, ".md"),
-                                       @end(head("$dir/$file", 3)),
-                                       join(" ", cut(head("$dir/$file"), ["f"=>"1-"]))
+                                       @end(head($file, 3)),
+                                       join(" ", cut(head($file), ["f"=>"1-"]))
                                );
                        }
                        printf("</ul>\n");
@@ -263,12 +257,29 @@ ob_start($s);
        <?php else: ?>
                <?php md($p, $s); ?>
        <?php endif; ?>
+       
+       <div id="disqus_thread"></div>
+       
        <footer>
                <a href="VERSION">Version</a>
                <a href="AUTHORS">Authors</a>
                <a href="LICENSE">License</a>
+               <?php if ($p !== "./") : ?>
+               <a href="https://github.com/m6w6/mdref/edit/master/<?=trim($p,"/")?>.md">Edit</a>
+               <?php endif; ?>
        </footer>
        <script src="index.js"></script>
+       <?php if ($_SERVER["SERVER_NAME"] != "localhost") : ?>
+    <script>
+        var disqus_shortname = 'mdref';
+        var disqus_identifier = '<?=$p?>';
+        (function() {
+            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+            dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
+            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+        })();
+    </script>
+    <?php endif; ?>
 </body>
 </html>
 <?php