Browse Source

add sort support for navs

master
filesite 3 years ago
parent
commit
c37c4def86
  1. 41
      themes/pagedirectory/controller/SiteController.php
  2. 1
      www/content/Theme_PageDirectory.md

41
themes/pagedirectory/controller/SiteController.php

@ -10,6 +10,7 @@ Class SiteController extends Controller {
public function actionIndex() { public function actionIndex() {
//获取数据 //获取数据
$menus = []; $menus = [];
$menus_sorted = [];
$htmlReadme = ''; $htmlReadme = '';
$titles = []; $titles = [];
@ -23,6 +24,10 @@ Class SiteController extends Controller {
$menus = $scanner->getMenus(); $menus = $scanner->getMenus();
if (!empty($readmeFile)) { if (!empty($readmeFile)) {
if (!empty($readmeFile['sort'])) {
$menus_sorted = explode("\n", $readmeFile['sort']);
}
$titles = $scanner->getMDTitles($readmeFile['id']); $titles = $scanner->getMDTitles($readmeFile['id']);
$content = file_get_contents($readmeFile['realpath']); $content = file_get_contents($readmeFile['realpath']);
@ -31,6 +36,42 @@ Class SiteController extends Controller {
$htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); $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开源系统"; $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统";
$viewName = 'index'; $viewName = 'index';
$params = compact('dirTree', 'menus', 'htmlReadme'); $params = compact('dirTree', 'menus', 'htmlReadme');

1
www/content/Theme_PageDirectory.md

@ -6,6 +6,7 @@
## 皮肤特点 ## 皮肤特点
* 一级目录为网站菜单,链接支持二级目录和文件两种形式,优先展示目录类型链接 * 一级目录为网站菜单,链接支持二级目录和文件两种形式,优先展示目录类型链接
* 支持根目录下用Readme_sort.txt描述文件指定一级目录排序
* 每个链接支持直接跳转和Readme.md详情介绍 * 每个链接支持直接跳转和Readme.md详情介绍
* 每个链接支持logo图标、网站名、Description简介展示 * 每个链接支持logo图标、网站名、Description简介展示
* 自适应PC和手机 * 自适应PC和手机

Loading…
Cancel
Save