Обновить build.py
This commit is contained in:
parent
480f432d78
commit
5400ec2501
19
build.py
19
build.py
@ -107,23 +107,24 @@ def build_page(md_path, html_path, title):
|
||||
with open(html_path, 'w', encoding='utf-8') as f:
|
||||
f.write(TEMPLATE.format(title=title, content=html_content))
|
||||
|
||||
# Улучшенная навигация с "хлебными крошками"
|
||||
def build_breadcrumbs(current_path):
|
||||
"""Создает навигационную цепочку (хлебные крошки)"""
|
||||
crumbs = ['<nav class="breadcrumbs">']
|
||||
crumbs.append('<a href="/">🏠 Главная</a>')
|
||||
|
||||
# Разбираем путь
|
||||
parts = current_path.strip('/').split('/')
|
||||
current_url = ''
|
||||
|
||||
for part in parts:
|
||||
current_url += '/' + part
|
||||
# Пропускаем последние элементы (это текущая страница)
|
||||
if part == parts[-1]:
|
||||
crumbs.append(f' / <span style="color: #666;">{part.replace(".html", "").title()}</span>')
|
||||
for i, part in enumerate(parts):
|
||||
if i == len(parts) - 1:
|
||||
# Последний элемент — это текущая страница, делаем её текстом
|
||||
display_name = part.replace('.html', '').replace('-', ' ').title()
|
||||
crumbs.append(f' / <span style="color: #888;">{display_name}</span>')
|
||||
else:
|
||||
crumbs.append(f' / <a href="{current_url}">{part.title()}</a>')
|
||||
# Промежуточные элементы. В нашей структуре файлы лежат в корне (news.html),
|
||||
# поэтому нужно обязательно добавлять .html к ссылке.
|
||||
display_name = part.replace('.html', '').replace('-', ' ').title()
|
||||
link = f"/{part}.html" if not part.endswith('.html') else f"/{part}"
|
||||
crumbs.append(f' / <a href="{link}">{display_name}</a>')
|
||||
|
||||
crumbs.append('</nav>')
|
||||
return ''.join(crumbs)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user