Обновить build.py

This commit is contained in:
masterpmi 2026-07-23 21:28:20 +03:00
parent df2a42bfce
commit 84882db02d

View File

@ -136,17 +136,52 @@ def main():
if Path('content/index.md').exists():
build_page(Path('content/index.md'), 'public/index.html', 'Главная')
# 2. Страница новостей
# 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])
# Добавляем хлебные крошки к контенту
news_cards = []
for md_file in news_files:
with open(md_file, 'r', encoding='utf-8') as f:
meta, body = parse_front_matter(f.read())
title = meta.get('title', md_file.stem.replace('-', ' ').title())
date = meta.get('date', '')
# Берем первые 200 символов как анонс
excerpt = body[:200].strip()
if len(body) > 200:
excerpt += '...'
# Конвертируем в HTML (только первый абзац)
first_paragraph = body.split('\n\n')[0] if '\n\n' in body else body[:150]
excerpt_html = markdown.markdown(first_paragraph, extensions=['fenced_code'])
# Форматируем дату
if date:
try:
from datetime import datetime
date_obj = datetime.strptime(date, '%Y-%m-%d')
date_formatted = date_obj.strftime('%d.%m.%Y')
except:
date_formatted = date
else:
date_formatted = md_file.stem.replace('-', '.')
card_html = f'''
<div class="news-card">
<h2><a href="news/{md_file.stem}.html">{title}</a></h2>
<div class="news-date">{date_formatted}</div>
<div class="news-excerpt">{excerpt_html}</div>
<a href="news/{md_file.stem}.html" class="news-read-more">Читать далее</a>
</div>'''
news_cards.append(card_html)
breadcrumbs = build_breadcrumbs('/news.html')
news_content = breadcrumbs + "<h2>Последние новости</h2><ul>" + news_links + "</ul>"
news_content = breadcrumbs + "<h2>Последние новости</h2>" + "".join(news_cards)
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:
build_page(md_file, Path(f'public/news/{md_file.stem}.html'), md_file.stem.replace('-', ' ').title())
f.write(TEMPLATE.format(title="Новости", content=news_content))
# 3. Страница сотрудников
staff_by_lab = {}