v0.6.2
[New] Added "content" and "excerpt" fields to pages [New] Added excerpt_length config setting
This commit is contained in:
parent
2416172ba7
commit
f9ebb4d75c
@ -1,5 +1,9 @@
|
|||||||
*** Pico Changelog ***
|
*** Pico Changelog ***
|
||||||
|
|
||||||
|
2013.05.07 - version 0.6.1
|
||||||
|
* [New] Added "content" and "excerpt" fields to pages
|
||||||
|
* [New] Added excerpt_length config setting
|
||||||
|
|
||||||
2013.05.06 - version 0.6
|
2013.05.06 - version 0.6
|
||||||
* [New] Added plugin functionality
|
* [New] Added plugin functionality
|
||||||
* [Changed] Other small cleanup
|
* [Changed] Other small cleanup
|
||||||
|
@ -14,6 +14,7 @@ $config['twig_config'] = array( // Twig settings
|
|||||||
);
|
);
|
||||||
$config['pages_order_by'] = 'alpha'; // Order pages by "alpha" or "date"
|
$config['pages_order_by'] = 'alpha'; // Order pages by "alpha" or "date"
|
||||||
$config['pages_order'] = 'asc'; // Order pages "asc" or "desc"
|
$config['pages_order'] = 'asc'; // Order pages "asc" or "desc"
|
||||||
|
$config['excerpt_length'] = 50; // The pages excerpt length (in words)
|
||||||
|
|
||||||
// To add a custom config setting:
|
// To add a custom config setting:
|
||||||
|
|
||||||
|
@ -79,6 +79,8 @@ All themes must include an `index.html` file to define the HTML structure of the
|
|||||||
* `{{ page.author }}`
|
* `{{ page.author }}`
|
||||||
* `{{ page.date }}`
|
* `{{ page.date }}`
|
||||||
* `{{ page.date_formatted }}`
|
* `{{ page.date_formatted }}`
|
||||||
|
* `{{ page.content }}`
|
||||||
|
* `{{ page.excerpt }}`
|
||||||
* `{{ prev_page }}` - A page object of the previous page (relative to current_page)
|
* `{{ prev_page }}` - A page object of the previous page (relative to current_page)
|
||||||
* `{{ current_page }}` - A page object of the current_page
|
* `{{ current_page }}` - A page object of the current_page
|
||||||
* `{{ next_page }}` - A page object of the next page (relative to current_page)
|
* `{{ next_page }}` - A page object of the next page (relative to current_page)
|
||||||
@ -92,8 +94,6 @@ Pages can be used like:
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul></pre>
|
</ul></pre>
|
||||||
|
|
||||||
Note the `{{ pages }}` objects don't contain `content`. It is mainly to be used in creating navigaiton.
|
|
||||||
|
|
||||||
### Config
|
### Config
|
||||||
|
|
||||||
You can override the default Pico settings (and add your own custom settings) by editing config.php in the root Pico directory. The config.php file
|
You can override the default Pico settings (and add your own custom settings) by editing config.php in the root Pico directory. The config.php file
|
||||||
|
29
lib/pico.php
29
lib/pico.php
@ -6,7 +6,7 @@
|
|||||||
* @author Gilbert Pellegrom
|
* @author Gilbert Pellegrom
|
||||||
* @link http://pico.dev7studios.com
|
* @link http://pico.dev7studios.com
|
||||||
* @license http://opensource.org/licenses/MIT
|
* @license http://opensource.org/licenses/MIT
|
||||||
* @version 0.6
|
* @version 0.6.1
|
||||||
*/
|
*/
|
||||||
class Pico {
|
class Pico {
|
||||||
|
|
||||||
@ -57,12 +57,11 @@ class Pico {
|
|||||||
|
|
||||||
$meta = $this->read_file_meta($content);
|
$meta = $this->read_file_meta($content);
|
||||||
$this->run_hooks('file_meta', array(&$meta));
|
$this->run_hooks('file_meta', array(&$meta));
|
||||||
$content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta
|
|
||||||
$content = $this->parse_content($content);
|
$content = $this->parse_content($content);
|
||||||
$this->run_hooks('content_parsed', array(&$content));
|
$this->run_hooks('content_parsed', array(&$content));
|
||||||
|
|
||||||
// Get all the pages
|
// Get all the pages
|
||||||
$pages = $this->get_pages($settings['base_url'], $settings['pages_order_by'], $settings['pages_order']);
|
$pages = $this->get_pages($settings['base_url'], $settings['pages_order_by'], $settings['pages_order'], $settings['excerpt_length']);
|
||||||
$prev_page = array();
|
$prev_page = array();
|
||||||
$current_page = array();
|
$current_page = array();
|
||||||
$next_page = array();
|
$next_page = array();
|
||||||
@ -131,6 +130,7 @@ class Pico {
|
|||||||
*/
|
*/
|
||||||
private function parse_content($content)
|
private function parse_content($content)
|
||||||
{
|
{
|
||||||
|
$content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta
|
||||||
$content = str_replace('%base_url%', $this->base_url(), $content);
|
$content = str_replace('%base_url%', $this->base_url(), $content);
|
||||||
$content = Markdown($content);
|
$content = Markdown($content);
|
||||||
|
|
||||||
@ -187,7 +187,8 @@ class Pico {
|
|||||||
'date_format' => 'jS M Y',
|
'date_format' => 'jS M Y',
|
||||||
'twig_config' => array('cache' => false, 'autoescape' => false, 'debug' => false),
|
'twig_config' => array('cache' => false, 'autoescape' => false, 'debug' => false),
|
||||||
'pages_order_by' => 'alpha',
|
'pages_order_by' => 'alpha',
|
||||||
'pages_order' => 'asc'
|
'pages_order' => 'asc',
|
||||||
|
'excerpt_length' => 50
|
||||||
);
|
);
|
||||||
|
|
||||||
if(is_array($config)) $config = array_merge($defaults, $config);
|
if(is_array($config)) $config = array_merge($defaults, $config);
|
||||||
@ -204,7 +205,7 @@ class Pico {
|
|||||||
* @param string $order order "asc" or "desc"
|
* @param string $order order "asc" or "desc"
|
||||||
* @return array $sorted_pages an array of pages
|
* @return array $sorted_pages an array of pages
|
||||||
*/
|
*/
|
||||||
private function get_pages($base_url, $order_by = 'alpha', $order = 'asc')
|
private function get_pages($base_url, $order_by = 'alpha', $order = 'asc', $excerpt_length = 50)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
@ -220,6 +221,7 @@ class Pico {
|
|||||||
// Get title and format $page
|
// Get title and format $page
|
||||||
$page_content = file_get_contents($page);
|
$page_content = file_get_contents($page);
|
||||||
$page_meta = $this->read_file_meta($page_content);
|
$page_meta = $this->read_file_meta($page_content);
|
||||||
|
$page_content = $this->parse_content($page_content);
|
||||||
$url = str_replace(CONTENT_DIR, $base_url .'/', $page);
|
$url = str_replace(CONTENT_DIR, $base_url .'/', $page);
|
||||||
$url = str_replace('index'. CONTENT_EXT, '', $url);
|
$url = str_replace('index'. CONTENT_EXT, '', $url);
|
||||||
$url = str_replace(CONTENT_EXT, '', $url);
|
$url = str_replace(CONTENT_EXT, '', $url);
|
||||||
@ -228,7 +230,9 @@ class Pico {
|
|||||||
'url' => $url,
|
'url' => $url,
|
||||||
'author' => $page_meta['author'],
|
'author' => $page_meta['author'],
|
||||||
'date' => $page_meta['date'],
|
'date' => $page_meta['date'],
|
||||||
'date_formatted' => date($config['date_format'], strtotime($page_meta['date']))
|
'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']] = $data;
|
if($order_by == 'date') $sorted_pages[$page_meta['date']] = $data;
|
||||||
else $sorted_pages[] = $data;
|
else $sorted_pages[] = $data;
|
||||||
@ -302,6 +306,19 @@ class Pico {
|
|||||||
}
|
}
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to limit the words in a string
|
||||||
|
*
|
||||||
|
* @param string $string the given string
|
||||||
|
* @param int $word_limit the number of words to limit to
|
||||||
|
* @return string the limited string
|
||||||
|
*/
|
||||||
|
private function limit_words($string, $word_limit)
|
||||||
|
{
|
||||||
|
$words = explode(' ',$string);
|
||||||
|
return trim(implode(' ', array_splice($words, 0, $word_limit))) .'...';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user