From 68d95268e782afc7d0f9ef242e12941ce5eab4d0 Mon Sep 17 00:00:00 2001 From: augushong Date: Fri, 21 Oct 2022 17:02:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E6=96=B0=E7=9A=84=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=9E=B6=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/model/Post.php | 57 +++++++++++++++++++ composer.json | 4 +- source/components/_index.scss | 1 + .../components/list/ul-music-list/_index.html | 16 ++++++ .../components/list/ul-music-list/_index.md | 2 + .../components/list/ul-music-list/_index.scss | 7 +++ .../components/list/ul-music-list/_title.txt | 1 + source/scss/layui-ul.scss | 2 + view/index/index/index.html | 38 ++++++++++++- 9 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 source/components/_index.scss create mode 100644 source/components/list/ul-music-list/_index.html create mode 100644 source/components/list/ul-music-list/_index.md create mode 100644 source/components/list/ul-music-list/_index.scss create mode 100644 source/components/list/ul-music-list/_title.txt diff --git a/app/model/Post.php b/app/model/Post.php index 070bc75..64bf654 100644 --- a/app/model/Post.php +++ b/app/model/Post.php @@ -4,8 +4,11 @@ declare(strict_types=1); namespace app\model; +use Parsedown; +use ScssPhp\ScssPhp\Compiler; use think\facade\App; use think\facade\Cache; +use think\facade\Env; use think\facade\Request; use think\facade\View; use think\Model; @@ -164,6 +167,60 @@ class Post extends Model return View::fetch($file_path); } + public function getComponentsAttr() + { + if (empty($this->getData('tpl_name'))) { + return []; + } + + $tpl_name = $this->getData('tpl_name'); + + $components_type_path = App::getRootPath() . '/source/components/' . $tpl_name; + + if (!is_dir($components_type_path)) { + return []; + } + + + $cache_key = 'cache_components_data_' . $tpl_name; + + $list_components_data = Cache::get($cache_key); + + if (!is_null($list_components_data) && !Env::get('APP_DEBUG')) { + return $list_components_data; + } + + $list_components = scandir($components_type_path); + + + + $list_components_data = []; + + + $scss_compiler = new Compiler(); + + $markdown_parser = new Parsedown(); + + foreach ($list_components as $components_name) { + if ($components_name == '.' || $components_name == '..') { + continue; + } + $components_path = $components_type_path . '/' . $components_name; + + $list_components_data[$components_name]['title'] = file_get_contents($components_path . '/_title.txt'); + $list_components_data[$components_name]['html'] = file_get_contents($components_path . '/_index.html'); + $list_components_data[$components_name]['scss'] = file_get_contents($components_path . '/_index.scss'); + $list_components_data[$components_name]['css'] = $scss_compiler->compileString($list_components_data[$components_name]['scss'])->getCss(); + $list_components_data[$components_name]['markdown'] = file_get_contents($components_path . '/_index.md'); + $list_components_data[$components_name]['desc'] = $markdown_parser->text($list_components_data[$components_name]['markdown']); + } + + Cache::set($cache_key, $list_components_data, 60); + + return $list_components_data; + } + + public static function quickSelect($clear = false) { $cacke_key = 'post_list'; diff --git a/composer.json b/composer.json index 1d4fadc..c86af82 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,9 @@ "topthink/think-migration": "^3.0", "topthink/think-helper": "^3.1", "topthink/think-captcha": "^3.0", - "topthink/think-multi-app": "^1.0" + "topthink/think-multi-app": "^1.0", + "scssphp/scssphp": "^1.11", + "erusev/parsedown": "^1.7" }, "require-dev": { "symfony/var-dumper": "^4.2" diff --git a/source/components/_index.scss b/source/components/_index.scss new file mode 100644 index 0000000..98f28a7 --- /dev/null +++ b/source/components/_index.scss @@ -0,0 +1 @@ +@import './list/ul-music-list/index' \ No newline at end of file diff --git a/source/components/list/ul-music-list/_index.html b/source/components/list/ul-music-list/_index.html new file mode 100644 index 0000000..5dc2439 --- /dev/null +++ b/source/components/list/ul-music-list/_index.html @@ -0,0 +1,16 @@ +
+
+
+ +
+
+ 11 +
+
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/source/components/list/ul-music-list/_index.md b/source/components/list/ul-music-list/_index.md new file mode 100644 index 0000000..cafa7de --- /dev/null +++ b/source/components/list/ul-music-list/_index.md @@ -0,0 +1,2 @@ + +适合音乐列表的样式 \ No newline at end of file diff --git a/source/components/list/ul-music-list/_index.scss b/source/components/list/ul-music-list/_index.scss new file mode 100644 index 0000000..07efc8d --- /dev/null +++ b/source/components/list/ul-music-list/_index.scss @@ -0,0 +1,7 @@ +.ul-music-list { + padding-left: 15px; + + .item { + padding: 6px + } +} \ No newline at end of file diff --git a/source/components/list/ul-music-list/_title.txt b/source/components/list/ul-music-list/_title.txt new file mode 100644 index 0000000..96aa4a8 --- /dev/null +++ b/source/components/list/ul-music-list/_title.txt @@ -0,0 +1 @@ +音乐列表 \ No newline at end of file diff --git a/source/scss/layui-ul.scss b/source/scss/layui-ul.scss index 3fb0cd9..43f65e1 100644 --- a/source/scss/layui-ul.scss +++ b/source/scss/layui-ul.scss @@ -9,6 +9,8 @@ @import './footer/index'; @import './desciptions/index'; @import './header/_index'; +@import '../components/index'; + /* 链接导航开始 */ .ul-link-select { diff --git a/view/index/index/index.html b/view/index/index/index.html index ff1deee..582264f 100644 --- a/view/index/index/index.html +++ b/view/index/index/index.html @@ -66,6 +66,39 @@
{$model_post->demo_page|raw} + + {volist name='model_post->components' id='vo'} +
+ {$vo.title} +
+
+ {$vo.desc|raw} +
+
{$vo.html|raw}
+
+
+
    +
  • HTML
  • +
  • SCSS
  • +
  • CSS
  • +
+
+
+
{$vo.html}
+
+
+ {$vo.scss|raw} +
+
+ {$vo.css|raw} + +
+
+
+
+
+
+ {/volist}
@@ -73,7 +106,7 @@
-
+
开源信息
@@ -125,6 +158,9 @@