Обновить build.py
This commit is contained in:
parent
ca6f42da87
commit
6d1de9e79a
32
build.py
32
build.py
@ -91,16 +91,24 @@ def build_page(md_path, html_path, title):
|
||||
f.write(TEMPLATE.format(title=title, content=html_content))
|
||||
|
||||
# Улучшенная навигация с "хлебными крошками"
|
||||
def build_breadcrumbs(path):
|
||||
"""Создает навигационную цепочку"""
|
||||
crumbs = [
|
||||
'<nav class="breadcrumbs"><a href="/">Главная</a>',
|
||||
]
|
||||
parts = path.strip('/').split('/')
|
||||
for i, part in enumerate(parts[:-1]):
|
||||
url = '/' + '/'.join(parts[:i+1]) + '/'
|
||||
crumbs.append(f' / <a href="{url}">{part.title()}</a>')
|
||||
crumbs.append(f' / <span>{parts[-1]}</span></nav>')
|
||||
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>')
|
||||
else:
|
||||
crumbs.append(f' / <a href="{current_url}">{part.title()}</a>')
|
||||
|
||||
crumbs.append('</nav>')
|
||||
return ''.join(crumbs)
|
||||
# ------------------------------------------------------------------------
|
||||
def main():
|
||||
@ -115,6 +123,10 @@ def main():
|
||||
# 2. Страница новостей
|
||||
news_files = sorted(Path('content/news').glob('*.md'), reverse=True)
|
||||
news_links = "".join([f'<li><a href="news/{f.stem}.html">{f.stem.replace("-", " ").title()}</a></li>' for f in news_files])
|
||||
# Добавляем хлебные крошки к контенту
|
||||
breadcrumbs = build_breadcrumbs('/news.html')
|
||||
news_content = breadcrumbs + "<h2>Последние новости</h2><ul>" + news_links + "</ul>"
|
||||
|
||||
with open('public/news.html', 'w', encoding='utf-8') as f:
|
||||
f.write(TEMPLATE.format(title="Новости", content=f"<h2>Последние новости</h2><ul>{news_links}</ul>"))
|
||||
for md_file in news_files:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user