Skip to content

Commit

Permalink
Fix the sidebar ordering: Directories alphabetically sorted first and…
Browse files Browse the repository at this point in the history
… then files in the same level alphabetically sorted. Fixes #160
  • Loading branch information
hakan committed Jul 16, 2021
1 parent ec1090c commit c482d72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion pervane/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import shutil
import subprocess
import sys
from operator import itemgetter

from jinja2 import Environment, BaseLoader
from flask import Flask, render_template, request, jsonify, redirect, url_for, send_from_directory, flash
Expand Down Expand Up @@ -351,7 +352,15 @@ def _make_tree(path):
this_node['children'].append(dict(
name=child_name, path=_get_workspace_path(child_path),
kind='file', ext=os.path.splitext(child_path)[1]))
return this_node

if len(this_node['children']) > 0:
# Sort by two keys.
# Kind is for sorting the directories first.
# Name is for natural alphabetical order within directories and files
# separately.
this_node['children'] = sorted(
this_node['children'], key=itemgetter('kind', 'name'))
return this_node


def is_ignored(file_path):
Expand Down
2 changes: 1 addition & 1 deletion pervane/templates/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
var searchResults = {{ search_results|safe if search_results else [] }};
var searchQuery = '{{ query if query else '' }}';
var searchStats = '{{ stats if stats else ''}}';
var tree = {{tree|safe}};
var tree = {{ tree|safe }};
</script>

{% raw %}
Expand Down
2 changes: 1 addition & 1 deletion pervane/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.81
0.0.82

0 comments on commit c482d72

Please # to comment.