-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexer.php
More file actions
53 lines (48 loc) · 1.61 KB
/
Copy pathindexer.php
File metadata and controls
53 lines (48 loc) · 1.61 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
<?php
/**
* Qnd indexer for multiple branches and libraries in one document
* @author Ralf Lang <lang@b1-systems.de>
*/
$currentBranch = $argv[1] ?? '';
$currentLib = $argv[2] ?? '';
// TODO: Init json if missing
$json = json_decode(file_get_contents('index.json'));
$timestamp = time();
// If we have arguments, add to json
if ($currentBranch && $currentLib) {
$json->branches->{$currentBranch}->latestLib = $currentLib;
$json->branches->{$currentBranch}->latestUpdate = $timestamp;
$json->docdirs->{$currentBranch}->{$currentLib} = $timestamp;
}
file_put_contents('index.json', json_encode($json));
// generate index.html
$page_top = '<html><head><title>Maintaina Horde PHPDoc Index</title></head><body>';
$page_body = '<h1>Available API Documentation</h1><h2>Branches</h2><ul>';
// branches index
foreach ($json->branches as $branch => $updates) {
$page_body .= sprintf(
'<li>%s (Last Updated: %s on %s)</li>',
$branch,
$updates->latestLib,
date('c', $updates->latestUpdate)
);
}
$page_body .= '</ul>';
// generate library index
$page_body .= '<h2>Packages</h2><ul>';
foreach ($json->docdirs as $branch => $libs) {
foreach ($libs as $lib => $ts) {
$page_body .= sprintf(
'<li><a href="%s/%s/index.html">%s/%s (Last Updated: on %s)</a></li>',
$branch,
$lib,
$branch,
$lib,
date('c', $ts)
);
}
}
$page_body .= '</ul>';
$page_body .= '<hr>Index last generated: ' . date('c', $timestamp);
$page_footer = '</body></html>';
file_put_contents('index.html', $page_top . $page_body . $page_footer);