logo

blog

My website can't be that messy, right? git clone https://hacktivis.me/git/blog.git

notes_index.pm (1791B)


  1. #!/usr/bin/env perl
  2. # Copyright 2023 Haelwenn (lanodan) Monnier <contact+blog@hacktivis.me>
  3. # SPDX-License-Identifier: MIT
  4. # Gentoo: dev-perl/URI
  5. # Alpine: perl-uri
  6. # https://repology.org/project/perl:uri/versions
  7. use URI::Escape;
  8. print '<!DOCTYPE html>
  9. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  10. <head>
  11. <!--#include file="/templates/head.shtml" -->
  12. <title>Index of /notes/</title>
  13. <link rel="stylesheet" href="/css/sorttable.css?serial=2020091801"/>
  14. </head>
  15. <body>
  16. <!--#include file="/templates/en/nav.shtml" -->
  17. <main>
  18. <table class="sortable">
  19. <thead>
  20. <tr><th class="sorttable_sorted">Name</th><th>Size</th><th>Last Modified</th></tr>
  21. </thead>
  22. <tbody>
  23. ';
  24. chdir('./notes/');
  25. my $lstree =
  26. `git ls-tree -r -z --format="%(objecttype)%x01%(objectsize:padded)%x01%(path)" HEAD`;
  27. my @list = split( /\x00/, $lstree );
  28. foreach (@list) {
  29. my ( $objtype, $size, $raw ) = split( /\x01/, $_, 3 );
  30. $objtype == "blob" or die "${raw}: objtype is ${objtype}, not blob";
  31. if ( $raw =~ /^index\.(s|x)html$/ ) {
  32. next;
  33. }
  34. if ( $raw =~ /\.(br|gz)$/ ) {
  35. next;
  36. }
  37. # try_files $uri $uri.shtml $uri.html $uri.xhtml $uri/ =404;
  38. my $fn = $raw;
  39. $fn =~ s@\.(s|x)?html$@@;
  40. my $escaped = uri_escape_utf8($fn);
  41. $escaped =~ s@%2F@/@;
  42. my $now = `git log -1 --format="format:%ai" -- "$raw"`;
  43. $size =~ s/^ *//;
  44. # thousand separation
  45. my $size_pp = $size;
  46. while ( $size_pp =~ s/(\d+)(\d{3})/$1 $2/ ) { }
  47. printf
  48. " <tr><td><a href=\"%s\">%s</a></td><td data-value=\"%s\" data-type=\"int\">%s B</td><td>%s</td></tr>\n",
  49. $escaped, $fn, $size, $size_pp, $now;
  50. }
  51. print ' </tbody>
  52. </table>
  53. </main>
  54. <!--#include file="/templates/en/footer.shtml" -->
  55. <script src="/javascript/sorttable.js?serial=2023030902"></script>
  56. </body>
  57. </html>
  58. ';