diff --git a/lib/DirScanner.php b/lib/DirScanner.php index 6fb4a8b..52d3a63 100644 --- a/lib/DirScanner.php +++ b/lib/DirScanner.php @@ -165,7 +165,7 @@ Class DirScanner { 'ctime' => $fstat['ctime'], ], 'realpath' => $realpath, - 'path' => $this->getFilePath( $id, $this->getDirectoryName($pathinfo['dirname'], $dirLevel), $pathinfo['filename'], $extension ), + 'path' => $this->getFilePath( $id, $this->getDirectoryName($pathinfo['dirname'], $dirLevel), $pathinfo['filename'], $extension, $fstat['mtime'] ), ]; if ($extension == 'url') { @@ -264,7 +264,8 @@ Class DirScanner { } //根据文件生成相对路径 - protected function getFilePath($id, $directory, $filename, $extension) { + //@ver: 增加静态文件的更新时间戳作为文件版本参数 + protected function getFilePath($id, $directory, $filename, $extension, $mtime) { if (empty($directory)) { $directory = '/'; } @@ -301,6 +302,11 @@ Class DirScanner { $path = $this->getSecureLink($path); } + //增加版本号ver参数 + if (!in_array($extension, ['md', 'url', 'txt'])) { + $path .= strpos($path, '?') !== false ? "&ver={$mtime}" : "?ver={$mtime}"; + } + return $path; } diff --git a/test/DirScannerTest.php b/test/DirScannerTest.php index 58b26c3..3d54568 100644 --- a/test/DirScannerTest.php +++ b/test/DirScannerTest.php @@ -72,7 +72,10 @@ echo "\n"; $readme_id = '34528ca632426cd2cd570dd32c9dcf4c'; $readme_titles = $scanner->getMDTitles($readme_id); +echo "Titles of MD file {$readme_id}:\n"; print_r($readme_titles); +echo "\n"; +echo "\n"; //$menus = $scanner->getMenus(); //echo "Directories:\n"; @@ -81,10 +84,10 @@ print_r($readme_titles); //echo "\n"; -//echo "Directories and files' tree:\n"; -//print_r($dirTree); -//echo "\n"; -//echo "\n"; +echo "Directories and files' tree:\n"; +print_r($dirTree); +echo "\n"; +echo "\n"; //$scanResults = $scanner->getScanResults();