Support for landing page per folder (index.md) #38

This commit is contained in:
Khaled Hammouda 2014-04-09 17:15:50 -04:00
parent cd29e1224d
commit 2bcd8cb688
2 changed files with 18 additions and 8 deletions

View File

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

View File

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