Обновить build.py
This commit is contained in:
parent
3da5864338
commit
ab000eecc9
76
build.py
76
build.py
@ -48,6 +48,7 @@ TEMPLATE = """<!DOCTYPE html>
|
||||
<a href="/news.html">Новости</a>
|
||||
<a href="/staff.html">Сотрудники</a>
|
||||
<a href="/publications.html">Публикации</a>
|
||||
<a href="/events.html">События</a>
|
||||
</nav>
|
||||
|
||||
<div class="search-box">
|
||||
@ -274,8 +275,79 @@ def main():
|
||||
# Если PDF пока нет, создаем заглушку
|
||||
with open('public/publications.html', 'w', encoding='utf-8') as f:
|
||||
f.write(TEMPLATE.format(title="Публикации", content="<h2>Публикации</h2><p>В этом разделе скоро появятся научные публикации и документы.</p>"))
|
||||
|
||||
# 6. Копирование статических файлов (картинки, PDF, CSS)
|
||||
|
||||
# 6. Страница событий (календарь)
|
||||
events = []
|
||||
|
||||
for event_file in sorted(Path('content/events').glob('*.md')):
|
||||
with open(event_file, 'r', encoding='utf-8') as f:
|
||||
meta, body = parse_front_matter(f.read())
|
||||
|
||||
title = meta.get('title', event_file.stem.replace('-', ' ').title())
|
||||
date = meta.get('date', '')
|
||||
time = meta.get('time', '')
|
||||
location = meta.get('location', '')
|
||||
|
||||
# Форматируем дату
|
||||
try:
|
||||
from datetime import datetime
|
||||
date_obj = datetime.strptime(date, '%Y-%m-%d')
|
||||
date_formatted = date_obj.strftime('%d %B %Y')
|
||||
except:
|
||||
date_formatted = date
|
||||
|
||||
events.append({
|
||||
'title': title,
|
||||
'date': date_formatted,
|
||||
'time': time,
|
||||
'location': location,
|
||||
'url': f"events/{event_file.stem}.html"
|
||||
})
|
||||
|
||||
# Генерируем HTML для календаря
|
||||
events_html = "<h2>Предстоящие события</h2>"
|
||||
|
||||
if events:
|
||||
for event in events:
|
||||
events_html += f"""
|
||||
<div class="event-item">
|
||||
<div class="event-date">
|
||||
<div class="event-day">{event['date'].split()[0]}</div>
|
||||
<div class="event-month">{event['date'].split()[1]}</div>
|
||||
</div>
|
||||
<div class="event-content">
|
||||
<h3>{event['title']}</h3>
|
||||
<div class="event-details">
|
||||
<div><strong>Дата:</strong> {event['date']}</div>
|
||||
<div><strong>Время:</strong> {event['time']}</div>
|
||||
<div><strong>Место:</strong> {event['location']}</div>
|
||||
</div>
|
||||
<a href="{event['url']}" class="pdf-link" style="margin-top: 15px;">Подробнее</a>
|
||||
</div>
|
||||
</div>"""
|
||||
else:
|
||||
events_html = "<p>В ближайшее время мероприятий не запланировано.</p>"
|
||||
|
||||
# Создаем страницу событий
|
||||
breadcrumbs = build_breadcrumbs('/events.html')
|
||||
with open('public/events.html', 'w', encoding='utf-8') as f:
|
||||
f.write(TEMPLATE.format(title="События", content=breadcrumbs + events_html))
|
||||
|
||||
# Создаем отдельные страницы для каждого события
|
||||
for event_file in Path('content/events').glob('*.md'):
|
||||
with open(event_file, 'r', encoding='utf-8') as f:
|
||||
meta, body = parse_front_matter(f.read())
|
||||
|
||||
title = meta.get('title', event_file.stem.replace('-', ' ').title())
|
||||
breadcrumbs = build_breadcrumbs(f'/events/{event_file.stem}.html')
|
||||
|
||||
full_content = breadcrumbs + f'<a href="/events.html" class="back-link">← Назад к календарю</a>\n' + body
|
||||
html_content = markdown.markdown(full_content, extensions=['fenced_code', 'tables'])
|
||||
|
||||
with open(Path(f'public/events/{event_file.stem}.html'), 'w', encoding='utf-8') as f:
|
||||
f.write(TEMPLATE.format(title=title, content=html_content))
|
||||
|
||||
# 7. Копирование статических файлов (картинки, PDF, CSS)
|
||||
if Path('static').exists():
|
||||
shutil.rmtree('public/static', ignore_errors=True)
|
||||
shutil.copytree('static', 'public/static')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user