Build a file listing page for any given directory
This commit is contained in:
parent
92d9a14057
commit
4e9dfee799
35
out/DIRECTORY_LISTING
Normal file
35
out/DIRECTORY_LISTING
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<!DOCTYPE html><!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/reset.css">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/sig.css">
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<script type="text/javascript">
|
||||||
|
function loadCodeBackground() {
|
||||||
|
fetch("codeBackground").then((data)=>data.text())
|
||||||
|
.then((data)=>{
|
||||||
|
document.getElementById("codeForeground").innerText=data
|
||||||
|
document.getElementById("codeBackground").innerText=data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
loadCodeBackground();
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="contentBody">
|
||||||
|
|
||||||
|
articles 2022-05-04T18:30:43.309932Z gitpod 116<br/>
|
||||||
|
codeBackground 2022-05-04T18:30:43.285932Z gitpod 2635<br/>
|
||||||
|
otherpage.html 2022-05-04T18:30:43.289932Z gitpod 900<br/>
|
||||||
|
reset.css 2022-05-04T18:30:43.293932Z gitpod 1093<br/>
|
||||||
|
sig.css 2022-05-04T18:30:43.301932Z gitpod 3550<br/>
|
||||||
|
testfile.html 2022-05-04T18:30:43.301932Z gitpod 828<br/>
|
||||||
|
|
||||||
|
</div> <!--End Content Body-->
|
||||||
|
<div class="codeForeground" id="codeForeground"></div>
|
||||||
|
<div class="codeBackground" id="codeBackground"></div>
|
||||||
|
</body>
|
||||||
|
<footer>
|
||||||
|
|
||||||
|
</footer>
|
||||||
|
</html>
|
32
out/articles/DIRECTORY_LISTING
Normal file
32
out/articles/DIRECTORY_LISTING
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<!DOCTYPE html><!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/reset.css">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/sig.css">
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<script type="text/javascript">
|
||||||
|
function loadCodeBackground() {
|
||||||
|
fetch("codeBackground").then((data)=>data.text())
|
||||||
|
.then((data)=>{
|
||||||
|
document.getElementById("codeForeground").innerText=data
|
||||||
|
document.getElementById("codeBackground").innerText=data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
loadCodeBackground();
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="contentBody">
|
||||||
|
|
||||||
|
curabitur vel tempus ex.article 2022-05-04T18:30:43.269932Z gitpod 618<br/>
|
||||||
|
sigplace1.article 2022-05-04T18:30:43.273932Z gitpod 1559<br/>
|
||||||
|
test articles 2022-05-04T18:30:43.205932Z gitpod 69<br/>
|
||||||
|
|
||||||
|
</div> <!--End Content Body-->
|
||||||
|
<div class="codeForeground" id="codeForeground"></div>
|
||||||
|
<div class="codeBackground" id="codeBackground"></div>
|
||||||
|
</body>
|
||||||
|
<footer>
|
||||||
|
|
||||||
|
</footer>
|
||||||
|
</html>
|
32
out/articles/test articles/DIRECTORY_LISTING
Normal file
32
out/articles/test articles/DIRECTORY_LISTING
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<!DOCTYPE html><!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/reset.css">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/sig.css">
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<script type="text/javascript">
|
||||||
|
function loadCodeBackground() {
|
||||||
|
fetch("codeBackground").then((data)=>data.text())
|
||||||
|
.then((data)=>{
|
||||||
|
document.getElementById("codeForeground").innerText=data
|
||||||
|
document.getElementById("codeBackground").innerText=data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
loadCodeBackground();
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="contentBody">
|
||||||
|
|
||||||
|
test1.article 2022-05-04T18:30:43.277932Z gitpod 1111<br/>
|
||||||
|
test2.article 2022-05-04T18:30:43.277932Z gitpod 807<br/>
|
||||||
|
test3.article 2022-05-04T18:30:43.281932Z gitpod 1020<br/>
|
||||||
|
|
||||||
|
</div> <!--End Content Body-->
|
||||||
|
<div class="codeForeground" id="codeForeground"></div>
|
||||||
|
<div class="codeBackground" id="codeBackground"></div>
|
||||||
|
</body>
|
||||||
|
<footer>
|
||||||
|
|
||||||
|
</footer>
|
||||||
|
</html>
|
@ -151,12 +151,47 @@ public class sigPlace {
|
|||||||
map.put("/",new ArrayList<Path>());
|
map.put("/",new ArrayList<Path>());
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Path f = it.next();
|
Path f = it.next();
|
||||||
|
if (!f.getFileName().toString().equals(OUTDIR)) {
|
||||||
String myKey = f.toAbsolutePath().toString().replace(startingPath,"").replace(f.getFileName().toString(),"");
|
String myKey = f.toAbsolutePath().toString().replace(startingPath,"").replace(f.getFileName().toString(),"");
|
||||||
System.out.println(myKey+","+f);
|
//System.out.println(myKey+","+f);
|
||||||
map.putIfAbsent(myKey,new ArrayList<Path>());
|
map.putIfAbsent(myKey,new ArrayList<Path>());
|
||||||
map.get(myKey).add(f);
|
map.get(myKey).add(f);
|
||||||
}
|
}
|
||||||
System.out.println(map);
|
}
|
||||||
|
System.out.println("Directory structure determined:");
|
||||||
|
System.out.println(" "+map);
|
||||||
|
for (String key : map.keySet()) {
|
||||||
|
System.out.println("Creating directory listing for "+key+"...");
|
||||||
|
StringBuilder sb = new StringBuilder("<!DOCTYPE html>");
|
||||||
|
List<String> data = Files.readAllLines(ops.get("%DEFAULT"));
|
||||||
|
List<String> data2 = Files.readAllLines(ops.get("%FOOTER"));
|
||||||
|
for (String d : data) {
|
||||||
|
for (String k : sigPlace.map.keySet()) {
|
||||||
|
d=d.replaceAll(Pattern.quote(k),sigPlace.map.get(k));
|
||||||
|
}
|
||||||
|
sb.append(d).append("\n");
|
||||||
|
}
|
||||||
|
sb.append("<div class=\"filelisting\">");
|
||||||
|
for (Path f : map.get(key)) {
|
||||||
|
sb.append(f.getFileName())
|
||||||
|
.append("\t")
|
||||||
|
.append(Files.getLastModifiedTime(f))
|
||||||
|
.append("\t")
|
||||||
|
.append(Files.getOwner(f))
|
||||||
|
.append("\t")
|
||||||
|
.append(Files.size(f))
|
||||||
|
.append("<br/>\n");
|
||||||
|
}
|
||||||
|
sb.append("</div>");
|
||||||
|
for (String d : data2) {
|
||||||
|
for (String k : sigPlace.map.keySet()) {
|
||||||
|
d=d.replaceAll(Pattern.quote(k),sigPlace.map.get(k));
|
||||||
|
}
|
||||||
|
sb.append(d).append("\n");
|
||||||
|
}
|
||||||
|
Path newf = Files.write(Paths.get(OUTDIR,key,DIRECTORYLISTING_FILENAME),sb.toString().getBytes());
|
||||||
|
System.out.println(" Added info for ("+map.size()+") files to "+newf.toAbsolutePath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private static boolean isArticleFile(Path f) {
|
private static boolean isArticleFile(Path f) {
|
||||||
return f.getFileName().toString().contains(".article");
|
return f.getFileName().toString().contains(".article");
|
||||||
|
@ -94,10 +94,10 @@ public class sigServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CreateRawRequest(clientOutput,statusCode,statusMsg,"text/html","We're sorry, your webpage is in another castle!".getBytes());
|
CreateRawRequest(clientOutput,statusCode,statusMsg,"text/html","<!DOCTYPE html>\nWe're sorry, your webpage is in another castle!".getBytes());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CreateRawRequest(clientOutput,statusCode,statusMsg,"text/html","We're sorry, your webpage exploded!".getBytes());
|
CreateRawRequest(clientOutput,statusCode,statusMsg,"text/html","<!DOCTYPE html>\nWe're sorry, your webpage exploded!".getBytes());
|
||||||
}
|
}
|
||||||
clientOutput.write("\r\n\r\n".getBytes());
|
clientOutput.write("\r\n\r\n".getBytes());
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user