diff --git a/updog/__main__.py b/updog/__main__.py index 63d5e06..2ba4ba9 100644 --- a/updog/__main__.py +++ b/updog/__main__.py @@ -12,6 +12,37 @@ from updog.utils.output import error, info, warn, success from updog import version as VERSION +def breadcrumb_items(base_directory, path): + + base_parts = [] + path_parts = [] + current = '/' + + if path: + items = [p for p in path.split('/') if p] + i = 0 + for item in items: + i += 1 + current += item + '/' + if i == len(items): + # Current directory + path_parts.append((item, None)) + else: + # Parent directory of current + path_parts.append((item, current)) + + items = [p for p in base_directory.split('/') if p] + i = 0 + for item in items: + i += 1 + if i == len(items) and path_parts: + # Link to root directory + base_parts.append((item, '/')) + else: + # Unsharable item, parent of root directory + base_parts.append((item, None)) + + return base_parts + path_parts def read_write_directory(directory): if os.path.exists(directory): @@ -22,7 +53,6 @@ def read_write_directory(directory): else: error('The specified directory does not exist') - def parse_arguments(): parser = argparse.ArgumentParser(prog='updog') cwd = os.getcwd() @@ -42,7 +72,6 @@ def parse_arguments(): return args - def main(): args = parse_arguments() @@ -110,8 +139,13 @@ def home(path): except PermissionError: abort(403, 'Read Permission Denied: ' + requested_path) - return render_template('home.html', files=directory_files, back=back, - directory=requested_path, is_subdirectory=is_subdirectory, version=VERSION) + return render_template('home.html', + files=directory_files, + back=back, + directory=requested_path, + breadcrumb_path = breadcrumb_items(base_directory, path), + is_subdirectory=is_subdirectory, + version=VERSION) else: return redirect('/') diff --git a/updog/templates/home.html b/updog/templates/home.html index c53a4a3..2756586 100644 --- a/updog/templates/home.html +++ b/updog/templates/home.html @@ -24,7 +24,7 @@
-

Directory: {{ directory }}

+

Directory: {% for crumb in breadcrumb_path %}/{% if crumb[1] %}{{crumb[0]}}{% else %}{{ crumb[0] }}{% endif %}{% endfor %}

@@ -115,4 +115,4 @@

Directory: {{ directory }}

- \ No newline at end of file +