Add new vars for easy theming

This commit is contained in:
danpros 2024-11-19 12:33:54 +07:00
commit 973a2c5a05
2 changed files with 55 additions and 9 deletions

View file

@ -80,6 +80,15 @@ get('/index', function () {
$pview = 'main';
}
$tblog = new stdClass;
$tblog->title = blog_tagline();
$tblog->url = site_url();
$tblog->count = count(get_blog_posts());
$tblog->description = blog_description();
$tblog->body = $tblog->description;
$tblog->rss = site_url() . 'feed/rss';
$tblog->slug = site_path();
if (empty($posts) || $page < 1) {
// a non-existing page
@ -110,11 +119,13 @@ get('/index', function () {
'metatags' => generate_meta(null, null),
'page' => $page,
'posts' => $posts,
'taxonomy' => $tblog,
'bodyclass' => 'in-front',
'breadcrumb' => '',
'pagination' => has_pagination($total, $perpage, $page),
'type' => 'is_frontpage',
'is_front' => true
'is_front' => true,
'is_taxonomy' => true
), $layout);
}
@ -2858,10 +2869,12 @@ get('/category/:category', function ($category) {
'page' => $page,
'posts' => $posts,
'category' => $desc,
'taxonomy' => $desc,
'bodyclass' => 'in-category category-' . strtolower($category),
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $desc->title,
'pagination' => has_pagination($total, $perpage, $page),
'is_category' => true
'is_category' => true,
'is_taxonomy' => true
), $layout);
});
@ -3074,6 +3087,8 @@ get('/type/:type', function ($type) {
$ttype->count = $total;
$ttype->description = i18n('Posts_with_type') . ' ' . ucfirst($type) . ' ' . i18n('by') . ' ' . blog_title();
$ttype->body = $ttype->description;
$ttype->rss = $ttype->url . '/feed';
$ttype->slug = strtolower($type);
if (empty($posts) || $page < 1) {
// a non-existing page
@ -3116,10 +3131,12 @@ get('/type/:type', function ($type) {
'page' => $page,
'posts' => $posts,
'type' => $ttype,
'taxonomy' => $ttype,
'bodyclass' => 'in-type type-' . strtolower($type),
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . ucfirst($type),
'pagination' => has_pagination($total, $perpage, $page),
'is_type' => true
'is_type' => true,
'is_taxonomy' => true
), $layout);
});
@ -3159,6 +3176,8 @@ get('/tag/:tag', function ($tag) {
$ttag->count = $total;
$ttag->description = i18n('All_posts_tagged') . ' ' . tag_i18n($tag) . ' ' . i18n('by') . ' ' . blog_title();
$ttag->body = $ttag->description;
$ttag->rss = $ttag->url . '/feed';
$ttag->slug = strtolower($tag);
if (empty($posts) || $page < 1) {
// a non-existing page
@ -3201,10 +3220,12 @@ get('/tag/:tag', function ($tag) {
'page' => $page,
'posts' => $posts,
'tag' => $ttag,
'taxonomy' => $ttag,
'bodyclass' => 'in-tag tag-' . strtolower($tag),
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Posts_tagged') . ' ' . tag_i18n($tag),
'pagination' => has_pagination($total, $perpage, $page),
'is_tag' => true
'is_tag' => true,
'is_taxonomy' => true
), $layout);
});
@ -3260,6 +3281,8 @@ get('/archive/:req', function ($req) {
$tarchive->count = $total;
$tarchive->description = i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title();
$tarchive->body = $tarchive->description;
$tarchive->rss = $tarchive->url . '/feed';
$tarchive->slug = strtolower($req);
if (!$date) {
// a non-existing page
@ -3296,10 +3319,12 @@ get('/archive/:req', function ($req) {
'page' => $page,
'posts' => $posts,
'archive' => $tarchive,
'taxonomy' => $tarchive,
'bodyclass' => 'in-archive archive-' . strtolower($req),
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Archive_for') . ' ' . $timestamp,
'pagination' => has_pagination($total, $perpage, $page),
'is_archive' => true
'is_archive' => true,
'is_taxonomy' => true
), $layout);
});
@ -3350,6 +3375,8 @@ get('/search/:keyword', function ($keyword) {
$tsearch->count = $total;
$tsearch->description = i18n('Search_results_for') . ' ' . $keyword . ' ' . i18n('by') . ' ' . blog_title();
$tsearch->body = $tsearch->description;
$tsearch->rss = $tsearch->url . '/feed';
$tsearch->slug = strtolower($keyword);
$vroot = rtrim(config('views.root'), '/');
@ -3397,10 +3424,12 @@ get('/search/:keyword', function ($keyword) {
'page' => $page,
'posts' => $posts,
'search' => $tsearch,
'taxonomy' => $tsearch,
'bodyclass' => 'in-search search-' . strtolower($keyword),
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Search_results_for') . ' ' . $keyword,
'pagination' => has_pagination($total, $perpage, $page),
'is_search' => true
'is_search' => true,
'is_taxonomy' => true
), $layout);
});
@ -3954,6 +3983,15 @@ get('/:static', function ($static) {
$pview = 'main';
}
$tblog = new stdClass;
$tblog->title = blog_string();
$tblog->url = site_url() . blog_path();
$tblog->count = count(get_blog_posts());
$tblog->description = i18n('all_blog_posts') . ' ' . i18n('by') . ' ' . blog_title();
$tblog->body = $tblog->description;
$tblog->rss = site_url() . 'feed/rss';
$tblog->slug = blog_path();
if (empty($posts) || $page < 1) {
// a non-existing page
@ -3982,10 +4020,12 @@ get('/:static', function ($static) {
'metatags' => generate_meta('is_blog', null),
'page' => $page,
'posts' => $posts,
'taxonomy' => $tblog,
'bodyclass' => 'in-blog',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . blog_string(),
'pagination' => has_pagination($total, $perpage, $page),
'is_blog' => true
'is_blog' => true,
'is_taxonomy' => true
), $layout);
} elseif ($static === 'front') {

View file

@ -984,6 +984,8 @@ function read_category_info($category)
$desc->file = $filename;
$desc->rss = $desc->url . '/feed';
// Get the contents and convert it to HTML
$content = file_get_contents($desc->file);
@ -1022,6 +1024,7 @@ function default_category($category = null)
$desc->description = i18n('Uncategorized_comment');
$desc->file = '';
$desc->count = get_categorycount($desc->slug);
$desc->rss = $desc->url . '/feed';
} else{
$desc->title = $category;
$desc->url = site_url() . 'category/' . $category;
@ -1031,6 +1034,7 @@ function default_category($category = null)
$desc->description = i18n('All_blog_posts') . ': ' . $category;
$desc->file = '';
$desc->count = get_categorycount($category);
$desc->rss = $desc->url . '/feed';
}
return $tmp[] = $desc;
@ -1227,6 +1231,8 @@ function get_author($name)
$author->avatar = get_content_tag("image", $content, site_url() . 'system/resources/images/logo-small.png');
$author->rss = $author->url . '/feed';
$toc = explode('<!--toc-->', $author->about);
if (isset($toc['1'])) {
$author->about = insert_toc('profile-' . $author->slug, $toc['0'], $toc['1']);
@ -2910,7 +2916,7 @@ function get_menu($custom = null, $auto = null)
}
if (config('blog.enable') == 'true' ) {
if ($req == site_path() . '/' . blog_path() || stripos($req, site_path() . '/'. blog_path() .'?page') !== false) {
$menu .= '<li class="item nav-item active"><a class="nav-link" href="' . site_url() . blog_path . '">' . blog_string() . '</a></li>';
$menu .= '<li class="item nav-item active"><a class="nav-link" href="' . site_url() . blog_path() . '">' . blog_string() . '</a></li>';
} else {
$menu .= '<li class="item nav-item"><a class="nav-link" href="' . site_url() . blog_path() . '">' . blog_string() . '</a></li>';
}