|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Docsets; |
|
4
|
|
|
|
|
5
|
|
|
use Godbout\DashDocsetBuilder\Docsets\BaseDocset; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
use Illuminate\Support\Facades\Storage; |
|
8
|
|
|
use Wa72\HtmlPageDom\HtmlPageCrawler; |
|
9
|
|
|
|
|
10
|
|
|
class Alfred4 extends BaseDocset |
|
11
|
|
|
{ |
|
12
|
|
|
public const CODE = 'alfred-4'; |
|
13
|
|
|
public const NAME = 'Alfred 4'; |
|
14
|
|
|
public const URL = 'www.alfredapp.com'; |
|
15
|
|
|
public const INDEX = 'help/index.html'; |
|
16
|
|
|
public const PLAYGROUND = ''; |
|
17
|
|
|
public const ICON_16 = 'favicon-16x16.png'; |
|
18
|
|
|
public const ICON_32 = 'favicon-32x32.png'; |
|
19
|
|
|
public const EXTERNAL_DOMAINS = [ |
|
20
|
|
|
'fonts.googleapis.com', |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
public function grab(): bool |
|
25
|
|
|
{ |
|
26
|
|
|
$toIgnore = implode('|', [ |
|
|
|
|
|
|
27
|
|
|
]); |
|
28
|
|
|
|
|
29
|
|
|
$toGet = implode('|', [ |
|
30
|
|
|
'\.css', |
|
31
|
|
|
'\.ico', |
|
32
|
|
|
'\.js', |
|
33
|
|
|
'\.png', |
|
34
|
|
|
'\.svg', |
|
35
|
|
|
'/css', |
|
36
|
|
|
'/help' |
|
37
|
|
|
]); |
|
38
|
|
|
|
|
39
|
|
|
system( |
|
40
|
|
|
"echo; wget www.alfredapp.com/help \ |
|
41
|
|
|
--mirror \ |
|
42
|
|
|
--trust-server-names \ |
|
43
|
|
|
--accept-regex='{$toGet}' \ |
|
44
|
|
|
--ignore-case \ |
|
45
|
|
|
--page-requisites \ |
|
46
|
|
|
--adjust-extension \ |
|
47
|
|
|
--convert-links \ |
|
48
|
|
|
--span-hosts \ |
|
49
|
|
|
--domains={$this->externalDomains()} \ |
|
50
|
|
|
--directory-prefix=storage/{$this->downloadedDirectory()} \ |
|
51
|
|
|
-e robots=off \ |
|
52
|
|
|
--quiet \ |
|
53
|
|
|
--show-progress", |
|
54
|
|
|
$result |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
return $result === 0; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function entries(string $file): Collection |
|
61
|
|
|
{ |
|
62
|
|
|
$crawler = HtmlPageCrawler::create(Storage::get($file)); |
|
63
|
|
|
|
|
64
|
|
|
$crawler->filter('h1')->each(function (HtmlPageCrawler $node) use ($entries) { |
|
|
|
|
|
|
65
|
|
|
$entries->push([ |
|
66
|
|
|
'name' => 'What Shows up in Dash', |
|
67
|
|
|
'type' => 'One of the Million of Dash Entry Type', |
|
68
|
|
|
'path' => 'The Path to the File', |
|
69
|
|
|
]); |
|
70
|
|
|
}); |
|
71
|
|
|
|
|
72
|
|
|
return $entries; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function format(string $file): string |
|
76
|
|
|
{ |
|
77
|
|
|
$crawler = HtmlPageCrawler::create(Storage::get($file)); |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* This is equivalent to murder |
|
81
|
|
|
*/ |
|
82
|
|
|
$crawler->filter('body')->remove(); |
|
83
|
|
|
|
|
84
|
|
|
return $crawler->saveHTML(); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|