Commit 13ccaad9 authored by vapier's avatar vapier Committed by Commit bot

add basic directory listing support

Current behavior when trying to browse to the basic URL is to return
an error message, and then force the dev to figure out the full path
to the doc and put it in.  Let's present a simple directory listing
instead for them to navigate if they want.

This doesn't try to emulate gitiles, just produce something that isn't
awful on the eyes.

R=dpranke@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2742683002
Cr-Commit-Position: refs/heads/master@{#455692}
parent fde2d611
......@@ -139,7 +139,7 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
elif os.path.exists(full_path + '/README.md'):
self._DoMD(path + '/README.md')
else:
self._DoUnknown()
self._DoDirListing(full_path)
def _DoMD(self, path):
extensions = [
......@@ -187,10 +187,41 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self.wfile.write('<html><body>%s not found</body></html>' % self.path)
def _DoUnknown(self):
self._WriteHeader('text/html')
self._WriteHeader('text/html', status_code=501)
self.wfile.write('<html><body>I do not know how to serve %s.</body>'
'</html>' % self.path)
def _DoDirListing(self, full_path):
self._WriteHeader('text/html')
self._WriteTemplate('header.html')
self.wfile.write('<div class="Breadcrumbs">\n')
self.wfile.write('<a class="Breadcrumbs-crumb">%s</a>\n' % self.path)
self.wfile.write('</div>\n')
for _, dirs, files in os.walk(full_path):
for f in sorted(files):
if f.startswith('.'):
continue
if f.endswith('.md'):
bold = ('<b>', '</b>')
else:
bold = ('', '')
self.wfile.write('<a href="%s/%s">%s%s%s</a><br/>\n' %
(self.path.rstrip('/'), f, bold[0], f, bold[1]))
self.wfile.write('<br/>\n')
for d in sorted(dirs):
if d.startswith('.'):
continue
self.wfile.write('<a href="%s/%s">%s/</a><br/>\n' %
(self.path.rstrip('/'), d, d))
break
self._WriteTemplate('footer.html')
def _Read(self, relpath, relative_to=None):
if relative_to is None:
relative_to = self.server.top_level
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment