From 2ae0cd949c331f83dcb05116cffdca21b2ecb871 Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Sun, 23 Oct 2011 18:10:46 +0530 Subject: [PATCH] next prev keyboard actions --- content/2011/09/{22 => }/arrive | 0 content/2011/09/beg | 9 +++++++++ content/2011/09/{27 => }/habitat | 0 content/2011/09/{28 => }/sriyantra | 0 content/2011/10/{06 => }/alphabet | 0 content/2011/10/{04 => }/dreams | 0 content/2011/10/dushera | 7 +++++++ content/2011/10/{05 => }/islands | 0 content/2011/10/{05 => }/overlords | 0 content/2011/10/smog | 5 +++++ content/2011/10/water_is_life | 8 ++++++++ css/style.css | 4 ++++ js/js.js | 26 ++++++++++++++++++++++++++ lib/data.php | 21 +++++++++++++++------ lib/init.php | 2 +- lib/model.php | 14 +++++++++++--- templates/default.html.tpl | 2 +- templates/footer.html.tpl | 2 ++ templates/head-inc.html.tpl | 1 + templates/nextprev.html.tpl | 10 ++++++++++ templates/single.html.tpl | 8 +++++--- 21 files changed, 105 insertions(+), 14 deletions(-) rename content/2011/09/{22 => }/arrive (100%) create mode 100644 content/2011/09/beg rename content/2011/09/{27 => }/habitat (100%) rename content/2011/09/{28 => }/sriyantra (100%) rename content/2011/10/{06 => }/alphabet (100%) rename content/2011/10/{04 => }/dreams (100%) create mode 100644 content/2011/10/dushera rename content/2011/10/{05 => }/islands (100%) rename content/2011/10/{05 => }/overlords (100%) create mode 100644 content/2011/10/smog create mode 100644 content/2011/10/water_is_life create mode 100644 js/js.js create mode 100644 templates/nextprev.html.tpl diff --git a/content/2011/09/22/arrive b/content/2011/09/arrive similarity index 100% rename from content/2011/09/22/arrive rename to content/2011/09/arrive diff --git a/content/2011/09/beg b/content/2011/09/beg new file mode 100644 index 0000000..5056e40 --- /dev/null +++ b/content/2011/09/beg @@ -0,0 +1,9 @@ +title = beg +date = Oct 16 2011, 15:34:03; IST +-- + + + + + +Tapping on the windows, the begger kids have perfected their methods. They move their mouths into a sad frown, they use their eyes, they tap on the windows. \ No newline at end of file diff --git a/content/2011/09/27/habitat b/content/2011/09/habitat similarity index 100% rename from content/2011/09/27/habitat rename to content/2011/09/habitat diff --git a/content/2011/09/28/sriyantra b/content/2011/09/sriyantra similarity index 100% rename from content/2011/09/28/sriyantra rename to content/2011/09/sriyantra diff --git a/content/2011/10/06/alphabet b/content/2011/10/alphabet similarity index 100% rename from content/2011/10/06/alphabet rename to content/2011/10/alphabet diff --git a/content/2011/10/04/dreams b/content/2011/10/dreams similarity index 100% rename from content/2011/10/04/dreams rename to content/2011/10/dreams diff --git a/content/2011/10/dushera b/content/2011/10/dushera new file mode 100644 index 0000000..73e05b2 --- /dev/null +++ b/content/2011/10/dushera @@ -0,0 +1,7 @@ +title = dushera +date = Sun, Oct 06 2011, 06:00:16 PM; IST +draft = true +-- + + +dushera \ No newline at end of file diff --git a/content/2011/10/05/islands b/content/2011/10/islands similarity index 100% rename from content/2011/10/05/islands rename to content/2011/10/islands diff --git a/content/2011/10/05/overlords b/content/2011/10/overlords similarity index 100% rename from content/2011/10/05/overlords rename to content/2011/10/overlords diff --git a/content/2011/10/smog b/content/2011/10/smog new file mode 100644 index 0000000..b5586f1 --- /dev/null +++ b/content/2011/10/smog @@ -0,0 +1,5 @@ +title = sun +date = Sun, Oct 23 2011, 06:06:33 PM; IST +-- + + diff --git a/content/2011/10/water_is_life b/content/2011/10/water_is_life new file mode 100644 index 0000000..d60a727 --- /dev/null +++ b/content/2011/10/water_is_life @@ -0,0 +1,8 @@ +title = water_is_life +date = Sun, Oct 23 2011, 06:04:38 PM; IST +draft = true +-- + + + +delapitated truck left near the Quotar Minar in Dadabari. Painting on the front bumper reads "Water is Life" in Hindi. \ No newline at end of file diff --git a/css/style.css b/css/style.css index 0a3766a..f10980a 100644 --- a/css/style.css +++ b/css/style.css @@ -9,6 +9,7 @@ body { a { color:rgb(198, 28, 111); + text-decoration:none; } a img { border:0; @@ -55,6 +56,9 @@ pre { padding:50px; background:#fff; } +#nextprev { + padding:0 50px 10px 50px; +} #nav { padding:30px 50px; border-top:1px dotted #aaa; diff --git a/js/js.js b/js/js.js new file mode 100644 index 0000000..e99e654 --- /dev/null +++ b/js/js.js @@ -0,0 +1,26 @@ +// javascript + +var init = ( function () { + + var LEFT = 37, RIGHT = 39; + + document.onkeypress = function(e) { + switch (e.keyCode) { + case LEFT : nextEntry(); break; + case RIGHT : prevEntry(); break; + } + } + + function prevEntry() { + if (typeof(PREV_ENTRY) != "undefined") { + window.location = PREV_ENTRY; + } + } + + function nextEntry() { + if (typeof(NEXT_ENTRY) != "undefined") { + window.location = NEXT_ENTRY; + } + } + +})(); diff --git a/lib/data.php b/lib/data.php index 5fceeb1..4ec23d3 100644 --- a/lib/data.php +++ b/lib/data.php @@ -37,6 +37,7 @@ function get_entries( $path = "", $args = array()) } } + switch ($order_by) { default : @@ -46,6 +47,14 @@ function get_entries( $path = "", $args = array()) array_multisort( $time, $order, $entries ); } + + // assign next/prev for each entry + $num_entries = count($entries); + for ($i = $num_entries-1; $i>=0; $i--) { + $entries[$i]['prev_entry'] = isset($entries[$i+1]) ? $entries[$i+1] : null; + $entries[$i]['next_entry'] = isset($entries[$i-1]) ? $entries[$i-1] : null; + } + return $entries; } @@ -86,6 +95,7 @@ function get_dirs( $path = "", $args = array()) return $dirs; } + /** * get all pages */ @@ -146,7 +156,6 @@ function parse_entry($fileInfo, $page = false) $cat = clean_slashes(str_replace(LOCAL_ROOT . CONTENT_DIR, "", $fileInfo->getPath())); $clean_path = str_replace(LOCAL_ROOT . CONTENT_DIR, "", clean_slashes($fileInfo->getPath())); - $f['cat'] = $page ? null : array('name' => $clean_path, 'url' => $clean_path ); $f['path'] = $fileInfo->getRealPath(); $f['url'] = ($page ? '' : $f['cat']['url'] . '/') . $fileInfo->getFilename(); @@ -160,17 +169,17 @@ function parse_entry($fileInfo, $page = false) } -function get_entry ( $relative_entry_path ) +function get_entry ( $relative_path ) { - return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, CONTENT_DIR, $relative_entry_path), DIRECTORY_SEPARATOR))); + return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, CONTENT_DIR, $relative_path), DIRECTORY_SEPARATOR))); } -function get_page ( $relative_page_path ) +function get_page ( $relative_path ) { - return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, PAGE_DIR, $relative_page_path), DIRECTORY_SEPARATOR)), 1); + return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, PAGE_DIR, $relative_path), DIRECTORY_SEPARATOR)), 1); } function parse_config ( $relative_path ) { return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, CONTENT_DIR, $relative_path, CONFIG_FILE), DIRECTORY_SEPARATOR))); -} \ No newline at end of file +} diff --git a/lib/init.php b/lib/init.php index c2e9436..8c030eb 100644 --- a/lib/init.php +++ b/lib/init.php @@ -40,4 +40,4 @@ require_once 'data.php'; require_once 'output.php'; require_once 'markdown.php'; require_once 'model.php'; -require_once 'view.php'; +require_once 'view.php'; \ No newline at end of file diff --git a/lib/model.php b/lib/model.php index 56dffca..d4f4991 100644 --- a/lib/model.php +++ b/lib/model.php @@ -25,11 +25,9 @@ class Model function parse_request( $request ) { - $this->content_request = join(array($this->request['dirname'], $this->request['filename']), DIRECTORY_SEPARATOR ); $this->page_request = $this->request['filename']; - # if entries (dir in CONTENT dir) if ($this->is_multiple()) { # check if config file exists in dir @@ -48,6 +46,17 @@ class Model else if ($this->is_single()) { $this->entry = get_entry( $this->content_request ); + + // heavy handed prev/next + $entries = get_entries(); + for($i = count($entries)-1; $i>=0; $i--) { + if ($this->entry['url'] == $entries[$i]['url']) { + $this->entry['prev_entry'] = $entries[$i]['prev_entry']; + $this->entry['next_entry'] = $entries[$i]['next_entry']; + break; + } + } + $this->template = 'single.' . $this->response_format . '.tpl'; } @@ -60,7 +69,6 @@ class Model 'page.' . $this->response_format . '.tpl'; } - # not found else { $this->template = '404.html.tpl'; diff --git a/templates/default.html.tpl b/templates/default.html.tpl index 7b6927c..9ae7ca8 100644 --- a/templates/default.html.tpl +++ b/templates/default.html.tpl @@ -8,7 +8,6 @@ - include_template('nav.html.tpl') ?>
@@ -24,6 +23,7 @@
include_template('footer.html.tpl') ?> + include_template('nav.html.tpl') ?> diff --git a/templates/footer.html.tpl b/templates/footer.html.tpl index 4ff0285..ec5b922 100644 --- a/templates/footer.html.tpl +++ b/templates/footer.html.tpl @@ -1,2 +1,4 @@ + + diff --git a/templates/head-inc.html.tpl b/templates/head-inc.html.tpl index 5f3b193..ae6fd8f 100644 --- a/templates/head-inc.html.tpl +++ b/templates/head-inc.html.tpl @@ -3,3 +3,4 @@ + diff --git a/templates/nextprev.html.tpl b/templates/nextprev.html.tpl new file mode 100644 index 0000000..ea2b652 --- /dev/null +++ b/templates/nextprev.html.tpl @@ -0,0 +1,10 @@ + + + prev + + + + + next + + diff --git a/templates/single.html.tpl b/templates/single.html.tpl index b2348d0..cae3f02 100644 --- a/templates/single.html.tpl +++ b/templates/single.html.tpl @@ -8,13 +8,15 @@ -
- include_template('entry.html.tpl'); ?> + include_template('entry.html.tpl'); ?>
- include_template('nav.html.tpl') ?> +
+ include_template('nextprev.html.tpl'); ?> +
+ include_template('nav.html.tpl') ?> include_template('footer.html.tpl') ?> -- 2.34.1