Skip to content

Commit 7a7d0a8

Browse files
committed
feat: blog category template view page
1 parent cc43c95 commit 7a7d0a8

File tree

9 files changed

+238
-2
lines changed

9 files changed

+238
-2
lines changed

config/module.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@
3131
'Banner' => [
3232
'enable' => true,
3333
],
34+
// 'BlogThemePaper' => [
35+
// 'enable' => true,
36+
// ],
3437
],
3538
];

module/Blog/Admin/Controller/BlogCategoryController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use ModStart\Form\Form;
1111
use ModStart\Grid\GridFilter;
1212
use ModStart\Support\Concern\HasFields;
13+
use Module\Blog\Type\BlogCategoryTemplateView;
1314
use Module\Blog\Util\BlogCategoryUtil;
1415

1516
class BlogCategoryController extends Controller
@@ -26,6 +27,7 @@ protected function crud(AdminCRUDBuilder $builder)
2627
$builder->text('title', '名称');
2728
$builder->text('keywords', '关键词');
2829
$builder->textarea('description', '描述');
30+
$builder->select('templateView', '列表模板')->optionType(BlogCategoryTemplateView::class);
2931
$builder->display('blogCount', '博客数')->listable(true)->addable(false)->editable(false);
3032
$builder->display('created_at', L('Created At'))->listable(false);
3133
$builder->display('updated_at', L('Updated At'))->listable(false);

module/Blog/Docs/release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 2.3.0
22

33
- 新增:博客标签独立页面
4+
- 新增:可根据博客分类选择列表模板
45

