diff --git a/.travis.yml b/.travis.yml index 806ab7c..cf988bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,11 +26,8 @@ matrix: before_install: - nvm install node script: - - php php/crawl.php - - php php/format.php - - npm install - - export BUILD_GITHUB_PAGES=true - - npm run build + - chmod 777 ./build_github_pages.sh + - ./build_github_pages.sh deploy: provider: pages local-dir: dist diff --git a/build_github_pages.sh b/build_github_pages.sh new file mode 100644 index 0000000..1b34f7b --- /dev/null +++ b/build_github_pages.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +php php/crawl.php +php php/format.php +npm install +export BUILD_GITHUB_PAGES=true +npm run build +sed -i "s/requestType:\ 'jsonp'/jsonUrl:\ '\/down_52pojie_cn\/list.json'/g" ./dist/index.html diff --git a/build_release.sh b/build_release.sh index 7b09e60..766e13c 100644 --- a/build_release.sh +++ b/build_release.sh @@ -1,11 +1,10 @@ +#!/usr/bin/env bash npm install -echo "VUE_APP_ROUTER_MODE=history" > .env.local -echo "USE_FANCY_INDEX=true" >> .env.local -echo "FANCY_INDEX_DIR=.fancyindex" >> .env.local +export VUE_APP_ROUTER_MODE=history +export USE_FANCY_INDEX=true +export FANCY_INDEX_DIR=.fancyindex npm run build -rm .env.local rm dist/index.html -rm dist/list.json cp LICENSE dist/ cp php/scan.php dist/ cp README.md dist/ diff --git a/php/scan.php b/php/scan.php index e0b6d0d..d1b2d1c 100644 --- a/php/scan.php +++ b/php/scan.php @@ -2,26 +2,39 @@ // ==================== config ==================== +// Windows define('BASE_DIR', 'C:\Users\Ganlv\Downloads'); -define('OUTPUT_FILE', dirname(__DIR__) . '\public\list.json'); +// define('OUTPUT_FILE', dirname(__DIR__) . '\public\list.json'); + +// Use jsonp +define('OUTPUT_FILE', dirname(__DIR__) . '\public\list.js'); + +// Linux // define('BASE_DIR', '/home/ganlv/Downloads'); // define('OUTPUT_FILE', BASE_DIR . '/list.json'); +// define('OUTPUT_FILE', BASE_DIR . '/list.js'); + $exclude_files = [ - '/.fancyindex', '/list.json', + '/list.js', ]; - // ================================================== +define('JSONP_CALLBACK', '__jsonpCallbackDown52PojieCn'); date_default_timezone_set('Asia/Shanghai'); foreach ($exclude_files as &$file) { $file = BASE_DIR . $file; } $list = scan(BASE_DIR, $exclude_files); -file_put_contents(OUTPUT_FILE, json_encode($list, JSON_UNESCAPED_UNICODE)); + +$output = json_encode($list, JSON_UNESCAPED_UNICODE); +if (substr(OUTPUT_FILE, -2) === '.js') { + $output = JSONP_CALLBACK . '(' . $output . ');'; +} +file_put_contents(OUTPUT_FILE, $output); function scan($dir, $exclude_files = []) {