feature: Directory tree and multi-column file listing

This commit is contained in:
Keith Solomon
2026-01-03 12:32:23 -06:00
parent 046f08d559
commit 318ef5f9b2
4 changed files with 231 additions and 18 deletions

View File

@@ -88,9 +88,11 @@ function parseApacheIndex(html, baseUrl) {
const results = [];
const preMatch = html.match(/<pre>[\s\S]*?<\/pre>/i);
const block = preMatch ? preMatch[0] : html;
const linkRegex = /<a href="([^"]+)">([^<]+)<\/a>/gi;
let match;
while ((match = linkRegex.exec(block)) !== null) {
const preLines = preMatch ? preMatch[0].split(/\r?\n/) : block.split(/\r?\n/);
const linkRegex = /<a href="([^"]+)">([^<]+)<\/a>/i;
for (const line of preLines) {
const match = line.match(linkRegex);
if (!match) continue;
const href = match[1];
const anchorText = match[2];
if (href === '../' || anchorText === '../') continue;
@@ -110,7 +112,16 @@ function parseApacheIndex(html, baseUrl) {
} catch (err) {
name = anchorText;
}
results.push({ name, href: fullUrl, isDir });
let size = '-';
const rest = line.slice(match.index + match[0].length).trim();
if (rest) {
const tokens = rest.split(/\s+/);
const sizeToken = tokens[tokens.length - 1];
if (sizeToken && sizeToken !== '-') {
size = sizeToken;
}
}
results.push({ name, href: fullUrl, isDir, size });
}
return results;
}