Custom /blog URL

Allow to change the /blog url eg, /news
This commit is contained in:
danpros 2024-09-05 09:22:56 +07:00
commit 6bc0f8880a
5 changed files with 76 additions and 15 deletions

View file

@ -25,6 +25,8 @@ static.frontpage = "false"
; Show the /blog url as the blog homepage. Options "false" and "true" ; Show the /blog url as the blog homepage. Options "false" and "true"
blog.enable = "false" blog.enable = "false"
blog.path = "blog"
blog.string = "Blog"
; Social account ; Social account
social.twitter = "" social.twitter = ""

View file

@ -54,6 +54,18 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group row">
<label for="blog.path" class="col-sm-2 col-form-label">Blog Path</label>
<div class="col-sm-10">
<input type="text" name="-config-blog.path" class="form-control" id="blog.path" placeholder="blog" value="<?php echo config('blog.path');?>">
</div>
</div>
<div class="form-group row">
<label for="blog.string" class="col-sm-2 col-form-label">Blog String</label>
<div class="col-sm-10">
<input type="text" name="-config-blog.string" class="form-control" id="blog.string" placeholder="Blog" value="<?php echo config('blog.string');?>">
</div>
</div>
<div class="form-group row"> <div class="form-group row">
<label for="posts.perpage" class="col-sm-2 col-form-label"><?php echo i18n('Posts_in_front_page_show_at_most');?></label> <label for="posts.perpage" class="col-sm-2 col-form-label"><?php echo i18n('Posts_in_front_page_show_at_most');?></label>
<div class="col-sm-10"> <div class="col-sm-10">

View file

@ -10,6 +10,8 @@
"permalink.type", "permalink.type",
"static.frontpage", "static.frontpage",
"blog.enable", "blog.enable",
"blog.path",
"blog.string",
"social.twitter", "social.twitter",
"social.facebook", "social.facebook",
"social.instagram", "social.instagram",

View file

@ -3558,7 +3558,7 @@ get('/post/:name', function ($name) {
} }
if (config('blog.enable') === 'true') { if (config('blog.enable') === 'true') {
$blog = '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . 'blog"><span itemprop="name">Blog</span></a><meta itemprop="position" content="2" /></li> &#187; '; $blog = '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . blog_path() .'"><span itemprop="name">' . blog_string() . '</span></a><meta itemprop="position" content="2" /></li> &#187; ';
} else { } else {
$blog = ''; $blog = '';
} }
@ -3966,7 +3966,7 @@ get('/:static', function ($static) {
header("location: $login"); header("location: $login");
} }
die; die;
} elseif ($static === 'blog') { } elseif ($static === blog_path()) {
if(config('blog.enable') !== 'true') return not_found(); if(config('blog.enable') !== 'true') return not_found();
@ -4003,7 +4003,7 @@ get('/:static', function ($static) {
// a non-existing page // a non-existing page
render('no-posts', array( render('no-posts', array(
'title' => generate_title('is_blog', null), 'title' => generate_title('is_blog', null),
'description' => blog_title() . ' Blog', 'description' => blog_title() . ' ' . blog_string(),
'canonical' => site_url(), 'canonical' => site_url(),
'metatags' => generate_meta('is_blog', null), 'metatags' => generate_meta('is_blog', null),
'bodyclass' => 'no-posts', 'bodyclass' => 'no-posts',
@ -4021,13 +4021,13 @@ get('/:static', function ($static) {
render($pview, array( render($pview, array(
'title' => generate_title('is_blog', null), 'title' => generate_title('is_blog', null),
'description' => blog_title() . ' Blog', 'description' => blog_title() . ' ' . blog_string(),
'canonical' => site_url() . 'blog' . $CanonicalPageNum, 'canonical' => site_url() . blog_path() . $CanonicalPageNum,
'metatags' => generate_meta('is_blog', null), 'metatags' => generate_meta('is_blog', null),
'page' => $page, 'page' => $page,
'posts' => $posts, 'posts' => $posts,
'bodyclass' => 'in-blog', 'bodyclass' => 'in-blog',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Blog', 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . blog_string(),
'pagination' => has_pagination($total, $perpage, $page), 'pagination' => has_pagination($total, $perpage, $page),
'is_blog' => true 'is_blog' => true
), $layout); ), $layout);
@ -4737,7 +4737,7 @@ get('/:year/:month/:name', function ($year, $month, $name) {
} }
if (config('blog.enable') === 'true') { if (config('blog.enable') === 'true') {
$blog = '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . 'blog"><span itemprop="name">Blog</span></a><meta itemprop="position" content="2" /></li> &#187; '; $blog = '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . blog_path() . '"><span itemprop="name">' . blog_string() . '</span></a><meta itemprop="position" content="2" /></li> &#187; ';
} else { } else {
$blog = ''; $blog = '';
} }

View file

@ -2818,10 +2818,10 @@ function get_menu($custom = null, $auto = null)
} }
if (config('blog.enable') == 'true' ) { if (config('blog.enable') == 'true' ) {
if ($req == site_path() . '/blog' || stripos($req, site_path() . '/blog?page') !== false) { 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">' . 'Blog' . '</a></li>'; $menu .= '<li class="item nav-item active"><a class="nav-link" href="' . site_url() . blog_path() . '">' . blog_string() . '</a></li>';
} else { } else {
$menu .= '<li class="item nav-item"><a class="nav-link" href="' . site_url() . 'blog">' . 'Blog' . '</a></li>'; $menu .= '<li class="item nav-item"><a class="nav-link" href="' . site_url() . blog_path() . '">' . blog_string() . '</a></li>';
} }
} }
} }
@ -2910,10 +2910,10 @@ function get_menu($custom = null, $auto = null)
$menu .= '<li class="item nav-item first"><a class="nav-link" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></li>'; $menu .= '<li class="item nav-item first"><a class="nav-link" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></li>';
} }
if (config('blog.enable') == 'true' ) { if (config('blog.enable') == 'true' ) {
if ($req == site_path() . '/blog' || stripos($req, site_path() . '/blog?page') !== false) { 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">' . 'Blog' . '</a></li>'; $menu .= '<li class="item nav-item active"><a class="nav-link" href="' . site_url() . blog_path . '">' . blog_string() . '</a></li>';
} else { } else {
$menu .= '<li class="item nav-item"><a class="nav-link" href="' . site_url() . 'blog">' . 'Blog' . '</a></li>'; $menu .= '<li class="item nav-item"><a class="nav-link" href="' . site_url() . blog_path() . '">' . blog_string() . '</a></li>';
} }
} }
$menu .= '</ul>'; $menu .= '</ul>';
@ -3123,6 +3123,28 @@ function sitemap_page_path()
$post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($file))); $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($file)));
$tmp[] = $post; $tmp[] = $post;
$subPages = get_static_subpages($filename);
foreach ($subPages as $sIndex => $sp) {
$subpost = new stdClass;
$bs = explode('.', $sp['filename']);
if (isset($bs[1])) {
$baseSub = $bs[1];
} else {
$baseSub = $sp['filename'];
}
$urlSub = $filename . '/' . $baseSub;
$subfile = $sp['dirname'] . '/' . $sp['basename'];
$subpost->url = site_url() . $urlSub;
$subpost->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($subfile)));
$tmp[] = $subpost;
}
} }
} }
@ -3185,6 +3207,9 @@ function generate_sitemap($str)
if ($priority !== '-1') { if ($priority !== '-1') {
$map .= '<url><loc>' . site_url() . '</loc><priority>' . $priority . '</priority></url>'; $map .= '<url><loc>' . site_url() . '</loc><priority>' . $priority . '</priority></url>';
if (config('blog.enable') === 'true') {
$map .= '<url><loc>' . site_url() . blog_path() .'</loc><priority>' . $priority . '</priority></url>';
}
} }
$map .= '</urlset>'; $map .= '</urlset>';
@ -3460,13 +3485,33 @@ function generate_json($posts)
function is_index() function is_index()
{ {
$req = $_SERVER['REQUEST_URI']; $req = $_SERVER['REQUEST_URI'];
if (stripos($req, '/category/') !== false || stripos($req, '/archive/') !== false || stripos($req, '/tag/') !== false || stripos($req, '/search/') !== false || stripos($req, '/type/') !== false || stripos($req, '/blog') !== false || $req == site_path() . '/' || stripos($req, site_path() . '/?page') !== false) { if (stripos($req, '/category/') !== false || stripos($req, '/archive/') !== false || stripos($req, '/tag/') !== false || stripos($req, '/search/') !== false || stripos($req, '/type/') !== false || stripos($req, '/' . blog_path()) !== false || $req == site_path() . '/' || stripos($req, site_path() . '/?page') !== false) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
// Return blog path index
function blog_path()
{
$path = config('blog.path');
if (!is_null($path) && !empty($path)) {
return $path;
}
return 'blog';
}
// Return blog string
function blog_string()
{
$string = config('blog.string');
if (!is_null($string) && !empty($string)) {
return $string;
}
return 'Blog';
}
// Return blog title // Return blog title
function blog_title() function blog_title()
{ {
@ -3972,7 +4017,7 @@ function generate_meta($type = null, $object = null)
$tags .= '<meta property="og:site_name" content="'. blog_title() . '" />' . "\n"; $tags .= '<meta property="og:site_name" content="'. blog_title() . '" />' . "\n";
if ($type == 'is_blog') { if ($type == 'is_blog') {
$tags .= '<meta property="og:title" content="'. generate_title('is_blog', null) . '" />' . "\n"; $tags .= '<meta property="og:title" content="'. generate_title('is_blog', null) . '" />' . "\n";
$tags .= '<meta property="og:description" content="'. blog_title() .' Blog" />' . "\n"; $tags .= '<meta property="og:description" content="'. blog_title() . ' ' . blog_string() .'" />' . "\n";
} else { } else {
$tags .= '<meta property="og:title" content="'. generate_title('is_front', null) . '" />' . "\n"; $tags .= '<meta property="og:title" content="'. generate_title('is_front', null) . '" />' . "\n";
$tags .= '<meta property="og:description" content="'. safe_html(strip_tags(blog_description())) .'" />' . "\n"; $tags .= '<meta property="og:description" content="'. safe_html(strip_tags(blog_description())) .'" />' . "\n";