From c37c4def868a272f80b46d70b1ee422469d16cfb Mon Sep 17 00:00:00 2001 From: filesite Date: Thu, 19 May 2022 08:44:58 +0800 Subject: [PATCH] add sort support for navs --- .../controller/SiteController.php | 41 +++++++++++++++++++ www/content/Theme_PageDirectory.md | 1 + 2 files changed, 42 insertions(+) diff --git a/themes/pagedirectory/controller/SiteController.php b/themes/pagedirectory/controller/SiteController.php index 5694c7c..40cd6a2 100644 --- a/themes/pagedirectory/controller/SiteController.php +++ b/themes/pagedirectory/controller/SiteController.php @@ -10,6 +10,7 @@ Class SiteController extends Controller { public function actionIndex() { //获取数据 $menus = []; + $menus_sorted = []; $htmlReadme = ''; $titles = []; @@ -23,6 +24,10 @@ Class SiteController extends Controller { $menus = $scanner->getMenus(); if (!empty($readmeFile)) { + if (!empty($readmeFile['sort'])) { + $menus_sorted = explode("\n", $readmeFile['sort']); + } + $titles = $scanner->getMDTitles($readmeFile['id']); $content = file_get_contents($readmeFile['realpath']); @@ -31,6 +36,42 @@ Class SiteController extends Controller { $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); } + //排序 + if (!empty($menus_sorted) && !empty($menus)) { + $menu_dirs = array_column($menus, 'directory'); + $names = array_replace(array_flip($menus_sorted), array_flip($menu_dirs)); + if (!empty($names)) { + $menus_sorted = array_keys($names); + + $arr = []; + foreach($menus_sorted as $name) { + $index = array_search($name, $menu_dirs); + array_push($arr, $menus[$index]); + } + $menus = $arr; + } + + //dirTree排序 + $sorted_dirs = array_column($menus, 'directory'); + $tree_dirs = array_column($dirTree, 'directory'); + $names = array_replace(array_flip($sorted_dirs), array_flip($tree_dirs)); + if (!empty($names)) { + $sorted_dirs = array_keys($names); + + $arr = []; + foreach($sorted_dirs as $name) { + foreach($dirTree as $index => $item) { + if ($item['directory'] == $name) { + array_push($arr, $item); + break; + } + } + } + $dirTree = $arr; + } + } + + $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统"; $viewName = 'index'; $params = compact('dirTree', 'menus', 'htmlReadme'); diff --git a/www/content/Theme_PageDirectory.md b/www/content/Theme_PageDirectory.md index 3f45044..10f9750 100644 --- a/www/content/Theme_PageDirectory.md +++ b/www/content/Theme_PageDirectory.md @@ -6,6 +6,7 @@ ## 皮肤特点 * 一级目录为网站菜单,链接支持二级目录和文件两种形式,优先展示目录类型链接 +* 支持根目录下用Readme_sort.txt描述文件指定一级目录排序 * 每个链接支持直接跳转和Readme.md详情介绍 * 每个链接支持logo图标、网站名、Description简介展示 * 自适应PC和手机