Skip to content

Commit 12840c5

Browse files
committed
feat: add 'Last Commit' date column for each crate in index.html
1 parent 3557466 commit 12840c5

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

contrib/autogen/gen_diagrams_remote.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
($text = @file_get_contents($cratefile)) || die("failed reading file $cratefile\n");
1212
($json = @json_decode($text, true)) || die("failed parsing json in $cratefile\n");
1313

14-
chdir($workdir) || die("failed chdir");
15-
1614
$cratepaths = [];
15+
$crate_dates = [];
1716
foreach($json as $crate => $meta) {
17+
chdir($workdir) || die("failed chdir");
18+
$output = null;
1819
$url = @$meta['git'];
1920
$cmd = sprintf('git clone --depth=1 %s %s', escapeshellarg($url), escapeshellarg($crate));
2021
shell($cmd) && die("git clone failed\n");
@@ -23,6 +24,13 @@
2324
if(strstr($url, "github.com")) {
2425
$src_url_mask = sprintf("%s/blob/master/{file}", $url);
2526
}
27+
28+
// Get date of last commit
29+
chdir("$cratedir") || die("failed chdir");
30+
exec("git log -1 --format=\%cd", $output, $rc); if($rc) { die("git log failed"); }
31+
$last_commit_date = date('Y-m-d', @strtotime(trim(implode("\n", $output))));
32+
$crate_dates[$crate] = $last_commit_date;
33+
2634
$cratepaths[] = sprintf("%s[::]%s",
2735
escapeshellarg(sprintf("%s/%s", $workdir, $cratedir)),
2836
escapeshellarg($src_url_mask));
@@ -37,7 +45,7 @@
3745

3846
shell($cmd) && die("");
3947

40-
gen_html_index($diagrams_dir, $json);
48+
gen_html_index($diagrams_dir, $json, $crate_dates);
4149

4250
echo "\nFinished. Diagrams are in $diagrams_dir\n";
4351

@@ -48,7 +56,7 @@ function shell($cmd) {
4856
return $rc;
4957
}
5058

51-
function gen_html_index($diagrams_dir, $json) {
59+
function gen_html_index($diagrams_dir, $json, $crate_dates) {
5260

5361
$buf = <<< END
5462
<html><head><style>
@@ -74,7 +82,7 @@ function gen_html_index($diagrams_dir, $json) {
7482
<body>
7583
<table class='diagrams'>
7684
<thead>
77-
<tr><td>Crate</td><td colspan="3">Diagrams</td><td colspan="3">References</td></tr>
85+
<tr><td>Crate</td><td colspan="3">Diagrams</td><td colspan="3">References</td><td>Last Commit</td></tr>
7886
</thead>
7987
END;
8088

@@ -88,8 +96,9 @@ function gen_html_index($diagrams_dir, $json) {
8896
$compact = sprintf('%s-compact.svg', $crate);
8997
$full = sprintf('%s.svg', $crate);
9098
$class = $cnt % 2 == 0 ? 'even' : 'odd';
99+
$last_commit_date = @$crate_dates[$crate];
91100

92-
$buf .= sprintf('<tr class="%s"><td>%s</td><td><a href="%s">bare</a></td><td><a href="%s">compact</a></td><td><a href="%s">full</a></td><td><a href="%s">repo</a></td><td><a href="%s">crates.io</a></td><td><a href="%s">docs.rs</a></td></tr>', $class, $crate, $bare, $compact, $full, $url, $crate_io_url, $docs_rs_url) . "\n";
101+
$buf .= sprintf('<tr class="%s"><td>%s</td><td><a href="%s">bare</a></td><td><a href="%s">compact</a></td><td><a href="%s">full</a></td><td><a href="%s">repo</a></td><td><a href="%s">crates.io</a></td><td><a href="%s">docs.rs</a></td><td>%s</td></tr>', $class, $crate, $bare, $compact, $full, $url, $crate_io_url, $docs_rs_url, $last_commit_date) . "\n";
93102
$cnt ++;
94103
}
95104
$buf .= "</table></body></html>";

0 commit comments

Comments
 (0)