Skip to content

Commit

Permalink
dir2html: Better filtering of uninteresting files & CSS classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oberon00 committed Apr 2, 2016
1 parent f7fc440 commit 8c07b6a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 14 additions & 4 deletions dir2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,27 @@ def ext(fname):
def write_dir_listing(indirname, outfname):
lines = []
outdirname = path.dirname(outfname)
try:
os.remove(outfname) # Avoid self-listing.
except FileNotFoundError:
pass

for root, dirs, files in os.walk(indirname):
def file_filter(f):
stemName, extName = path.splitext(f)
if extName != ".html":
return False
if ext(stemName)[1:].lower() not in CEXTS:
return False
return True

files = list(filter(file_filter, files))
if not files:
continue
files.sort()
root = path.relpath(root, outdirname)
lines.append('<li class="dir">{0}:<ul>'.format(root))
lines.append('<li class="dir"><span class="dirname">{0}</span><ul>'.format(root))
for file in files:
stemName = stem(file)
if ext(stemName)[1:].lower() not in CEXTS:
continue
lines.append('<li class="file"><a href="{0}">{1}</a></li>'
.format(escape(path.join(root, file)), escape(stem(file))))
lines.append("</ul></li>")
Expand Down
6 changes: 3 additions & 3 deletions dirlisting.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ ul {
list-style-type: none;
}

.dir {
.dirname {
font-weight: bold;
margin-top: 2em;
}

.dir > * {
font-weight: normal;
.dirname:after {
content: ":";
}

@media screen and (min-width: 500px), print {
Expand Down

0 comments on commit 8c07b6a

Please sign in to comment.