Allow to change the post permalink prefix

Example: /blog/post-slug
This commit is contained in:
danpros 2024-09-06 14:19:25 +07:00
commit a473482da8
5 changed files with 60 additions and 57 deletions

View file

@ -399,7 +399,6 @@ function get_posts($posts, $page = 1, $perpage = 0)
$auto = config('toc.automatic');
$counter = config('views.counter');
$caption = config('fig.captions');
$permalink = config('permalink.type');
if ($counter == 'true') {
$viewsFile = "content/data/views.json";
@ -469,10 +468,10 @@ function get_posts($posts, $page = 1, $perpage = 0)
// The archive per day
$post->archive = site_url() . 'archive/' . date('Y-m', $post->date);
if ($permalink == 'post') {
$post->url = site_url() . 'post/' . str_replace('.md', '', $arr[2]);
} else {
if (permalink_type() == 'default') {
$post->url = site_url() . date('Y/m', $post->date) . '/' . str_replace('.md', '', $arr[2]);
} else {
$post->url = site_url() . permalink_type() . '/' . str_replace('.md', '', $arr[2]);
}
$post->slug = str_replace('.md', '', $arr[2]);
@ -3085,10 +3084,10 @@ function sitemap_post_path($posts, $page = 1, $perpage = 0)
$post->archiveyear = site_url() . 'archive/' . date('Y', $post->date);
// The post URL
if (config('permalink.type') == 'post') {
$post->url = site_url() . 'post/' . str_replace('.md', '', $arr[2]);
} else {
if (permalink_type() == 'default') {
$post->url = site_url() . date('Y/m', $post->date) . '/' . str_replace('.md', '', $arr[2]);
} else {
$post->url = site_url() . permalink_type() . '/' . str_replace('.md', '', $arr[2]);
}
$tmp[] = $post;
@ -3492,6 +3491,16 @@ function is_index()
}
}
// Return post permalink type
function permalink_type()
{
$permalink = config('permalink.type');
if (!is_null($permalink) && !empty($permalink)) {
return strtolower($permalink);
}
return 'default';
}
// Return blog path index
function blog_path()
{