forked from yangyao/ssr_subscribe_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.php
30 lines (24 loc) · 1.08 KB
/
build.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
require 'vendor/autoload.php';
use Symfony\Component\Dotenv\Dotenv;
$dotEnv = new Dotenv();
$dotEnv->load(__DIR__.'/.env');
$domain = getenv('DOMAIN');
$accessToken = getenv('ACCESS_TOKEN');
if(($accessToken && ($accessToken != '$ACCESS_TOKEN')) && ($domain && ($domain != '$DOMAIN'))){
// add subscribe form data to node.txt
$netlify = new \Yangyao\SSR\Netlify($accessToken,$domain);
$site = $netlify->getSite();
$subscribes = $netlify->getSubmissions( $site['id'],'subscribe');
collect($subscribes)->each(function($subscribe){
$link = $subscribe['data']['link'];
$plain = \Yangyao\SSR\SSR::getFromSubLink($link);
file_put_contents('node.txt',PHP_EOL."## {$link} ".PHP_EOL,FILE_APPEND);
file_put_contents('node.txt',$plain.PHP_EOL,FILE_APPEND);
});
}
$plain = file_get_contents('node.txt');
$ssr = collect(explode(PHP_EOL,$plain))->filter(function($line){
return \Illuminate\Support\Str::contains($line,"ssr://");
});
return file_put_contents('dist/index.html',base64_encode(implode(PHP_EOL,$ssr->all())));