change markdown
remove ?> rework for composer
This commit is contained in:
parent
5943454877
commit
6e621654aa
5 changed files with 20 additions and 1762 deletions
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"require": {
|
||||
"twig/twig": "1.12.*"
|
||||
"twig/twig": "1.*",
|
||||
"michelf/php-markdown": "1.*"
|
||||
}
|
||||
}
|
|
@ -21,5 +21,3 @@ $config['excerpt_length'] = 50; // The pages excerpt length (in words)
|
|||
$config['custom_setting'] = 'Hello'; // Can be accessed by {{ config.custom_setting }} in a theme
|
||||
|
||||
*/
|
||||
|
||||
?>
|
|
@ -9,8 +9,5 @@ define('THEMES_DIR', ROOT_DIR .'themes/');
|
|||
define('CACHE_DIR', LIB_DIR .'cache/');
|
||||
|
||||
require(ROOT_DIR .'vendor/autoload.php');
|
||||
require(LIB_DIR .'markdown.php');
|
||||
require(LIB_DIR .'pico.php');
|
||||
$pico = new Pico();
|
||||
|
||||
?>
|
1732
lib/markdown.php
1732
lib/markdown.php
File diff suppressed because it is too large
Load diff
42
lib/pico.php
42
lib/pico.php
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Michelf\MarkdownExtra;
|
||||
|
||||
/**
|
||||
* Pico
|
||||
*
|
||||
|
@ -151,7 +153,7 @@ class Pico {
|
|||
{
|
||||
$content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta
|
||||
$content = str_replace('%base_url%', $this->base_url(), $content);
|
||||
$content = Markdown($content);
|
||||
$content = MarkdownExtra::defaultTransform($content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
@ -160,30 +162,21 @@ class Pico {
|
|||
* Parses the file meta from the txt file header
|
||||
*
|
||||
* @param string $content the raw txt content
|
||||
* @return array $headers an array of meta values
|
||||
* @return array $headers an array of meta values. Meta keys are converted to lowercase automatically.
|
||||
*/
|
||||
private function read_file_meta($content)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$headers = array(
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
'author' => 'Author',
|
||||
'date' => 'Date',
|
||||
'robots' => 'Robots',
|
||||
'layout' => 'Layout'
|
||||
);
|
||||
private function read_file_meta($content)
|
||||
{
|
||||
global $config;
|
||||
|
||||
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 ] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($headers['date'])) $headers['date_formatted'] = date($config['date_format'], strtotime($headers['date']));
|
||||
$headers = array();
|
||||
if (preg_match_all("/\/\*(.+?)\*\/(.*)/ms", $content, $h_and_c)) {
|
||||
preg_match_all('/(\w+)\s*:\s*(.*)/i', $h_and_c[1][0], $m);
|
||||
for ($i = 0; $i < count($m[0]); $i++) {
|
||||
$headers[strtolower($m[1][$i])] = trim($m[2][$i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($headers['date'])) $headers['date_formatted'] = date($config['date_format'], strtotime($headers['date']));
|
||||
|
||||
if (empty($headers['title'])) {
|
||||
preg_match('/^(.+?)[ ]*\n(=+|-+)[ ]*\n+/imu', $content, $matches);
|
||||
|
@ -198,7 +191,7 @@ class Pico {
|
|||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the config
|
||||
|
@ -260,6 +253,7 @@ class Pico {
|
|||
// Get title and format $page
|
||||
$page_content = file_get_contents($page);
|
||||
$page_meta = $this->read_file_meta($page_content);
|
||||
if(!$page_meta) trigger_error("$page meta not read");
|
||||
$page_content = $this->parse_content($page_content);
|
||||
$url = str_replace(CONTENT_DIR, $base_url .'/', $page);
|
||||
$url = str_replace('index'. CONTENT_EXT, '', $url);
|
||||
|
|
Loading…
Add table
Reference in a new issue