mirror of
https://github.com/danpros/htmly.git
synced 2026-04-17 11:16:00 +05:30
Allow to change the post permalink prefix
Example: /blog/post-slug
This commit is contained in:
parent
435f871162
commit
a473482da8
5 changed files with 60 additions and 57 deletions
|
|
@ -74,26 +74,51 @@ Please install and enable the GD extension to use the thumbnail feature.
|
|||
</nav>
|
||||
<br><br>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo get_csrf(); ?>">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo get_csrf(); ?>">
|
||||
<h4><?php echo i18n('Permalink');?></h4>
|
||||
<hr>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label"><?php echo i18n('Permalink');?></label>
|
||||
<label class="col-sm-2 col-form-label"><?php echo i18n('Enable_blog_URL');?></label>
|
||||
<div class="col-sm-10">
|
||||
<div class="col-sm-10">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="-config-permalink.type" id="permalink.type1" value="default" <?php if (config('permalink.type') === 'default'):?>checked<?php endif;?>>
|
||||
<label class="form-check-label" for="permalink.type1">
|
||||
<?php echo i18n('year_month_your_post_slug');?>
|
||||
<input class="form-check-input" type="radio" name="-config-blog.enable" id="blog.enable1" value="true" <?php if (config('blog.enable') === 'true'):?>checked<?php endif;?>>
|
||||
<label class="form-check-label" for="blog.enable1">
|
||||
<?php echo i18n('Enable');?>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="-config-permalink.type" id="permalink.type1" value="post" <?php if (config('permalink.type') === 'post'):?>checked<?php endif;?>>
|
||||
<label class="form-check-label" for="permalink.type2">
|
||||
<?php echo i18n('post_your_post_slug');?>
|
||||
<input class="form-check-input" type="radio" name="-config-blog.enable" id="blog.enable2" value="false" <?php if (config('blog.enable') === 'false'):?>checked<?php endif;?>>
|
||||
<label class="form-check-label" for="blog.enable2">
|
||||
<?php echo i18n('Disable');?>
|
||||
</label>
|
||||
</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">
|
||||
<label for="custom.permalink" class="col-sm-2 col-form-label"><?php echo i18n('Permalink');?> Prefix</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="-config-permalink.type" class="form-control" id="permalink.type" value="<?php echo permalink_type();?>" placeholder="default">
|
||||
<p class="title-format" style="margin-bottom:5px;"><code>default</code> <?php echo i18n('year_month_your_post_slug');?></p>
|
||||
<p class="title-format" style="margin-bottom:5px;"><code>post</code> <?php echo i18n('post_your_post_slug');?></p>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<h4><?php echo i18n('Metatags');?></h4>
|
||||
<hr>
|
||||
<div class="form-group row">
|
||||
<label for="description.char" class="col-sm-2 col-form-label"><?php echo i18n('Meta_description_character');?></label>
|
||||
<div class="col-sm-10">
|
||||
|
|
|
|||
|
|
@ -35,37 +35,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label"><?php echo i18n('Enable_blog_URL');?></label>
|
||||
<div class="col-sm-10">
|
||||
<div class="col-sm-10">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="-config-blog.enable" id="blog.enable1" value="true" <?php if (config('blog.enable') === 'true'):?>checked<?php endif;?>>
|
||||
<label class="form-check-label" for="blog.enable1">
|
||||
<?php echo i18n('Enable');?>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="-config-blog.enable" id="blog.enable2" value="false" <?php if (config('blog.enable') === 'false'):?>checked<?php endif;?>>
|
||||
<label class="form-check-label" for="blog.enable2">
|
||||
<?php echo i18n('Disable');?>
|
||||
</label>
|
||||
</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">
|
||||
<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">
|
||||
|
|
|
|||
|
|
@ -48,11 +48,11 @@ $timestamp = $time->format("Y-m-d H:i:s");
|
|||
// The post date
|
||||
$postdate = strtotime($timestamp);
|
||||
// The post URL
|
||||
if (config('permalink.type') == 'post') {
|
||||
$delete = site_url() . 'post/' . $oldmd . '/delete?destination=' . $destination;
|
||||
if (permalink_type() == 'default') {
|
||||
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
|
||||
} else {
|
||||
// The post URL
|
||||
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
|
||||
$delete = site_url() . permalink_type() . '/' . $oldmd . '/delete?destination=' . $destination;
|
||||
}
|
||||
|
||||
$tags = tag_cloud(true);
|
||||
|
|
|
|||
|
|
@ -3486,7 +3486,7 @@ get('/feed/opml', function () {
|
|||
});
|
||||
|
||||
// Show blog post without year-month
|
||||
get('/post/:name', function ($name) {
|
||||
get('/'. permalink_type() .'/:name', function ($name) {
|
||||
|
||||
if (isset($_GET['search'])) {
|
||||
$search = _h($_GET['search']);
|
||||
|
|
@ -3494,7 +3494,7 @@ get('/post/:name', function ($name) {
|
|||
header("Location: $url");
|
||||
}
|
||||
|
||||
if (config('permalink.type') != 'post') {
|
||||
if (permalink_type() == 'default') {
|
||||
$post = find_post(null, null, $name);
|
||||
if (is_null($post)) {
|
||||
not_found();
|
||||
|
|
@ -3607,7 +3607,7 @@ get('/post/:name', function ($name) {
|
|||
});
|
||||
|
||||
// Edit blog post
|
||||
get('/post/:name/edit', function ($name) {
|
||||
get('/'. permalink_type() .'/:name/edit', function ($name) {
|
||||
|
||||
if (login()) {
|
||||
|
||||
|
|
@ -3677,7 +3677,7 @@ get('/post/:name/edit', function ($name) {
|
|||
});
|
||||
|
||||
// Get edited data from blog post
|
||||
post('/post/:name/edit', function () {
|
||||
post('/'. permalink_type() .'/:name/edit', function () {
|
||||
if(!login()) {
|
||||
$login = site_url() . 'login';
|
||||
header("location: $login");
|
||||
|
|
@ -3825,7 +3825,7 @@ post('/post/:name/edit', function () {
|
|||
});
|
||||
|
||||
// Delete blog post
|
||||
get('/post/:name/delete', function ($name) {
|
||||
get('/'. permalink_type() .'/:name/delete', function ($name) {
|
||||
|
||||
if (login()) {
|
||||
|
||||
|
|
@ -3886,7 +3886,7 @@ get('/post/:name/delete', function ($name) {
|
|||
});
|
||||
|
||||
// Get deleted data from blog post
|
||||
post('/post/:name/delete', function () {
|
||||
post('/'. permalink_type() .'/:name/delete', function () {
|
||||
|
||||
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
|
||||
if ($proper && login()) {
|
||||
|
|
@ -4682,8 +4682,8 @@ get('/:year/:month/:name', function ($year, $month, $name) {
|
|||
header("Location: $url");
|
||||
}
|
||||
|
||||
if (config('permalink.type') == 'post') {
|
||||
$redir = site_url() . 'post/' . $name;
|
||||
if (permalink_type() !== 'default') {
|
||||
$redir = site_url() . permalink_type() . '/' . $name;
|
||||
header("location: $redir", TRUE, 301);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue