Skip to content

Commit cc43c95

Browse files
committed
feat: blog tags page
1 parent bc54ab1 commit cc43c95

File tree

10 files changed

+112
-4
lines changed

10 files changed

+112
-4
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
4+
namespace Module\Blog\Api\Controller;
5+
6+
7+
use Illuminate\Routing\Controller;
8+
use ModStart\Core\Input\Response;
9+
use Module\Blog\Util\BlogTagUtil;
10+
11+
12+
class TagsController extends Controller
13+
{
14+
15+
public function all()
16+
{
17+
$tags = BlogTagUtil::records();
18+
return Response::generateSuccessData([
19+
'tags' => $tags,
20+
]);
21+
}
22+
}

module/Blog/Api/routes.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010

1111
$router->match(['post'], 'blog/paginate', 'BlogController@paginate');
1212
$router->match(['post'], 'blog/get', 'BlogController@get');
13-
1413
$router->match(['post'], 'blog/comment/add', 'CommentController@add');
15-
1614
$router->match(['post'], 'blog/message/paginate', 'MessageController@paginate');
1715
$router->match(['post'], 'blog/message/add', 'MessageController@add');
16+
$router->match(['post'], 'blog/tags/all', 'TagsController@all');
1817

1918
});

module/Blog/Core/MBlog.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,10 @@ public static function tags()
7474
{
7575
return BlogTagUtil::all();
7676
}
77+
78+
79+
public static function tagRecords()
80+
{
81+
return BlogTagUtil::records();
82+
}
7783
}

module/Blog/Core/ModuleServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function boot(Dispatcher $events)
3131
['博客首页', modstart_web_url('blog')],
3232
['博客列表', modstart_web_url('blogs')],
3333
['博客留言', modstart_web_url('blog/message')],
34+
['博客标签', modstart_web_url('blog/tags')],
3435
['关于博主', modstart_web_url('blog/about')],
3536
], $categories));
3637
});

module/Blog/Docs/release.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.3.0
2+
3+
- 新增:博客标签独立页面
4+
5+
---
6+
17
## 2.2.0 博客操作类和文档,新增关键词和描述
28

39
- 新增:博客分类增加关键词和描述字段

module/Blog/Util/BlogTagUtil.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Illuminate\Support\Facades\Cache;
88
use ModStart\Core\Dao\ModelUtil;
9+
use ModStart\Core\Util\ArrayUtil;
910
use ModStart\Core\Util\TagUtil;
1011

1112
class BlogTagUtil
@@ -33,4 +34,14 @@ public static function all()
3334
return $tags;
3435
});
3536
}
37+
38+
public static function records()
39+
{
40+
$all = self::all();
41+
$records = array_build($all, function ($k, $v) {
42+
return [$k, ['name' => $k, 'count' => $v]];
43+
});
44+
$records = ArrayUtil::sortByKey($records, 'count', 'desc');
45+
return $records;
46+
}
3647
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@extends($_viewFrame)
2+
3+
@section('pageTitleMain')博客标签@endsection
4+
@section('pageKeywords')博客标签@endsection
5+
@section('pageDescription')博客标签@endsection
6+
7+
@section('bodyContent')
8+
9+
<div class="ub-container">
10+
<div class="row">
11+
<div class="col-md-8 margin-top">
12+
13+
<div class="tw-p-6 tw-bg-white tw-rounded">
14+
<div class="tw-text-lg">
15+
<i class="iconfont icon-tag"></i>
16+
博客标签
17+
</div>
18+
<div class="tw-mt-4">
19+
@foreach($tags as $tag)
20+
<a href="{{modstart_web_url('blogs',['keywords'=>$tag['name']])}}"
21+
class="tw-rounded-3xl tw-text-gray-600 tw-inline-block tw-bg-gray-100 tw-leading-8 tw-mb-3 tw-px-2 tw-mr-2 @if(!empty($keywords)&&$keywords==$t) ub-bg-primary ub-text-white @endif">
22+
{{$tag['name']}}
23+
<span class="tw-rounded-3xl tw-bg-gray-300 tw-text-white tw-px-2">
24+
{{$tag['count']?$tag['count']:0}}
25+
</span>
26+
</a>
27+
@endforeach
28+
</div>
29+
</div>
30+
31+
</div>
32+
<div class="col-md-4 margin-top">
33+
34+
@include('module::Blog.View.pc.blog.inc.info')
35+
36+
@include('module::Blog.View.pc.blog.inc.contact')
37+
38+
@include('module::Blog.View.pc.blog.inc.categories')
39+
40+
@include('module::Blog.View.pc.blog.inc.blogLatest')
41+
42+
</div>
43+
</div>
44+
</div>
45+
46+
@endsection
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
4+
namespace Module\Blog\Web\Controller;
5+
6+
7+
use ModStart\Core\Input\Response;
8+
use ModStart\Module\ModuleBaseController;
9+
10+
class TagsController extends ModuleBaseController
11+
{
12+
public function index(\Module\Blog\Api\Controller\TagsController $api)
13+
{
14+
$viewData = Response::tryGetData($api->all());
15+
return $this->view('blog.tags', $viewData);
16+
}
17+
}

module/Blog/Web/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
$router->match(['get'], 'blog', 'IndexController@index');
1212

1313
$router->match(['get'], 'blog/about', 'AboutController@index');
14-
1514
$router->match(['get'], 'blog/message', 'MessageController@index');
15+
$router->match(['get'], 'blog/tags', 'TagsController@index');
1616

1717
$router->match(['get'], 'blogs', 'BlogController@index');
1818
$router->match(['get'], 'blog/{id}', 'BlogController@show');

module/Blog/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"laravel5",
1515
"laravel9"
1616
],
17-
"version": "2.2.0",
17+
"version": "2.3.0",
1818
"author": "ModStart",
1919
"description": "提供一个基础的博客系统",
2020
"suggest": [

0 commit comments

Comments
 (0)