-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-docs.php
More file actions
211 lines (173 loc) · 7.87 KB
/
Copy pathbuild-docs.php
File metadata and controls
211 lines (173 loc) · 7.87 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Docsmith\Docsmith;
// ── Helpers ──────────────────────────────────────────────────────────────────
/**
* Parse YAML frontmatter from a markdown file.
* Returns [frontmatter array, body string without the --- block].
*/
function parseFrontmatter(string $content): array
{
$content = str_replace("\r\n", "\n", $content);
if (! str_starts_with($content, "---\n")) {
return [[], $content];
}
if (! preg_match('/\A---\n(?P<meta>.*?)\n---\n(?P<body>.*)\z/s', $content, $m)) {
return [[], $content];
}
$meta = [];
$currentKey = null;
$isArray = false;
foreach (explode("\n", $m['meta']) as $line) {
// Indented object key: key: "value"
if (preg_match('/^ {2}([\w-]+):\s*"?([^"]*)"?\s*$/', $line, $nm)) {
if (is_array($meta[$currentKey] ?? null)) {
$meta[$currentKey][$nm[1]] = trim($nm[2], '"\'');
}
$isArray = false;
}
// Indented array item: - "value"
elseif (preg_match('/^ {2}-\s*"?(.+?)"?\s*$/', $line, $am) && $currentKey && $isArray) {
$meta[$currentKey][] = trim($am[1], '"\'');
}
// Top-level quoted: key: "value"
elseif (preg_match('/^([\w-]+):\s*"(.*)"\s*$/', $line, $km)) {
$currentKey = $km[1];
$meta[$currentKey] = $km[2];
$isArray = false;
}
// Top-level unquoted: key: value
elseif (preg_match('/^([\w-]+):\s+(\S.*)\s*$/', $line, $km)) {
$currentKey = $km[1];
$meta[$currentKey] = trim($km[2], '"\'');
$isArray = false;
}
// Top-level block: key: (array/map follows)
elseif (preg_match('/^([\w-]+):\s*$/', $line, $km)) {
$currentKey = $km[1];
$meta[$currentKey] = [];
$isArray = true;
}
}
return [$meta, ltrim($m['body'], "\n")];
}
function esc(string $v): string
{
return htmlspecialchars($v, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
/**
* Build a styled HTML info card from plugin frontmatter.
*/
function pluginCard(array $meta): string
{
$author = (string) ($meta['author'] ?? '');
$price = (string) ($meta['price'] ?? 'Free');
$version = (string) ($meta['version'] ?? '');
$license = (string) ($meta['license'] ?? '');
$github = (string) ($meta['github'] ?? '');
$source = (string) ($meta['source'] ?? '');
$compat = is_array($meta['compatibility'] ?? null) ? $meta['compatibility'] : [];
$isPaid = strtolower($price) !== 'free';
$badgeClass = $isPaid ? 'pi-badge-paid' : 'pi-badge-free';
$isFirstParty = strtolower($author) === 'bifrost technology';
$partyBadge = $isFirstParty ? 'pi-badge-first-party' : 'pi-badge-community';
$partyLabel = $isFirstParty ? '1st Party Plugin' : 'Community Plugin';
$html = '<div class="plugin-info">';
// ── Meta row ─────────────────────────────────────────────────────────────
$html .= '<div class="pi-meta">';
if ($author !== '') {
$html .= '<span class="pi-item"><span class="pi-label">Author</span>'
. '<span class="pi-value">' . esc($author) . '</span></span>';
}
$html .= '<span class="pi-item"><span class="pi-label">Plugin Type</span>'
. '<span class="pi-badge ' . $partyBadge . '">' . $partyLabel . '</span></span>';
if ($price !== '') {
$html .= '<span class="pi-item"><span class="pi-label">Price</span>'
. '<span class="pi-badge ' . $badgeClass . '">' . esc($price) . '</span></span>';
}
if ($version !== '') {
$html .= '<span class="pi-item"><span class="pi-label">Version</span>'
. '<span class="pi-value">v' . esc($version) . '</span></span>';
}
if ($license !== '') {
$html .= '<span class="pi-item"><span class="pi-label">License</span>'
. '<span class="pi-value">' . esc($license) . '</span></span>';
}
$html .= '</div>';
// ── Compatibility chips ───────────────────────────────────────────────────
if ($compat !== []) {
$labels = [
'nativephp' => 'NativePHP',
'ios' => 'iOS',
'android' => 'Android',
'php' => 'PHP',
'laravel' => 'Laravel',
];
$html .= '<div class="pi-compat">';
foreach ($compat as $k => $v) {
$v = (string) $v;
if (strtolower($v) === 'not supported') {
continue;
}
$label = $labels[$k] ?? ucfirst((string) $k);
$html .= '<span class="pi-chip">'
. '<span class="pi-chip-label">' . esc($label) . '</span>'
. '<span class="pi-chip-value">' . esc($v) . '</span>'
. '</span>';
}
$html .= '</div>';
}
// ── Links ────────────────────────────────────────────────────────────────
$links = [];
if ($github !== '') {
$links[] = '<a href="' . esc($github) . '" class="pi-link" target="_blank" rel="noopener">GitHub →</a>';
}
if ($source !== '') {
$links[] = '<a href="' . esc($source) . '" class="pi-link pi-link-buy" target="_blank" rel="noopener">Buy on NativePHP →</a>';
}
if ($links !== []) {
$html .= '<div class="pi-links">' . implode('', $links) . '</div>';
}
$html .= '</div>' . "\n\n";
return $html;
}
// ── Preprocess plugin files into .build/ ─────────────────────────────────────
$buildDir = __DIR__ . '/.build';
foreach (['free', 'paid'] as $cat) {
$dir = "$buildDir/plugins/$cat";
if (! is_dir($dir)) {
mkdir($dir, 0777, true);
}
}
foreach (['free', 'paid'] as $category) {
foreach (glob(__DIR__ . "/plugins/$category/*.md") ?: [] as $srcFile) {
$raw = (string) file_get_contents($srcFile);
[$meta, $body] = parseFrontmatter($raw);
$card = $meta !== [] ? pluginCard($meta) : '';
file_put_contents(
"$buildDir/plugins/$category/" . basename($srcFile),
$card . $body
);
}
}
// Copy README to .build/ so its relative links resolve to .build/plugins/...
copy(__DIR__ . '/README.md', "$buildDir/README.md");
// ── Build ────────────────────────────────────────────────────────────────────
Docsmith::make()
->readmeIndex("$buildDir/README.md")
->output(__DIR__ . '/docs')
->title('NativePHP Plugins List')
->description('Listed all are created and maintained by independent developers, not the NativePHP team. Please review each plugin source code, license, and maintenance status before using it in production.')
->customCss(__DIR__ . '/custom.css')
->build();
// ── Cleanup ──────────────────────────────────────────────────────────────────
foreach (['free', 'paid'] as $cat) {
foreach (glob("$buildDir/plugins/$cat/*.md") ?: [] as $f) {
unlink($f);
}
@rmdir("$buildDir/plugins/$cat");
}
@unlink("$buildDir/README.md");
@rmdir("$buildDir/plugins");
@rmdir($buildDir);