Skip to content

Commit ea4fea6

Browse files
list folders first and hide size for folders.
1 parent 533c775 commit ea4fea6

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

index_generator/__main__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ def generate_once(template_dir, path='.', name='index.html', if_print=False):
4949
)
5050
template = environment.get_template(name)
5151
entries = list(map(lambda f: Entry(f), os.listdir(path)))
52+
entries.sort(key=lambda x: x.isDir, reverse=True)
5253
files = []
5354
for entry in entries:
5455
files.append({
5556
'path': entry.path,
5657
'name': entry.name,
5758
'size': entry.size,
5859
'modified': time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(entry.modified)),
59-
'mime': entry.mime
60+
'mime': entry.mime,
61+
'isDir': entry.isDir
6062
})
6163
html = template.render(ig={
6264
'currentPath': '/',

index_generator/models/entries.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ def __init__(self, path, root='/'):
99
self.path = root + path
1010
self.size = os.path.getsize(path)
1111
self.modified = os.path.getmtime(path)
12+
self.isDir = os.path.isdir(path)

index_generator/templates/default/index.html

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@
1919
<td>-</td>
2020
<td>-</td>
2121
</tr>
22-
{% for dir in ig.dirs %}
23-
<tr>
24-
<td><a href="{{ ig.currentPath }}/{{ dir.name }}">{{ dir.name }}/</a></td>
25-
<td>{{ dir.modified }}</td>
26-
<td>-</td>
27-
</tr>
28-
{% endfor %}
2922
{% for file in ig.files %}
3023
<tr>
31-
<td><a href="{{ ig.currentPath }}/{{ file.name }}">{{ file.name }}</a></td>
24+
<td><a href="{{ file.name }}">{{ file.name }}</a></td>
3225
<td>{{ file.modified }}</td>
26+
{% if file.isDir %}
27+
<td>-</td>
28+
{% else %}
3329
<td>{{ file.size }}</td>
30+
{% endif %}
3431
</tr>
3532
{% endfor %}
3633
</table>

0 commit comments

Comments
 (0)