mirror of
https://github.com/danpros/htmly.git
synced 2026-04-21 13:06:22 +05:30
Simple subPages Integration added
Need work on edit page and menu.
This commit is contained in:
parent
8ea2611323
commit
a92b2ad997
3 changed files with 118 additions and 0 deletions
|
|
@ -1078,6 +1078,34 @@ get('/admin/update/now/:csrf', function($CSRF) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
get('/:static/:sub', function($static,$sub) {
|
||||||
|
|
||||||
|
$father_post = get_static_post($static);
|
||||||
|
if (!$father_post) {
|
||||||
|
not_found();
|
||||||
|
}
|
||||||
|
$post = get_static_sub_post($static,$sub);
|
||||||
|
if (!$post) {
|
||||||
|
not_found();
|
||||||
|
}
|
||||||
|
$post = $post[0];
|
||||||
|
|
||||||
|
add_view($post->file);
|
||||||
|
|
||||||
|
if (!login()) {
|
||||||
|
file_cache($_SERVER['REQUEST_URI']);
|
||||||
|
}
|
||||||
|
|
||||||
|
render('static-sub', array(
|
||||||
|
'head_contents' => head_contents($post->title . ' - ' . blog_title(), $description = get_description($post->body), $post->url),
|
||||||
|
'bodyclass' => 'inpage',
|
||||||
|
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> » <a href="' . $father_post[0]->url . '">' . $father_post[0]->title . '</a> » ' . $post->title,
|
||||||
|
'p' => $post,
|
||||||
|
'type' => 'staticpage',
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
// If we get here, it means that
|
// If we get here, it means that
|
||||||
// nothing has been matched above
|
// nothing has been matched above
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,33 @@ function get_static_pages() {
|
||||||
return $_page;
|
return $_page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get static page path. Unsorted.
|
||||||
|
function get_static_sub_pages($static = null) {
|
||||||
|
|
||||||
|
static $_sub_page = array();
|
||||||
|
|
||||||
|
if (empty($_sub_page)) {
|
||||||
|
$url = 'cache/index/index-sub-page.txt';
|
||||||
|
if(! file_exists($url)) {
|
||||||
|
rebuilt_cache('all');
|
||||||
|
}
|
||||||
|
$_sub_page = unserialize(file_get_contents($url));
|
||||||
|
}
|
||||||
|
if($static != null)
|
||||||
|
{
|
||||||
|
$stringLen = strlen($static);
|
||||||
|
return array_filter($_sub_page, function($sub_page)use($static,$stringLen){
|
||||||
|
$x = explode("/",$sub_page);
|
||||||
|
if($x[count($x)-2] == $static)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return $_sub_page;
|
||||||
|
}
|
||||||
|
|
||||||
// Get author bio path. Unsorted.
|
// Get author bio path. Unsorted.
|
||||||
function get_author_names() {
|
function get_author_names() {
|
||||||
|
|
||||||
|
|
@ -130,6 +157,11 @@ function rebuilt_cache($type) {
|
||||||
$page_cache = glob('content/static/*.md', GLOB_NOSORT);
|
$page_cache = glob('content/static/*.md', GLOB_NOSORT);
|
||||||
$string = serialize($page_cache);
|
$string = serialize($page_cache);
|
||||||
file_put_contents('cache/index/index-page.txt', print_r($string, true));
|
file_put_contents('cache/index/index-page.txt', print_r($string, true));
|
||||||
|
} elseif ($type === 'subpage') {
|
||||||
|
|
||||||
|
$page_cache = glob('content/static/*/*.md', GLOB_NOSORT);
|
||||||
|
$string = serialize($page_cache);
|
||||||
|
file_put_contents('cache/index/index-sub-page.txt', print_r($string, true));
|
||||||
} elseif ($type === 'author') {
|
} elseif ($type === 'author') {
|
||||||
|
|
||||||
$author_cache = glob('content/*/author.md', GLOB_NOSORT);
|
$author_cache = glob('content/*/author.md', GLOB_NOSORT);
|
||||||
|
|
@ -138,6 +170,7 @@ function rebuilt_cache($type) {
|
||||||
} elseif ($type === 'all') {
|
} elseif ($type === 'all') {
|
||||||
rebuilt_cache('posts');
|
rebuilt_cache('posts');
|
||||||
rebuilt_cache('page');
|
rebuilt_cache('page');
|
||||||
|
rebuilt_cache('subpage');
|
||||||
rebuilt_cache('author');
|
rebuilt_cache('author');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -466,6 +499,53 @@ function get_static_post($static) {
|
||||||
|
|
||||||
return $tmp;
|
return $tmp;
|
||||||
}
|
}
|
||||||
|
// Return static page.
|
||||||
|
function get_static_sub_post($static,$sub_static) {
|
||||||
|
|
||||||
|
$posts = get_static_sub_pages($static);
|
||||||
|
|
||||||
|
$tmp = array();
|
||||||
|
|
||||||
|
if (!empty($posts)) {
|
||||||
|
|
||||||
|
foreach ($posts as $index => $v) {
|
||||||
|
if (strpos($v, $sub_static . '.md') !== false) {
|
||||||
|
|
||||||
|
$post = new stdClass;
|
||||||
|
|
||||||
|
// Replaced string
|
||||||
|
$replaced = substr($v, 0, strrpos($v, '/')) . '/';
|
||||||
|
|
||||||
|
// The static page URL
|
||||||
|
$url = str_replace($replaced, '', $v);
|
||||||
|
$post->url = site_url() . $static . "/" . str_replace('.md', '', $url);
|
||||||
|
|
||||||
|
$post->file = $v;
|
||||||
|
|
||||||
|
// Get the contents and convert it to HTML
|
||||||
|
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
|
||||||
|
|
||||||
|
// Extract the title and body
|
||||||
|
$arr = explode('t-->', $content);
|
||||||
|
if (isset($arr[1])) {
|
||||||
|
$title = str_replace('<!--t', '', $arr[0]);
|
||||||
|
$title = rtrim(ltrim($title, ' '), ' ');
|
||||||
|
$post->title = $title;
|
||||||
|
$post->body = $arr[1];
|
||||||
|
} else {
|
||||||
|
$post->title = $sub_static;
|
||||||
|
$post->body = $arr[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$post->views = get_views($post->file);
|
||||||
|
|
||||||
|
$tmp[] = $post;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
// Return search page.
|
// Return search page.
|
||||||
function get_keyword($keyword, $page, $perpage) {
|
function get_keyword($keyword, $page, $perpage) {
|
||||||
|
|
|
||||||
10
themes/logs/static-sub.html.php
Normal file
10
themes/logs/static-sub.html.php
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php if (!empty($breadcrumb)):?><div class="breadcrumb" xmlns:v="http://rdf.data-vocabulary.org/#"><?php echo $breadcrumb ?></div><?php endif;?>
|
||||||
|
<?php if(login()) { echo tab($p);} ?>
|
||||||
|
<div class="post" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
|
||||||
|
<div class="main">
|
||||||
|
<h1 class="title-post" itemprop="name"><?php echo $p->title ?></h1>
|
||||||
|
<div class="post-body" itemprop="articleBody">
|
||||||
|
<?php echo $p->body; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue