Merge pull request #153 from khaledh/master

Adds support for landing page per folder (index.md) #38
This commit is contained in:
Denis Kisselev 2014-05-17 10:56:43 -07:00
commit ebc53ac80f
2 changed files with 18 additions and 8 deletions

View File

@ -73,7 +73,7 @@
function directory_tree($dir, $ignore) { function directory_tree($dir, $ignore) {
global $base_doc, $multilanguage, $output_language; global $base_doc, $multilanguage, $output_language;
$tree = array(); $tree = array();
$Item = array_diff(scandir($dir), array(".", "..", "index.md")); $Item = array_diff(scandir($dir), array(".", ".."));
foreach ($Item as $key => $value) { foreach ($Item as $key => $value) {
if (is_dir($dir . '/' . $value)) { if (is_dir($dir . '/' . $value)) {
if (!in_array($value, $ignore['folders'])) if (!in_array($value, $ignore['folders']))
@ -115,7 +115,13 @@
$return .= "<li"; $return .= "<li";
if (!(strpos($url, $key) === FALSE)) $return .= " class=\"open\""; if (!(strpos($url, $key) === FALSE)) $return .= " class=\"open\"";
$return .= ">"; $return .= ">";
$return .= "<a href=\"#\" class=\"aj-nav folder\">"; $link = "#";
$nav_class = "aj-nav ";
if(in_array("index.md", $node)) {
$link = $t . clean_url($key, $mode);
$nav_class = "";
}
$return .= "<a href=\"" . $link . "\" class=\"" . $nav_class . "folder\">";
$return .= clean_url($key, "Title"); $return .= clean_url($key, "Title");
$return .= "</a>"; $return .= "</a>";
$return .= "<ul class=\"nav nav-list\">"; $return .= "<ul class=\"nav nav-list\">";
@ -124,7 +130,7 @@
$return .= "</ul>"; $return .= "</ul>";
$return .= "</li>"; $return .= "</li>";
} }
else { else if($node !== "index.md") {
$return .= "<li"; $return .= "<li";
if ($url === $current_dir . '/' . $node) $return .= " class=\"active\""; if ($url === $current_dir . '/' . $node) $return .= " class=\"active\"";
$return .= ">"; $return .= ">";
@ -139,8 +145,8 @@
function generate_page($file) { function generate_page($file) {
global $base, $base_doc, $base_path, $docs_path, $options, $mode, $relative_base; global $base, $base_doc, $base_path, $docs_path, $options, $mode, $relative_base;
$template = $options['template']; $template = $options['template'];
$filename = substr(strrchr($file, "/"), 1); $file_relative_path = str_replace($docs_path . '/', "", $file);
if ($filename === 'index.md') $homepage = TRUE; if ($file_relative_path === 'index.md') $homepage = TRUE;
else $homepage = FALSE; else $homepage = FALSE;
if (!$file) { if (!$file) {
$page['path'] = ''; $page['path'] = '';
@ -149,7 +155,7 @@
$page['content'] = "<h3>Oh No. That page doesn't exist</h3>"; $page['content'] = "<h3>Oh No. That page doesn't exist</h3>";
$options['file_editor'] = false; $options['file_editor'] = false;
} else { } else {
$page['path'] = str_replace($docs_path . '/', "", $file); $page['path'] = $file_relative_path;
$page['markdown'] = file_get_contents($file); $page['markdown'] = file_get_contents($file);
$page['modified'] = filemtime($file); $page['modified'] = filemtime($file);
$page['content'] = MarkDownExtended($page['markdown']); $page['content'] = MarkDownExtended($page['markdown']);
@ -184,8 +190,11 @@
return $url; return $url;
case 'Title': case 'Title':
case 'Filename': case 'Filename':
$t = substr_count($url, '/'); $parts = array_reverse(explode('/', $url));
if ($t > 0) $url = substr(strrchr($url, "/"), 1); if (isset($parts[0])) {
if ($parts[0] === "index.md" && isset($parts[1])) $url = $parts[1];
else $url = $parts[0];
}
$url = explode('_', $url); $url = explode('_', $url);
if (isset($url[0]) && is_numeric($url[0])) unset($url[0]); if (isset($url[0]) && is_numeric($url[0])) unset($url[0]);
if ($mode === 'Filename') $url = implode('_', $url); if ($mode === 'Filename') $url = implode('_', $url);

View File

@ -51,6 +51,7 @@
$file .= '/' . $dirs[$key]; $file .= '/' . $dirs[$key];
$tree = $tree[$dirs[$key]]; $tree = $tree[$dirs[$key]];
} }
if (is_file($file . "/index.md")) $file = $file . "/index.md";
return $file; return $file;
} }
} }