Skip to content

Commit b71de33

Browse files
authored
Update server.jl
1 parent 976efb1 commit b71de33

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/server.jl

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,28 @@ function get_dir_list(dir::AbstractString)
121121
enc = "utf-8" # sys.getfilesystemencoding()
122122
title = "Directory listing for $(dir)"
123123
write(io, """
124-
<!DOCTYPE HTML>
125-
<html>
126-
<head>
127-
""")
128-
write(io, """<meta http-equiv="Content-Type" content="text/html; charset=$(enc)">""")
129-
write(io, """<title>$(title)</title>\n</head>""")
130-
write(io, """<body>\n<h1>$(title)</h1>""")
131-
write(io, """<hr>\n<ul>""")
124+
<!DOCTYPE HTML>
125+
<html>
126+
<head>
127+
<meta charset="utf-8">
128+
<meta name="viewport" content="width=device-width, initial-scale=1">
129+
<title>$(title)</title>
130+
</head>
131+
<body>
132+
<h1>$(title)</h1>
133+
<hr>
134+
<ul>
135+
"""
136+
)
132137

133138
if isfile(path)
134139
linkname = path
135140
displayname = basename(path)
136-
write(io, """<li><a href="$(linkname)">$(displayname)</a></li>""")
137-
list = []
141+
write(io, """
142+
<li><a href="$(linkname)">$(displayname)</a></li>
143+
"""
144+
)
145+
empty!(list)
138146
end
139147

140148
for name in list
@@ -149,12 +157,19 @@ function get_dir_list(dir::AbstractString)
149157
displayname = name * "@"
150158
# Note: a link to a directory displays with @ and links with /
151159
end
152-
write(io, """<li><a href="$(linkname)">$(displayname)</a></li>""")
160+
write(io, """
161+
<li><a href="$(linkname)">$(displayname)</a></li>
162+
"""
163+
)
153164
end
154-
write(io, """</ul>\n<hr>\n</body>\n</html>\n""")
155-
index_page = take!(io)
156-
157-
return index_page
165+
write(io, """
166+
</ul>
167+
<hr>
168+
</body>
169+
</html>
170+
"""
171+
)
172+
return String(take!(io))
158173
end
159174

160175
"""

0 commit comments

Comments
 (0)