1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 16:55:08 +00:00

WebServer: Use table tags in directory listings

Use tables to align stuff instead of putting everything in a <pre>.
This commit is contained in:
Andreas Kling 2020-07-27 19:40:34 +02:00
parent efa117f801
commit 5c7d54d50d

View file

@ -167,18 +167,16 @@ void Client::handle_directory_listing(const String& requested_path, const String
builder.append(escape_html_entities(requested_path)); builder.append(escape_html_entities(requested_path));
builder.append("</h1>\n"); builder.append("</h1>\n");
builder.append("<hr>\n"); builder.append("<hr>\n");
builder.append("<pre>\n"); builder.append("<table>\n");
Core::DirIterator dt(real_path); Core::DirIterator dt(real_path);
while (dt.has_next()) { while (dt.has_next()) {
auto name = dt.next_path(); auto name = dt.next_path();
builder.append("<a href=\""); builder.append("<tr><td><a href=\"");
builder.append(urlencode(name)); builder.append(urlencode(name));
builder.append("\">"); builder.append("\">");
builder.append(escape_html_entities(name)); builder.append(escape_html_entities(name));
builder.append("</a>"); builder.append("</a></td>");
for (size_t i = 0; i < (40 - name.length()); ++i)
builder.append(' ');
StringBuilder path_builder; StringBuilder path_builder;
path_builder.append(real_path); path_builder.append(real_path);
@ -190,13 +188,14 @@ void Client::handle_directory_listing(const String& requested_path, const String
if (rc < 0) { if (rc < 0) {
perror("stat"); perror("stat");
} }
builder.appendf(" %10d", st.st_size); builder.appendf("<td>%10d</td>", st.st_size);
builder.appendf(" "); builder.append("<td>");
builder.append(Core::DateTime::from_timestamp(st.st_mtime).to_string()); builder.append(Core::DateTime::from_timestamp(st.st_mtime).to_string());
builder.append("\n"); builder.append("</td>");
builder.append("</tr>\n");
} }
builder.append("</pre>\n"); builder.append("</table>\n");
builder.append("<hr>\n"); builder.append("<hr>\n");
builder.append("<i>Generated by WebServer (SerenityOS)</i>\n"); builder.append("<i>Generated by WebServer (SerenityOS)</i>\n");
builder.append("</body>\n"); builder.append("</body>\n");