[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
*/
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.
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"
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.
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.
@ -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:
* %base_url% - 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
[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)
* `{{ 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)
* `{{ 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
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
*/
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
*/
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
* @link http://pico.dev7studios.com/
* @license http://opensource.org/licenses/MIT
* @version 0.3
* @version 0.4
*/
class Pico {
@ -46,6 +46,9 @@ class Pico {
$settings = $this->get_config();
$env = array('autoescape' => false);
if($settings['enable_cache']) $env['cache'] = CACHE_DIR;
// Get all the pages
$pages = $this->get_pages($settings['base_url']);
// Load the theme
Twig_Autoloader::register();
@ -59,7 +62,8 @@ class Pico {
'theme_url' => $settings['base_url'] .'/'. basename(THEMES_DIR) .'/'. $settings['theme'],
'site_title' => $settings['site_title'],
'meta' => $meta,
'content' => $content
'content' => $content,
'pages' => $pages
));
}
@ -126,6 +130,37 @@ class Pico {
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
@ -156,6 +191,22 @@ class Pico {
preg_match("|^HTTP[S]?|is",$_SERVER['SERVER_PROTOCOL'],$m);
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>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8" />
<title>{% if meta.title %}{{ meta.title }} | {% endif %}{{ site_title }}</title>
{% if meta.description %}<meta name="description" content="{{ meta.description }}">{% endif %}
{% if meta.robots %}<meta name="robots" content="{{ meta.robots }}">{% endif %}
<link rel="stylesheet" href="{{ theme_url }}/style.css" type="text/css" media="screen" />
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script type="text/javascript" src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="{{ theme_url }}/scripts/modernizr-1.7.min.js"></script>
<meta charset="utf-8" />
<title>{% if meta.title %}{{ meta.title }} | {% endif %}{{ site_title }}</title>
{% if meta.description %}
<meta name="description" content="{{ meta.description }}">
{% endif %}{% if meta.robots %}
<meta name="robots" content="{{ meta.robots }}">
{% 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>
{{ 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>
</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
/*=================================*/
/*====================*/
/*=== Reset Styles ===*/
/*====================*/
/* Reset Styles
/*---------------------------------------------*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
@ -25,75 +24,119 @@ table, caption, tbody, tfoot, thead, tr, th, td {
font-family: inherit;
vertical-align: baseline;
}
body {
line-height: 1;
color: black;
background: white;
}
table {
border-collapse: separate;
border-spacing: 0;
}
caption, th, td {
text-align: left;
font-weight: normal;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: "";
}
blockquote, q {
quotes: "" "";
}
/* HTML5 tags */
header, section, footer,
aside, nav, article, figure {
display: block;
}
/*===================*/
/*=== Main Styles ===*/
/*===================*/
body {
font: 14px/1.6 "Helvetica Neue", Helvetica, Arial, sans-serif;
/* hand cursor on clickable input elements */
label, input[type=button], input[type=submit], button {
cursor: pointer;
}
/* 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;
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 {
color: blue;
color: #2EAE9B;
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 {
color: #000;
text-decoration: none;
}
h1, h2, h3, h4, h5, h6 {
line-height: 1.2;
color: #000;
line-height: 1.2em;
margin-bottom: 0.6em;
}
h1 {
font-size: 2.2em;
font-size: 2em;
}
h2 {
font-size: 1.9em;
}
h3 {
font-size: 1.7em;
}
h3 {
font-size: 1.5em;
margin-top: 2em;
}
h4 {
font-size: 1.5em;
}
h5 {
font-size: 1.3em;
}
h6 {
font-size: 1.2em;
}
p {
margin-bottom: 1em;
}
@ -106,65 +149,108 @@ ol, ul {
b, strong {
font-weight: bold;
}
i, em {
font-style: italic;
}
u {
text-decoration: underline;
}
abbr, acronym {
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 {
font-family: Courier,"Courier New",Monaco,Tahoma;
font-family: Courier, "Courier New", Monaco, Tahoma;
background: #eee;
color: #000;
color: #333;
padding: 0px 2px;
}
pre {
background: #eee;
padding: 20px;
margin-bottom: 1em;
overflow: auto;
}
blockquote {
font-style: italic;
margin: 0 0 1em 15px;
padding-left: 10px;
border-left: 5px solid #999;
border-left: 5px solid #dddddd;
}
/* hand cursor on clickable input elements */
label, input[type=button], input[type=submit], button { cursor: pointer; }
/* make buttons play nice in IE:
www.viget.com/inspire/styling-the-button-element-in-internet-explorer/ */
button { width: auto; overflow: visible; }
/* Structure Styles
/*---------------------------------------------*/
.inner {
width: 850px;
margin: 0 auto;
}
table { margin-bottom: 1em; }
th {
#header {
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;
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; }
/*====================*/
/*=== Other Styles ===*/
/*====================*/
#footer {
background: #707070;
padding: 60px 0;
margin-top: 80px;
color: #C0C0C0;
}
#footer a { color: #ddd; }
#footer a:hover { color: #fff; }
/* Clearfix */
.cf:before,
.cf:after {
content:"";
display:table;
/* Misc Styles
/*---------------------------------------------*/
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.cf:after {
clear:both;
.clearfix:after {
clear: both;
}
/* For IE 6/7 (trigger hasLayout) */
.cf {
zoom:1;
}
.clearfix {
*zoom: 1;
}