/
index.php
55 lines (44 loc) · 1.78 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* @copyright Copyright (C) 2015 hiphper, All rights reserved.
* @license GNU/GPL V2 http://gnu.org/licenses/gpl-2.0.html
* @author hiphper at 163 dot com
* @link https://github.com/hi-phper/xieblog
*/
require 'vendor/autoload.php';
use HiPhper\XieBlog\Config;
use HiPhper\XieBlog\Post;
use JasonGrimes\Paginator;
$config = new Config('config.json');
Flight::set('flight.views.path', './templates/' . $config->get('template'));
Flight::route('/', function() use ($config) {
$post = new Post();
$page = 1;
$posts = $post->getPosts($page, $config->get('per_page'));
$totalItems = count($post->getPostNames());
$urlPattern = $config->get('base_url') . 'page/(:num)';
$paginator = new Paginator($totalItems, $config->get('per_page'), $page, $urlPattern);
Flight::render('index', array('posts' => $posts, 'config' => $config, 'paginator' => $paginator), 'content_layout');
Flight::render('layouts/default');
});
Flight::route('/page/@page', function($page) use ($config) {
$post = new Post();
$posts = $post->getPosts($page, $config->get('per_page'));
$totalItems = count($post->getPostNames());
$urlPattern = $config->get('base_url') . 'page/(:num)';
$paginator = new Paginator($totalItems, $config->get('per_page'), $page, $urlPattern);
Flight::render('index', ['posts'=>$posts, 'config'=>$config, 'paginator'=>$paginator], 'content_layout');
Flight::render('layouts/default');
});
Flight::route('/posts/@name', function($name) use ($config) {
$name = str_replace('../', '', $name);
$name = 'posts/' . $name . '.md';
if(file_exists($name)) {
$onePost = new Post();
$onePost->setListView(FALSE);
$post = $onePost->getPost($name);
Flight::render('post', ['post'=>$post, 'config'=>$config], 'content_layout');
Flight::render('layouts/default');
}
});
Flight::start();