-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmk-indexes.pl.html
95 lines (89 loc) · 2.66 KB
/
mk-indexes.pl.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>sum codez: using mk-indexes.pl</title>
<link rel="stylesheet" type="text/css" href="./documentation.css"/>
</head>
<body>
<div id="app">
<h1>sum codez: using mk-indexes.pl to create index.html files</h1>
<p>
the script <code>mk-index.pl</code> may be used to create
index.html files for directories on the website that don't
have default indexes.
</p>
<p>
Note that this script is a work in progress and will
ultimately be moved to PHP in order that it may more
efficiently be run "live" to create index files
"on the fly" at run-time.
</p>
<pre class="code">
#!/usr/bin/perl -w
my $ifn = "directories";
my $ofn = "00Tree.html";
my @exts = ( "php","html","js","xml" );
open my $inp, '<', $ifn or die "Can't read direcoties list : $!";
while ( <$inp> ) {
my $indexfile = "";
$ofn="";
chomp;
$dirname = $_;
my $i = scalar @exts;
while ( $i > 0 ) {
$i--;
$indexfile = "$dirname/index.$exts[$i-1]";
if (-T $indexfile) {
$ofn = $indexfile;
print "Found INDEX file $indexfile\n";
break;
}
}
if ( $indexfile ) {
} else {
print "\n$dirname does not have index $ofn\n";
opendir(my $dh, $dirname) || die "Can't open $dirname: $!";
while (readdir $dh) {
unless (m/^\./) {
chomp;
if (m/^index\.[php,html,js,xml]$/) {
print "$_\n";
}
print "$dirname/$_\n";
}
}
closedir $dh;
}
}
close $inp;
# use IO::File;
# $fh = IO::File->new($ifn,'r');
# if (defined $fh) {
# print <$fh>;
# undef $fh;
# }
##
## Get the entire file at once using Path::Tiny;
##
#use Path::Tiny;
#my $all_of_it = path($filename)->slurp; # entire file in scalar
#for my $line ( path($filename)->lines ) { print $line; }
#open(my $fh,"<",$ifn) || die "cannot open directory list $ifn";
##
#while ( my $line = <$fh> )
#{
# # read the name of a sub-directory from the input file.
# # TODO: the input file should be read into an array all at once;
# ( defined( $_ = readline($fh)) )
# or die( "readline() failed for $ifn: $!");
# change to the sub-directory we're creating the index for
# $cmd = 'tree --timefmt="%F %X" -Rx -I "*~" -T $PWD -o $ofn -fDhH .';
# print "$_";
#}
#close($fh);
</div>
</body>
</html>