Browse Source

improve snapshot's path

master
filesite 3 years ago
parent
commit
7402ad14c9
  1. 27
      lib/DirScanner.php
  2. 2
      test/DirScannerTest.php
  3. 4
      test/init_test_files.sh

27
lib/DirScanner.php

@ -75,11 +75,26 @@ Class DirScanner { @@ -75,11 +75,26 @@ Class DirScanner {
//解析描述文件内容
private function parseDescriptionFiles($realpath) {
//snapshot相对路径完善,支持secure_link
private function parseDescriptionFiles($realpath, $dirLevel) {
$pathinfo = pathinfo($realpath);
$field = preg_replace('/^.+_/', '', $pathinfo['filename']);
$content = file_get_contents($realpath);
$data = [];
if (in_array($field, ['title', 'snapshot'])) {
$content = preg_replace('/\s/', '', $content);
if ($field == 'snapshot') {
$img_realpath = str_replace("{$pathinfo['filename']}.{$pathinfo['extension']}", $content, $realpath);
echo "img_realpath: ".$img_realpath."\n";
$id = $this->getId($img_realpath);
$fp = fopen($img_realpath, 'r');
$fstat = fstat($fp);
fclose($fp);
$img_pathinfo = pathinfo($img_realpath);
$extension = strtolower($img_pathinfo['extension']);
$content = $this->getFilePath( $id, $this->getDirectoryName($img_pathinfo['dirname'], $dirLevel), $img_pathinfo['filename'], $extension, $fstat['mtime'] );
}
}
$data[$field] = $content;
return $data;
@ -206,9 +221,9 @@ Class DirScanner { @@ -206,9 +221,9 @@ Class DirScanner {
}
//合并描述文件内容到md文件或者目录数据
private function mergeDescriptionData($realpath) {
private function mergeDescriptionData($realpath, $dirLevel) {
$data = [];
$ext = $this->parseDescriptionFiles($realpath);
$ext = $this->parseDescriptionFiles($realpath, $dirLevel);
//try to find the md file
$targetFile = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.md', $realpath);
@ -481,7 +496,7 @@ Class DirScanner { @@ -481,7 +496,7 @@ Class DirScanner {
$branch = $this->getFileData($realpath, $this->scanningDirLevel);
}else {
//把描述文件内容合并到被描述的目录或md文件数据中
$branch = $this->mergeDescriptionData($realpath);
$branch = $this->mergeDescriptionData($realpath, $this->scanningDirLevel);
}
}
}
@ -521,10 +536,10 @@ Class DirScanner { @@ -521,10 +536,10 @@ Class DirScanner {
'path' => $item['path'],
];
if (!empty($item['snapshot'])) {
$dir['snapshot'] = preg_replace('/\s/', '', $item['snapshot']);
$dir['snapshot'] = $item['snapshot'];
}
if (!empty($item['title'])) {
$dir['title'] = preg_replace('/\s/', '', $item['title']);
$dir['title'] = $item['title'];
}
if (!empty($item['description'])) {
$dir['description'] = $item['description'];

2
test/DirScannerTest.php

@ -71,7 +71,7 @@ $dirTree = $scanner->scan(__DIR__ . '/content/', 4); @@ -71,7 +71,7 @@ $dirTree = $scanner->scan(__DIR__ . '/content/', 4);
echo "Time cost: {$scanner->scanTimeCost} ms\n";
echo "\n";
$readme_id = '34528ca632426cd2cd570dd32c9dcf4c';
$readme_id = '6a8a2df95732bd046e20269707a70171';
$readme_titles = $scanner->getMDTitles($readme_id);
echo "Titles of MD file {$readme_id}:\n";
print_r($readme_titles);

4
test/init_test_files.sh

@ -54,7 +54,7 @@ tee -a "小说/金庸小说/最爱金庸.url" <<EOF @@ -54,7 +54,7 @@ tee -a "小说/金庸小说/最爱金庸.url" <<EOF
[InternetShortcut]
URL=https://www.google.com
EOF
echo '/favs/小说/金庸小说/最爱金庸网站图标.ico' > "小说/金庸小说/snapshot.txt"
echo '最爱金庸网站图标.ico' > "小说/金庸小说/snapshot.txt"
touch "小说/古龙小说/最爱古龙网站图标.ico"
touch "小说/古龙小说/最爱古龙.url"
@ -74,7 +74,7 @@ tee -a "图片/图片搜索/description.txt" <<EOF @@ -74,7 +74,7 @@ tee -a "图片/图片搜索/description.txt" <<EOF
什么图片都能搜,
输入关键词,然后点“搜索”
EOF
echo '/favs/图片/图片搜索/谷歌图片搜索图标.ico' > "图片/图片搜索/snapshot.txt"
echo '谷歌图片搜索图标.ico' > "图片/图片搜索/snapshot.txt"
touch "图片/必应图片搜索/bing图标.ico"
touch "图片/必应图片搜索/bing.url"

Loading…
Cancel
Save