Fix subfolder files
This commit is contained in:
parent
188454667a
commit
a4c8bd8a01
42
main.py
42
main.py
@ -792,44 +792,14 @@ def _render_folder_index_page(
|
|||||||
|
|
||||||
template = string.Template(content)
|
template = string.Template(content)
|
||||||
|
|
||||||
# Build folder index sidebar HTML
|
# Build folder index sidebar HTML using recursive tree renderer
|
||||||
prefix = path.rstrip("/") or ""
|
folder_path = path.rstrip("/") or None
|
||||||
lines: list[str] = []
|
folder_index_html = _render_folder_index_html(
|
||||||
|
current_path=folder_path,
|
||||||
# Breadcrumb
|
current_order=current_order,
|
||||||
lines.append("<nav class='breadcrumb'>")
|
current_delay=current_delay,
|
||||||
lines.append('<a href="/navigate/">/</a>')
|
|
||||||
if prefix:
|
|
||||||
parts = prefix.split("/")
|
|
||||||
accumulated = ""
|
|
||||||
for part in parts:
|
|
||||||
accumulated += f"{part}/"
|
|
||||||
lines.append(f'<a href="/navigate/{accumulated}">{part}</a>')
|
|
||||||
lines.append("</nav>")
|
|
||||||
|
|
||||||
# Folders
|
|
||||||
for folder in folders:
|
|
||||||
folder_path = f"{prefix}{folder}/" if prefix else f"{folder}/"
|
|
||||||
lines.append(
|
|
||||||
f'<div class="index-item folder">'
|
|
||||||
f'<a href="/navigate/{folder_path}">📁 {folder}</a>'
|
|
||||||
f"</div>"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Files
|
|
||||||
for file in files:
|
|
||||||
file_path = f"{prefix}{file}" if prefix else file
|
|
||||||
href_params = ""
|
|
||||||
if current_order is not None and current_delay is not None:
|
|
||||||
href_params = f"?order={current_order}&delay={current_delay}"
|
|
||||||
lines.append(
|
|
||||||
f'<div class="index-item file">'
|
|
||||||
f'<a href="/navigate/{file_path}{href_params}">📄 {file}</a>'
|
|
||||||
f"</div>"
|
|
||||||
)
|
|
||||||
|
|
||||||
folder_index_html = "\n".join(lines)
|
|
||||||
|
|
||||||
content = template.substitute(
|
content = template.substitute(
|
||||||
img_url="#",
|
img_url="#",
|
||||||
image_click_url="#",
|
image_click_url="#",
|
||||||
|
|||||||
@ -106,6 +106,24 @@ class TestNavigatePage:
|
|||||||
response = await client_zip_navigate.get("/navigate/")
|
response = await client_zip_navigate.get("/navigate/")
|
||||||
assert "/navigate/top.txt" in response.text
|
assert "/navigate/top.txt" in response.text
|
||||||
|
|
||||||
|
async def test_subfolder_index_shows_nested_files(
|
||||||
|
self, client_zip_navigate: AsyncClient
|
||||||
|
) -> None:
|
||||||
|
"""Subfolder index shows files within that folder."""
|
||||||
|
response = await client_zip_navigate.get("/navigate/folder/")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert "/navigate/folder/deep.txt" in response.text
|
||||||
|
assert "/navigate/folder/image.png" in response.text
|
||||||
|
|
||||||
|
async def test_subfolder_index_shows_full_tree(
|
||||||
|
self, client_zip_navigate: AsyncClient
|
||||||
|
) -> None:
|
||||||
|
"""Subfolder index sidebar shows full tree from root."""
|
||||||
|
response = await client_zip_navigate.get("/navigate/folder/")
|
||||||
|
assert response.status_code == 200
|
||||||
|
# Should still show root-level items in the tree
|
||||||
|
assert "/navigate/top.txt" in response.text
|
||||||
|
|
||||||
async def test_file_page_has_sidebar(
|
async def test_file_page_has_sidebar(
|
||||||
self, client_zip_navigate: AsyncClient
|
self, client_zip_navigate: AsyncClient
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user