56
---
67

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
6+
class ModifyBlogDynamicTemplate extends Migration
7+
{
8+
9+
public function up()
10+
{
11+
Schema::table('blog_category', function (Blueprint $table) {
12+
$table->string('templateView', 50)->nullable()->comment('');
13+
});
14+
Schema::table('blog', function (Blueprint $table) {
15+
$table->string('templateView', 50)->nullable()->comment('');
16+
});
17+
}
18+
19+
20+
public function down()
21+
{
22+
23+
}
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
4+
namespace Module\Blog\Type;
5+
6+
7+
use Illuminate\Support\Str;
8+
use ModStart\Core\Type\BaseType;
9+
use ModStart\Core\Util\FileUtil;
10+
use ModStart\Core\View\ResponsiveView;
11+
12+
class BlogCategoryTemplateView implements BaseType
13+
{
14+
public static function getList()
15+
{
16+
$map = [
17+
'' => '默认',
18+
];
19+
$templateRoot = ResponsiveView::templateRootRealpath('Blog');
20+
$files = FileUtil::listFiles($templateRoot . 'pc/blog', '*.blade.php');
21+
$files = array_filter($files, function ($file) {
22+
return Str::startsWith($file['filename'], 'list');
23+
});
24+
foreach ($files as $file) {
25+
$name = $file['filename'];
26+
$name = substr($name, 0, -strlen('.blade.php'));
27+
$map[$name] = $name;
28+
}
29+
return $map;
30+
}
31+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@if(empty($records))
2+
<div class="ub-empty">
3+
<div class="icon">
4+
<div class="iconfont icon-empty-box"></div>
5+
</div>
6+
<div class="text">
7+
暂无数据
8+
</div>
9+
</div>
10+
@endif
11+
<div class="row">
12+
@foreach($records as $record)
13+
<div class="col-md-4">
14+
<div class="ub-text-blog"
15+
data-scroll-animate="animated fadeInUp"
16+
>
17+
<a class="lg:tw-w-40 tw-w-20 tw-ml-4 tw-flex-shrink-0" href="{{modstart_web_url('blog/'.$record['id'])}}">
18+
<div class="ub-cover-3-2 tw-rounded" style="background-image:url({{empty($record['_cover'])?'':$record['_cover']}})"></div>
19+
</a>
20+
<div class="ub-text-truncate tw-text-center">
21+
<a href="{{modstart_web_url('blog/'.$record['id'])}}" class="pb-keywords-highlight tw-text-gray-800">
22+
{{$record['title']}}
23+
</a>
24+
</div>
25+
</div>
26+
</div>
27+
@endforeach
28+
</div>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
@extends($_viewFrame)
2+
3+
@section('pageTitle'){{$pageTitle?$pageTitle.' | '.modstart_config('siteName'):modstart_config('siteName')}}@endsection
4+
@section('pageKeywords'){{$pageKeywords}}@endsection
5+
@section('pageDescription'){{$pageDescription}}@endsection
6+
7+
{!! \ModStart\ModStart::js('asset/common/scrollAnimate.js') !!}
8+
9+
{!! \ModStart\ModStart::js('asset/vendor/jqueryMark.js') !!}
10+
{!! \ModStart\ModStart::style('[data-markjs]{color:red !important;background:transparent;}') !!}
11+
{!! \ModStart\ModStart::script("$('.pb-keywords-highlight').mark(".json_encode($keywords).",{});") !!}
12+
13+
@section('bodyContent')
14+
15+
<div class="ub-container">
16+
<div class="row">
17+
<div class="col-md-8">
18+
@if($keywords)
19+
<div class="tw-p-6 tw-rounded tw-bg-white margin-top tw-text-lg">
20+
<i class="iconfont icon-search"></i>
21+
搜索
22+
<span class="ub-text-primary ub-text-bold">{{$keywords}}</span>
23+
共找到
24+
<span class="ub-text-primary ub-text-bold">{{$total}}</span>
25+
条记录
26+
<a href="?{{\ModStart\Core\Input\Request::mergeQueries(['keywords'=>null])}}" class="ub-text-muted">
27+
<i class="iconfont icon-close"></i>
28+
</a>
29+
</div>
30+
@endif
31+
@if($category)
32+
<div class="tw-p-6 tw-rounded tw-bg-white margin-top tw-text-lg">
33+
<i class="iconfont icon-category"></i>
34+
<a href="{{modstart_web_url('blogs')}}" class="tw-text-lg tw-text-gray-400">
35+
全部
36+
</a>
37+
<i class="iconfont icon-angle-right ub-text-muted"></i>
38+
<a href="{{modstart_web_url('blogs',['categoryId'=>$category])}}" class="tw-text-lg tw-text-gray-800">
39+
{{$category['title']}}
40+
</a>
41+
</div>
42+
@endif
43+
44+
<div class="tw-p-6 tw-rounded tw-bg-white margin-top">
45+
46+
@include('module::Blog.View.pc.blog.inc.blogItemsCover')
47+
48+
<div>
49+
<div class="ub-page">
50+
{!! $pageHtml !!}
51+
</div>
52+
</div>
53+
</div>
54+
</div>
55+
<div class="col-md-4 margin-top">
56+
57+
@include('module::Blog.View.pc.blog.inc.info')
58+
59+
@include('module::Blog.View.pc.blog.inc.categories')
60+
61+
@include('module::Blog.View.pc.blog.inc.tags')
62+
63+
@include('module::Blog.View.pc.blog.inc.partners')
64+
65+
</div>
66+
</div>
67+
</div>
68+
69+
@endsection

module/Blog/Web/Controller/BlogController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@ public function index(\Module\Blog\Api\Controller\BlogController $api)
1616
{
1717
$viewData = Response::tryGetData($api->paginate());
1818
$viewData['pageHtml'] = PageHtmlUtil::render($viewData['total'], $viewData['pageSize'], $viewData['page'], '?' . Request::mergeQueries(['page' => ['{page}']]));
19-
return $this->view('blog.list', $viewData);
19+
$templateView = 'blog.list';
20+
if (!empty($viewData['category']['templateView'])) {
21+
$templateView = 'blog.' . $viewData['category']['templateView'];
22+
}
23+
return $this->view($templateView, $viewData);
2024
}
2125

2226
public function show(\Module\Blog\Api\Controller\BlogController $api, $id)
2327
{
2428
InputPackage::mergeToInput('id', $id);
2529
$viewData = Response::tryGetData($api->get());
2630
$viewData['commentPageHtml'] = PageHtmlUtil::render($viewData['commentTotal'], $viewData['commentPageSize'], $viewData['commentPage'], '?commentPage={page}');
27-
return $this->view('blog.show', $viewData);
31+
$templateView = 'blog.show';
32+
if (!empty($viewData['record']['templateView'])) {
33+
$templateView = 'blog.' . $viewData['record']['templateView'];
34+
}
35+
return $this->view($templateView, $viewData);
2836
}
2937

3038
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
4+
namespace ModStart\Core\View;
5+
6+
7+
use Illuminate\Support\Facades\Input;
8+
use Illuminate\Support\Facades\Session;
9+
use Illuminate\Support\Str;
10+
use Module\Vendor\Provider\SiteTemplate\SiteTemplateProvider;
11+
12+
class ResponsiveView
13+
{
14+
public static function templateRoot()
15+
{
16+
static $provider = null;
17+
static $templateRoot = null;
18+
if (null !== $templateRoot) {
19+
return $templateRoot;
20+
}
21+
static $templateName = 'default';
22+
$msSiteTemplate = Input::get('msSiteTemplate', null);
23+
if (!empty($msSiteTemplate)) {
24+
$provider = SiteTemplateProvider::get($msSiteTemplate);
25+
if (!empty($provider)) {
26+
Session::put('msSiteTemplate', $msSiteTemplate);
27+
}
28+
}
29+
if (empty($provider)) {
30+
$msSiteTemplate = Session::get('msSiteTemplate', null);
31+
if (!empty($msSiteTemplate)) {
32+
$provider = SiteTemplateProvider::get($msSiteTemplate);
33+
if (empty($provider)) {
34+
Session::forget('msSiteTemplate');
35+
}
36+
}
37+
}
38+
if (empty($provider)) {
39+
$templateName = modstart_config()->getWithEnv('siteTemplate', 'default');
40+
$provider = SiteTemplateProvider::get($templateName);
41+
}
42+
if ($provider && $provider->root()) {
43+
$templateRoot = $provider->root();
44+
} else {
45+
$templateRoot = "theme.$templateName";
46+
}
47+
return $templateRoot;
48+
}
49+
50+
public static function templateRootRealpath($module)
51+
{
52+
$root = self::templateRoot();
53+
if (Str::startsWith($root, 'module::')) {
54+
$root = str_replace(['::', '.'], '/', $root);
55+
$root = base_path($root);
56+
} else if (Str::startsWith($root, 'theme.')) {
57+
$root = 'resources/views/' . str_replace(['.'], '/', $root);
58+
$root = base_path($root);
59+
if (!file_exists($root)) {
60+
$root = base_path('module/' . $module . '/View');
61+
}
62+
if (!file_exists($root)) {
63+
$root = base_path('resources/views/theme/default');
64+
}
65+
} else {
66+
$root = base_path($root);
67+
}
68+
return rtrim($root, '\\/') . '/';
69+
}
70+
}

0 commit comments

Comments
 (0)