Permalink
Browse files

Latest entry detection and subdirectory parsing

  • Loading branch information...
jackmcdade committed Mar 30, 2012
1 parent 65630fe commit b69d54c52c5f78bb8ab02d507d3ae56bc2d2d148
Showing with 31 additions and 10 deletions.
  1. 0 README
  2. +0 −1 config.yaml
  3. +2 −0 content/20120330/index.php
  4. +1 −0 content/20120330/meta.yaml
  5. +28 −9 index.php
View
0 README
No changes.
View
@@ -3,6 +3,5 @@ siteName: Chronical Default Title
defaultTitle: Untitled
dateFormat: Ymd
contentDir: './content'
debug: true
@@ -0,0 +1,2 @@
<h1><?= $title ?></h1>
May 30th.
@@ -0,0 +1 @@
title: Finally!
View
@@ -1,13 +1,18 @@
<?php
if(phpversion() < 5.3) {
die('<h3>Chronical requires PHP/5.3 or higher.<br>You are currently running PHP/'.phpversion().'.</h3><p>Time to upgrade.</p>');
}
require 'app/Slim.php';
require 'app/parsers/spyc.php';
require 'app/helpers.php';
$config = Spyc::YAMLLoad('config.yaml');
$app = new Slim(array(
'debug' => $config['debug'],
'templates.path' => $config['contentDir']
'templates.path' => 'content'
));
// Sitewide global config
@@ -16,7 +21,6 @@
// This is today
$app->today = date($app->config['dateFormat']);
/**
* Functions
*
@@ -31,21 +35,30 @@ function get_meta($date) {
$defaults = array(
'title' => $app->config['defaultTitle']
);
$meta = Spyc::YAMLLoad($app->config['contentDir'] .'/'. $date .'/meta.yaml');
$meta = Spyc::YAMLLoad('content/'. $date .'/meta.yaml');
return array_merge($defaults, $meta);
}
// @todo functions
function parse_content()
function get_directories()
{
// probably should be a class
$app = Slim::getInstance();
$dirs = array_filter(glob('content/*', GLOB_ONLYDIR), 'is_dir');
// remove the archive dir
$archive = array_search('content/archive', $dirs);
if ($archive)
unset($dirs[$archive]);
return $dirs;
}
function find_latest()
{
$app = Slim::getInstance();
{
$dirs = get_directories();
$latest = end($dirs);
return get_dir_endpoint($latest);
}
function find_next()
@@ -57,6 +70,12 @@ function find_prev()
{
$app = Slim::getInstance();
}
function get_dir_endpoint($dir)
{
$dir_array = explode('/', $dir);
return end($dir_array);
}
//
/**
@@ -70,7 +89,7 @@ function find_prev()
$app->get('/', function () use ($app) {
// @todo make this the "latest", not just today
$app->redirect($app->today);
$app->redirect(find_latest());
});

0 comments on commit b69d54c

Please sign in to comment.