Add markdown support for custom headers and footers.

This commit is contained in:
Lars Jung 2014-06-08 15:13:36 +02:00
parent f0721afb88
commit b6cf568e31
7 changed files with 132 additions and 36 deletions

View file

@ -267,7 +267,7 @@ class App {
}
public function get_customizations($url) {
public function get_customizations2($url) {
if (!$this->options["custom"]["enabled"]) {
return array(
@ -309,4 +309,66 @@ class App {
"footer" => $footer
);
}
private function read_custom_file($path, $name, &$content, &$type) {
foreach (array("html", "md") as $ext) {
$file = "$path/" . FILE_PREFIX . ".$name.$ext";
if (is_readable($file)) {
$content = file_get_contents($file);
$type = $ext;
return;
}
}
}
public function get_customizations($url) {
if (!$this->options["custom"]["enabled"]) {
return array(
"header" => null,
"header_type" => null,
"footer" => null,
"footer_type" => null
);
}
$path = $this->to_path($url);
$header = null;
$header_type = null;
$footer = null;
$footer_type = null;
$this->read_custom_file($path, "header", $header, $header_type);
$this->read_custom_file($path, "footer", $footer, $footer_type);
while ($header === null || $footer === null) {
if ($header === null) {
$this->read_custom_file($path, "headers", $header, $header_type);
}
if ($footer === null) {
$this->read_custom_file($path, "footers", $footer, $footer_type);
}
if ($path === ROOT_PATH) {
break;
}
$parent_path = normalize_path(dirname($path));
if ($parent_path === $path) {
break;
}
$path = $parent_path;
}
return array(
"header" => $header,
"header_type" => $header_type,
"footer" => $footer,
"footer_type" => $footer_type
);
}
}