소스 검색

Added arbitrary header metadata

gidlov 10 년 전
부모
커밋
7ccba20803
1개의 변경된 파일13개의 추가작업 그리고 19개의 파일을 삭제
  1. 13 19
      lib/pico.php

+ 13 - 19
lib/pico.php

@@ -137,7 +137,6 @@ class Pico {
 	{
 		$content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta
 		$content = str_replace('%base_url%', $this->base_url(), $content);
-		//$content = MarkdownExtra::defaultTransform($content);
 		$content = Parsedown::instance()->text($content);
 		return $content;
 	}
@@ -151,30 +150,25 @@ class Pico {
 	protected function read_file_meta($content)
 	{
 		global $config;
-		
-		$headers = array(
-			'title'       	=> 'Title',
-			'description' 	=> 'Description',
-			'author' 		=> 'Author',
-			'date' 			=> 'Date',
-			'robots'     	=> 'Robots',
-			'template'      => 'Template'
-		);
 
+		$headers = array();
+		
 		// Add support for custom headers by hooking into the headers array
+		// Is no longer needed but kept for compatibility reasons.
 		$this->run_hooks('before_read_file_meta', array(&$headers));
 
-	 	foreach ($headers as $field => $regex){
-			if (preg_match('/^[ \t\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $content, $match) && $match[1]){
-				$headers[ $field ] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1]));
-			} else {
-				$headers[ $field ] = '';
+		// Add any meta-headers from your *.md-files.
+		if (preg_match_all('/^\/\*.(.*?)\*\//ims', $content, $match) && isset($match[1]) && isset($match[1][0])) {
+			$lines = array_filter(explode("\n", $match[1][0]));
+			foreach ($lines as $line) {
+				if (strpos($line, ':') == true) {
+					list($key, $val) = explode(':', $line);
+					$headers[trim(strtolower($key))] = trim($val);
+				}
 			}
-		}
-		
-		if(isset($headers['date'])) $headers['date_formatted'] = date($config['date_format'], strtotime($headers['date']));
-
+		if (isset($headers['date'])) $headers['date_formatted'] = date($config['date_format'], strtotime($headers['date']));
 		return $headers;
+		}
 	}
 
 	/**