Parse all headers as meta. No need for Advanced Meta Plugin any more
This commit is contained in:
parent
ec37ff4e75
commit
3447324b7a
4 changed files with 30 additions and 35 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
composer.lock
|
||||
composer.phar
|
||||
*.sublime-*
|
||||
vendor/twig/twig/doc/*
|
||||
vendor/twig/twig/ext/*
|
||||
vendor/twig/twig/test/*
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
Title: Welcome
|
||||
Description: This description will go in the meta description tag
|
||||
keywords: Pico CMS
|
||||
*/
|
||||
|
||||
## Welcome to Pico
|
||||
|
|
58
lib/pico.php
58
lib/pico.php
|
@ -96,7 +96,7 @@ class Pico {
|
|||
'current_page' => $current_page,
|
||||
'next_page' => $next_page,
|
||||
'is_front_page' => $url ? false : true,
|
||||
);
|
||||
);
|
||||
$this->run_hooks('before_render', array(&$twig_vars, &$twig));
|
||||
$output = $twig->render('index.html', $twig_vars);
|
||||
$this->run_hooks('after_render', array(&$output));
|
||||
|
@ -147,25 +147,17 @@ class Pico {
|
|||
{
|
||||
global $config;
|
||||
|
||||
$headers = array(
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
'author' => 'Author',
|
||||
'date' => 'Date',
|
||||
'robots' => 'Robots'
|
||||
);
|
||||
|
||||
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 ] = '';
|
||||
$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($headers['date']) $headers['date_formatted'] = date($config['date_format'], strtotime($headers['date']));
|
||||
|
||||
return $headers;
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,7 +181,7 @@ class Pico {
|
|||
'pages_order_by' => 'alpha',
|
||||
'pages_order' => 'asc',
|
||||
'excerpt_length' => 50
|
||||
);
|
||||
);
|
||||
|
||||
if(is_array($config)) $config = array_merge($defaults, $config);
|
||||
else $config = $defaults;
|
||||
|
@ -234,7 +226,7 @@ class Pico {
|
|||
'date_formatted' => date($config['date_format'], strtotime($page_meta['date'])),
|
||||
'content' => $page_content,
|
||||
'excerpt' => $this->limit_words(strip_tags($page_content), $excerpt_length)
|
||||
);
|
||||
);
|
||||
if($order_by == 'date'){
|
||||
$sorted_pages[$page_meta['date'].$date_id] = $data;
|
||||
$date_id++;
|
||||
|
@ -294,7 +286,7 @@ class Pico {
|
|||
preg_match("|^HTTP[S]?|is",$_SERVER['SERVER_PROTOCOL'],$m);
|
||||
return strtolower($m[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to recusively get all files in a directory
|
||||
*
|
||||
|
@ -304,21 +296,21 @@ class Pico {
|
|||
*/
|
||||
private function get_files($directory, $ext = '')
|
||||
{
|
||||
$array_items = array();
|
||||
if($handle = opendir($directory)){
|
||||
while(false !== ($file = readdir($handle))){
|
||||
if($file != "." && $file != ".."){
|
||||
if(is_dir($directory. "/" . $file)){
|
||||
$array_items = array_merge($array_items, $this->get_files($directory. "/" . $file, $ext));
|
||||
} else {
|
||||
$file = $directory . "/" . $file;
|
||||
if(!$ext || strstr($file, $ext)) $array_items[] = preg_replace("/\/\//si", "/", $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
return $array_items;
|
||||
$array_items = array();
|
||||
if($handle = opendir($directory)){
|
||||
while(false !== ($file = readdir($handle))){
|
||||
if($file != "." && $file != ".."){
|
||||
if(is_dir($directory. "/" . $file)){
|
||||
$array_items = array_merge($array_items, $this->get_files($directory. "/" . $file, $ext));
|
||||
} else {
|
||||
$file = $directory . "/" . $file;
|
||||
if(!$ext || strstr($file, $ext)) $array_items[] = preg_replace("/\/\//si", "/", $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
return $array_items;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,14 +9,15 @@
|
|||
{% endif %}{% if meta.robots %}
|
||||
<meta name="robots" content="{{ meta.robots }}">
|
||||
{% endif %}
|
||||
|
||||
{% if meta.keywords %}
|
||||
<meta name="keywords" content="{{ meta.keywords }}">
|
||||
{% endif %}
|
||||
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,700" type="text/css" />
|
||||
<link rel="stylesheet" href="{{ theme_url }}/style.css" type="text/css" />
|
||||
|
||||
<script src="{{ theme_url }}/scripts/modernizr-2.6.1.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header id="header">
|
||||
<div class="inner clearfix">
|
||||
<h1><a href="{{ base_url }}">{{ site_title }}</a></h1>
|
||||
|
|
Loading…
Add table
Reference in a new issue