Skip to content

Instantly share code, notes, and snippets.

@WillForan
Created November 20, 2023 19:42
Show Gist options
  • Save WillForan/1a6a0d06584f539dcc70f722797aa3d7 to your computer and use it in GitHub Desktop.
Save WillForan/1a6a0d06584f539dcc70f722797aa3d7 to your computer and use it in GitHub Desktop.
global $conf;
$my_pages = file($conf['indexdir'] . '/page.idx');
# don't care about titles -- but might in the future
#$my_titles = file($conf['indexdir'] . '/title.idx');
# $title = trim($my_titles[$id]);
# $title = empty($title)?($key."**"):$title;
$my_dates_html = array();
foreach($my_pages as $id => $page) {
$key = trim($page);
if(preg_match("/^(wiki|notebook|playground|publications)/", $key)) {
continue;
}
$date = p_get_metadata($key,"date", 0);
if(!$date) { continue; }
$fn_size = filesize(wikiFN($key));
$mdate = $date['modified'];
$cdate = $date['created'];
$url = "<a href='?id=" . $key . "'>" . $key . "</a>";
$html = date("Y-m-d", $cdate) . " -- " .
date("Y-m-d", $mdate) . " <font style='color:gray;font-size:smaller;family:monospace'>" .
$fn_size . " b</font> ".
$url ."<br>\n";
array_push($my_dates_html,
array("date"=>$mdate,
"cdate"=>$cdate,
"size" =>$fn_size,
"url" => $url,
"html"=>$html));
//echo $key . "<br>\n";
}
### sort by size
usort($my_dates_html, fn($a, $b) => $a['size'] <=> $b['size']);
echo "<br><br><h2 id=smallest>Smallest</h2>";
echo "<table style='width:400px !important'><tr><th>page</th><th>size</th><th>last mod</th></tr>";
$cnt = 0;
foreach($my_dates_html as $id => $a){
echo "<tr><td>" .
$a["url"] .
"</td><td>" .
$a["size"] .
"</td><td>" .
date("Y-m-d", $a["date"]).
"</td></tr>";
if(++$cnt>15) { break; }
}
echo "</table>";
# sort by last mod. break ties by creation date
# tie breaker not actually working?!
usort($my_dates_html, fn($a, $b) =>
($a['date'] == $b['date'])?
($a['cdate'] <=> $b['cdate']):
($a['date'] <=> $b['date']));
echo "<h2 id=oldest>Oldest</h2>";
$cnt = 0;
foreach($my_dates_html as $id => $a){
echo $a["html"];
if(++$cnt>15) { break; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment