[New] Add get_pages() function for listing content
[New] Added changelog.txt
[Changed] Updated default theme
[Changed] Updated documentation
This commit is contained in:
Gilbert Pellegrom 2013-05-01 14:34:24 +01:00
parent 585a39a800
commit cc7ceafc1e
9 changed files with 280 additions and 88 deletions

19
changelog.txt Normal file
View File

@ -0,0 +1,19 @@
*** Pico Changelog ***
2013.05.01 - version 0.4
* [New] Add get_pages() function for listing content
* [New] Added changelog.txt
* [Changed] Updated default theme
* [Changed] Updated documentation
2013.04.27 - version 0.3
* [Fixed] get_config() function
2013.04.26 - version 0.2
* [Changed] Updated Twig
* [Changed] Better checking for HTTPS
* [Fixed] Add 404 header to 404 page
* [Fixed] Case sensitive folder bug
2012.04.04 - version 0.1
* Initial release

View File

@ -3,13 +3,11 @@ Title: Welcome
Description: This description will go in the meta description tag Description: This description will go in the meta description tag
*/ */
Welcome to Pico ## Welcome to Pico
===============
Congratulations you have successfully installed [Pico](http://pico.dev7studios.com). Pico is a stupidly simple, blazing fast, flat file CMS. Congratulations you have successfully installed [Pico](http://pico.dev7studios.com). Pico is a stupidly simple, blazing fast, flat file CMS.
Creating Content ### Creating Content
----------------
Pico is a flat file CMS, this means there is no administration backend and database to deal with. You simply create `.txt` files in the "content" Pico is a flat file CMS, this means there is no administration backend and database to deal with. You simply create `.txt` files in the "content"
folder and that becomes a page. For example this file is called `index.txt` and is shown as the main landing page. folder and that becomes a page. For example this file is called `index.txt` and is shown as the main landing page.
@ -33,8 +31,7 @@ and will be able to access it from the URL `http://yousite.com/sub/page`. Below
If a file cannot be found, the file `content/404.txt` will be shown. If a file cannot be found, the file `content/404.txt` will be shown.
Text File Markup ### Text File Markup
----------------
Text files are marked up using [Markdown](http://daringfireball.net/projects/markdown/syntax). They can also contain regular HTML. Text files are marked up using [Markdown](http://daringfireball.net/projects/markdown/syntax). They can also contain regular HTML.
@ -50,10 +47,9 @@ These values will be contained in the `{{ meta }}` variable in themes (see below
There are also certain variables that you can use in your text files: There are also certain variables that you can use in your text files:
* &#37;base_url&#37; - The URL to your Pico site * <code>&#37;base_url&#37;</code> - The URL to your Pico site
Themes ### Themes
------
You can create themes for your Pico installation and in the "themes" folder. Check out the default theme for an example of a theme. Pico uses You can create themes for your Pico installation and in the "themes" folder. Check out the default theme for an example of a theme. Pico uses
[Twig](http://twig.sensiolabs.org/documentation) for it's templating engine. You can select your theme by setting the `$config['theme']` variable [Twig](http://twig.sensiolabs.org/documentation) for it's templating engine. You can select your theme by setting the `$config['theme']` variable
@ -69,9 +65,15 @@ All themes must include an `index.html` file to define the HTML structure of the
* `{{ site_title }}` - Shortcut to the site title (defined in config.php) * `{{ site_title }}` - Shortcut to the site title (defined in config.php)
* `{{ meta }}` - Contains the meta values from the current page (e.g. `{{ meta.title }}`, `{{ meta.description }}`, `{{ meta.robots }}`) * `{{ meta }}` - Contains the meta values from the current page (e.g. `{{ meta.title }}`, `{{ meta.description }}`, `{{ meta.robots }}`)
* `{{ content }}` - The content of the current page (after it has been processed through Markdown) * `{{ content }}` - The content of the current page (after it has been processed through Markdown)
* `{{ pages }}` - A collection of all the content in your site. Use it like:
Config <pre>&lt;ul class=&quot;nav&quot;&gt;
------ {% for page in pages %}
&lt;li&gt;&lt;a href=&quot;{{ page.url }}&quot;&gt;{{ page.title }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
&lt;/ul&gt;</pre>
### 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
list all of the settings and their defaults. To override a setting simply uncomment it in config.php and set your custom value. list all of the settings and their defaults. To override a setting simply uncomment it in config.php and set your custom value.

View File

@ -2,5 +2,10 @@
Title: Sub Page Index Title: Sub Page Index
*/ */
This is a Sub Page Index ## This is a Sub Page Index
========================
This is index.txt in the "sub" folder.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ultricies tristique nulla et mattis. Phasellus id massa eget nisl congue blandit sit amet id ligula. Praesent et nulla eu augue tempus sagittis. Mauris faucibus nibh et nibh cursus in vestibulum sapien egestas. Curabitur ut lectus tortor. Sed ipsum eros, egestas ut eleifend non, elementum vitae eros. Mauris felis diam, pellentesque vel lacinia ac, dictum a nunc. Mauris mattis nunc sed mi sagittis et facilisis tortor volutpat. Etiam tincidunt urna mattis erat placerat placerat ac eu tellus. Ut nec velit id nisl tincidunt vehicula id a metus. Pellentesque erat neque, faucibus id ultricies vel, mattis in ante. Donec lobortis, mauris id congue scelerisque, diam nisl accumsan orci, condimentum porta est magna vel arcu. Curabitur varius ante dui. Vivamus sit amet ante ac diam ullamcorper sodales sed a odio.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ultricies tristique nulla et mattis. Phasellus id massa eget nisl congue blandit sit amet id ligula. Praesent et nulla eu augue tempus sagittis. Mauris faucibus nibh et nibh cursus in vestibulum sapien egestas. Curabitur ut lectus tortor. Sed ipsum eros, egestas ut eleifend non, elementum vitae eros. Mauris felis diam, pellentesque vel lacinia ac, dictum a nunc. Mauris mattis nunc sed mi sagittis et facilisis tortor volutpat. Etiam tincidunt urna mattis erat placerat placerat ac eu tellus. Ut nec velit id nisl tincidunt vehicula id a metus. Pellentesque erat neque, faucibus id ultricies vel, mattis in ante. Donec lobortis, mauris id congue scelerisque, diam nisl accumsan orci, condimentum porta est magna vel arcu. Curabitur varius ante dui. Vivamus sit amet ante ac diam ullamcorper sodales sed a odio.

View File

@ -2,5 +2,10 @@
Title: Sub Page Title: Sub Page
*/ */
This is a Sub Page ## This is a Sub Page
==================
This is page.txt in the "sub" folder.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ultricies tristique nulla et mattis. Phasellus id massa eget nisl congue blandit sit amet id ligula. Praesent et nulla eu augue tempus sagittis. Mauris faucibus nibh et nibh cursus in vestibulum sapien egestas. Curabitur ut lectus tortor. Sed ipsum eros, egestas ut eleifend non, elementum vitae eros. Mauris felis diam, pellentesque vel lacinia ac, dictum a nunc. Mauris mattis nunc sed mi sagittis et facilisis tortor volutpat. Etiam tincidunt urna mattis erat placerat placerat ac eu tellus. Ut nec velit id nisl tincidunt vehicula id a metus. Pellentesque erat neque, faucibus id ultricies vel, mattis in ante. Donec lobortis, mauris id congue scelerisque, diam nisl accumsan orci, condimentum porta est magna vel arcu. Curabitur varius ante dui. Vivamus sit amet ante ac diam ullamcorper sodales sed a odio.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ultricies tristique nulla et mattis. Phasellus id massa eget nisl congue blandit sit amet id ligula. Praesent et nulla eu augue tempus sagittis. Mauris faucibus nibh et nibh cursus in vestibulum sapien egestas. Curabitur ut lectus tortor. Sed ipsum eros, egestas ut eleifend non, elementum vitae eros. Mauris felis diam, pellentesque vel lacinia ac, dictum a nunc. Mauris mattis nunc sed mi sagittis et facilisis tortor volutpat. Etiam tincidunt urna mattis erat placerat placerat ac eu tellus. Ut nec velit id nisl tincidunt vehicula id a metus. Pellentesque erat neque, faucibus id ultricies vel, mattis in ante. Donec lobortis, mauris id congue scelerisque, diam nisl accumsan orci, condimentum porta est magna vel arcu. Curabitur varius ante dui. Vivamus sit amet ante ac diam ullamcorper sodales sed a odio.

View File

@ -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.3 * @version 0.4
*/ */
class Pico { class Pico {
@ -46,6 +46,9 @@ class Pico {
$settings = $this->get_config(); $settings = $this->get_config();
$env = array('autoescape' => false); $env = array('autoescape' => false);
if($settings['enable_cache']) $env['cache'] = CACHE_DIR; if($settings['enable_cache']) $env['cache'] = CACHE_DIR;
// Get all the pages
$pages = $this->get_pages($settings['base_url']);
// Load the theme // Load the theme
Twig_Autoloader::register(); Twig_Autoloader::register();
@ -59,7 +62,8 @@ class Pico {
'theme_url' => $settings['base_url'] .'/'. basename(THEMES_DIR) .'/'. $settings['theme'], 'theme_url' => $settings['base_url'] .'/'. basename(THEMES_DIR) .'/'. $settings['theme'],
'site_title' => $settings['site_title'], 'site_title' => $settings['site_title'],
'meta' => $meta, 'meta' => $meta,
'content' => $content 'content' => $content,
'pages' => $pages
)); ));
} }
@ -126,6 +130,37 @@ class Pico {
return $config; return $config;
} }
/**
* Get a list of pages
*
* @param string $base_url the base URL of the site
* @return array $pages an array of pages
*/
function get_pages($base_url)
{
$pages = $this->glob_recursive(CONTENT_DIR .'*.txt');
foreach($pages as $key=>$page){
// Skip 404
if(basename($page) == '404.txt'){
unset($pages[$key]);
continue;
}
// Get title and format $page
$page_content = file_get_contents($page);
$page_meta = $this->read_file_meta($page_content);
$url = str_replace(CONTENT_DIR, $base_url .'/', $page);
$url = str_replace('index.txt', '', $url);
$url = str_replace('.txt', '', $url);
$pages[$key] = array(
'title' => $page_meta['title'],
'url' => $url
);
}
return $pages;
}
/** /**
* Helper function to work out the base URL * Helper function to work out the base URL
@ -156,6 +191,22 @@ class Pico {
preg_match("|^HTTP[S]?|is",$_SERVER['SERVER_PROTOCOL'],$m); preg_match("|^HTTP[S]?|is",$_SERVER['SERVER_PROTOCOL'],$m);
return strtolower($m[0]); return strtolower($m[0]);
} }
/**
* Helper function to make glob recursive
*
* @param string $pattern glob pattern
* @param int $flags glob flags
* @return array the matched files/directories
*/
function glob_recursive($pattern, $flags = 0)
{
$files = glob($pattern, $flags);
foreach(glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir){
$files = array_merge($files, $this->glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}
} }

View File

@ -1,23 +1,45 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" class="no-js"> <html lang="en" class="no-js">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>{% if meta.title %}{{ meta.title }} | {% endif %}{{ site_title }}</title> <title>{% if meta.title %}{{ meta.title }} | {% endif %}{{ site_title }}</title>
{% if meta.description %}<meta name="description" content="{{ meta.description }}">{% endif %} {% if meta.description %}
{% if meta.robots %}<meta name="robots" content="{{ meta.robots }}">{% endif %} <meta name="description" content="{{ meta.description }}">
{% endif %}{% if meta.robots %}
<link rel="stylesheet" href="{{ theme_url }}/style.css" type="text/css" media="screen" /> <meta name="robots" content="{{ meta.robots }}">
{% endif %}
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,700" type="text/css" />
<script type="text/javascript" src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <link rel="stylesheet" href="{{ theme_url }}/style.css" type="text/css" />
<![endif]-->
<script src="{{ theme_url }}/scripts/modernizr-1.7.min.js"></script> <script src="{{ theme_url }}/scripts/modernizr-2.6.1.min.js"></script>
</head> </head>
<body> <body>
{{ content }} <header id="header">
<div class="inner clearfix">
<h1><a href="{{ base_url }}">{{ site_title }}</a></h1>
<ul class="nav">
{% for page in pages %}
<li><a href="{{ page.url }}">{{ page.title }}</a></li>
{% endfor %}
</ul>
</div>
</header>
<section id="content">
<div class="inner">
{{ content }}
</div>
</section>
<footer id="footer">
<div class="inner">
<a href="http://pico.dev7studios.com">Pico</a> was made by <a href="http://gilbert.pellegrom.me">Gilbert Pellegrom</a>
from <a href="http://dev7studios.com">Dev7studios</a>.
</div>
</footer>
</body> </body>
</html> </html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -4,9 +4,8 @@
/* http: //dev7studios.com /* http: //dev7studios.com
/*=================================*/ /*=================================*/
/*====================*/ /* Reset Styles
/*=== Reset Styles ===*/ /*---------------------------------------------*/
/*====================*/
html, body, div, span, applet, object, iframe, html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre, h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code, a, abbr, acronym, address, big, cite, code,
@ -25,75 +24,119 @@ table, caption, tbody, tfoot, thead, tr, th, td {
font-family: inherit; font-family: inherit;
vertical-align: baseline; vertical-align: baseline;
} }
body { body {
line-height: 1; line-height: 1;
color: black; color: black;
background: white; background: white;
} }
table { table {
border-collapse: separate; border-collapse: separate;
border-spacing: 0; border-spacing: 0;
} }
caption, th, td { caption, th, td {
text-align: left; text-align: left;
font-weight: normal; font-weight: normal;
} }
blockquote:before, blockquote:after, blockquote:before, blockquote:after,
q:before, q:after { q:before, q:after {
content: ""; content: "";
} }
blockquote, q { blockquote, q {
quotes: "" ""; quotes: "" "";
} }
/* HTML5 tags */ /* HTML5 tags */
header, section, footer, header, section, footer,
aside, nav, article, figure { aside, nav, article, figure {
display: block; display: block;
} }
/*===================*/ /* hand cursor on clickable input elements */
/*=== Main Styles ===*/ label, input[type=button], input[type=submit], button {
/*===================*/ cursor: pointer;
body { }
font: 14px/1.6 "Helvetica Neue", Helvetica, Arial, sans-serif;
/* make buttons play nice in IE:
www.viget.com/inspire/styling-the-button-element-in-internet-explorer/ */
button {
width: auto;
overflow: visible;
}
/* Sharper Thumbnails */
img {
-ms-interpolation-mode: bicubic;
}
/* Input Styles
/*---------------------------------------------*/
input,
textarea,
select {
padding: 5px;
font: 400 1em Verdana, Sans-serif;
color: #666;
background: #fff;
border: 1px solid #999999;
margin: 0 0 1em 0;
}
input:focus,
textarea:focus,
select:focus {
color: #000; color: #000;
background: #fff; background: #fff;
padding: 40px; border: 1px solid #666666;
}
/* Main Styles
/*---------------------------------------------*/
body {
font: 14px/1.8em 'Open Sans', Helvetica, Arial, Helvetica, sans-serif;
color: #444;
background: #fff;
-webkit-font-smoothing: antialiased;
} }
a, a:visited { a, a:visited {
color: blue; color: #2EAE9B;
text-decoration: none; text-decoration: none;
border-bottom: 1px solid blue; -webkit-transition: all 0.2s linear;
-moz-transition: all 0.2s linear;
-ms-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
} }
a:hover, a:active { a:hover, a:active {
color: #000; color: #000;
text-decoration: none; text-decoration: none;
} }
h1, h2, h3, h4, h5, h6 { h1, h2, h3, h4, h5, h6 {
line-height: 1.2; color: #000;
line-height: 1.2em;
margin-bottom: 0.6em; margin-bottom: 0.6em;
} }
h1 { h1 {
font-size: 2.2em; font-size: 2em;
} }
h2 { h2 {
font-size: 1.9em;
}
h3 {
font-size: 1.7em; font-size: 1.7em;
}
h3 {
font-size: 1.5em;
margin-top: 2em; margin-top: 2em;
} }
h4 {
font-size: 1.5em;
}
h5 {
font-size: 1.3em;
}
h6 {
font-size: 1.2em;
}
p { p {
margin-bottom: 1em; margin-bottom: 1em;
} }
@ -106,65 +149,108 @@ ol, ul {
b, strong { b, strong {
font-weight: bold; font-weight: bold;
} }
i, em { i, em {
font-style: italic; font-style: italic;
} }
u { u {
text-decoration: underline; text-decoration: underline;
} }
abbr, acronym { abbr, acronym {
cursor: help; cursor: help;
border-bottom: .1em dotted; border-bottom: 0.1em dotted;
}
td, td img {
vertical-align: top;
}
sub {
vertical-align: sub;
font-size: smaller;
}
sup {
vertical-align: super;
font-size: smaller;
} }
td, td img { vertical-align: top; }
sub { vertical-align: sub; font-size: smaller; }
sup { vertical-align: super; font-size: smaller; }
code { code {
font-family: Courier,"Courier New",Monaco,Tahoma; font-family: Courier, "Courier New", Monaco, Tahoma;
background: #eee; background: #eee;
color: #000; color: #333;
padding: 0px 2px; padding: 0px 2px;
} }
pre { pre {
background: #eee; background: #eee;
padding: 20px; padding: 20px;
margin-bottom: 1em; margin-bottom: 1em;
overflow: auto;
} }
blockquote { blockquote {
font-style: italic; font-style: italic;
margin: 0 0 1em 15px; margin: 0 0 1em 15px;
padding-left: 10px; padding-left: 10px;
border-left: 5px solid #999; border-left: 5px solid #dddddd;
} }
/* hand cursor on clickable input elements */ /* Structure Styles
label, input[type=button], input[type=submit], button { cursor: pointer; } /*---------------------------------------------*/
/* make buttons play nice in IE: .inner {
www.viget.com/inspire/styling-the-button-element-in-internet-explorer/ */ width: 850px;
button { width: auto; overflow: visible; } margin: 0 auto;
}
table { margin-bottom: 1em; } #header {
th { background: #2EAE9B;
padding: 60px 0;
margin-bottom: 80px;
color: #afe1da;
}
#header a { color: #afe1da; }
#header h1 a,
#header a:hover { color: #fff; }
#header h1 {
font-weight: bold; font-weight: bold;
padding: 0 5px; margin: 0;
float: left;
}
#header .nav {
float: right;
list-style: none;
margin: 0;
padding: 0;
}
#header .nav li { display: inline; }
#header .nav a {
font-weight: bold;
margin-left: 20px;
} }
td { padding: 0 5px; }
/*====================*/ #footer {
/*=== Other Styles ===*/ background: #707070;
/*====================*/ padding: 60px 0;
margin-top: 80px;
color: #C0C0C0;
}
#footer a { color: #ddd; }
#footer a:hover { color: #fff; }
/* Clearfix */ /* Misc Styles
.cf:before, /*---------------------------------------------*/
.cf:after { .clearfix:before,
content:""; .clearfix:after {
display:table; content: " ";
display: table;
} }
.cf:after { .clearfix:after {
clear:both; clear: both;
} }
/* For IE 6/7 (trigger hasLayout) */ .clearfix {
.cf { *zoom: 1;
zoom:1; }
}