diff --git a/build.py b/build.py index 453d629..cb76b9c 100644 --- a/build.py +++ b/build.py @@ -48,6 +48,7 @@ TEMPLATE = """ Новости Сотрудники Публикации + События
В этом разделе скоро появятся научные публикации и документы.
")) - - # 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 = "В ближайшее время мероприятий не запланировано.
" + + # Создаем страницу событий + 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'← Назад к календарю\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')