Refactor: полный переход на простой Python + Markdown (без Hugo)
This commit is contained in:
parent
2b8cd21e74
commit
228f3fed61
88
build.py
Normal file
88
build.py
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
import os
|
||||||
|
import markdown
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Базовый HTML-шаблон с подключенным KaTeX для формул
|
||||||
|
TEMPLATE = """<!DOCTYPE html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{title} | ФМИ</title>
|
||||||
|
<!-- Подключаем KaTeX для красивых формул -->
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
|
||||||
|
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
|
||||||
|
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js" onload="renderMathInElement(document.body);"></script>
|
||||||
|
<style>
|
||||||
|
body {{ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; line-height: 1.6; color: #333; }}
|
||||||
|
header {{ border-bottom: 2px solid #003366; padding-bottom: 10px; margin-bottom: 30px; }}
|
||||||
|
h1 {{ color: #003366; }}
|
||||||
|
.meta {{ color: #666; font-size: 0.9em; margin-bottom: 20px; }}
|
||||||
|
nav {{ margin-bottom: 30px; }}
|
||||||
|
nav a {{ margin-right: 15px; text-decoration: none; color: #003366; font-weight: bold; }}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>Физико-математический институт</h1>
|
||||||
|
<nav>
|
||||||
|
<a href="/">Главная</a>
|
||||||
|
<a href="/news.html">Новости</a>
|
||||||
|
<a href="/staff.html">Сотрудники</a>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
{content}
|
||||||
|
</main>
|
||||||
|
<footer style="margin-top: 50px; border-top: 1px solid #ccc; padding-top: 20px; font-size: 0.8em; color: #666;">
|
||||||
|
© 2026 Физико-математический институт
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>"""
|
||||||
|
|
||||||
|
def build_page(md_path, html_path, title):
|
||||||
|
with open(md_path, 'r', encoding='utf-8') as f:
|
||||||
|
md_text = f.read()
|
||||||
|
|
||||||
|
# Конвертируем Markdown в HTML + поддерживаем формулы
|
||||||
|
html_content = markdown.markdown(md_text, extensions=['fenced_code', 'tables'])
|
||||||
|
|
||||||
|
with open(html_path, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(TEMPLATE.format(title=title, content=html_content))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# Создаем папку для готового сайта
|
||||||
|
Path('public').mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
# 1. Главная страница (список новостей)
|
||||||
|
news_files = sorted(Path('content/news').glob('*.md'), reverse=True)
|
||||||
|
news_links = "".join([f'<li><a href="news/{f.stem}.html">{f.stem}</a></li>' for f in news_files])
|
||||||
|
build_page(Path('content/index.md'), 'public/index.html', 'Главная') # Создайте этот файл
|
||||||
|
|
||||||
|
# 2. Страница всех новостей
|
||||||
|
news_list_html = "<h2>Последние новости</h2><ul>" + news_links + "</ul>"
|
||||||
|
with open('public/news.html', 'w', encoding='utf-8') as f:
|
||||||
|
f.write(TEMPLATE.format(title="Новости", content=news_list_html))
|
||||||
|
|
||||||
|
# 3. Отдельные страницы новостей
|
||||||
|
for md_file in news_files:
|
||||||
|
out_path = Path(f'public/news/{md_file.stem}.html')
|
||||||
|
out_path.parent.mkdir(exist_ok=True)
|
||||||
|
build_page(md_file, out_path, md_file.stem.replace('-', ' ').title())
|
||||||
|
|
||||||
|
# 4. Страница сотрудников (аналогично)
|
||||||
|
staff_files = sorted(Path('content/staff').glob('*.md'))
|
||||||
|
staff_links = "".join([f'<li><a href="staff/{f.stem}.html">{f.stem}</a></li>' for f in staff_files])
|
||||||
|
staff_list_html = "<h2>Наши сотрудники</h2><ul>" + staff_links + "</ul>"
|
||||||
|
with open('public/staff.html', 'w', encoding='utf-8') as f:
|
||||||
|
f.write(TEMPLATE.format(title="Сотрудники", content=staff_list_html))
|
||||||
|
|
||||||
|
for md_file in staff_files:
|
||||||
|
out_path = Path(f'public/staff/{md_file.stem}.html')
|
||||||
|
out_path.parent.mkdir(exist_ok=True)
|
||||||
|
build_page(md_file, out_path, md_file.stem.replace('-', ' ').title())
|
||||||
|
|
||||||
|
print("✅ Сайт успешно собран!")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
1
content/index.md
Normal file
1
content/index.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Добро пожаловать на сайт ФМИ
|
||||||
9
content/news/2026-07-22-seminar.md
Normal file
9
content/news/2026-07-22-seminar.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Семинар по квантовой механике
|
||||||
|
|
||||||
|
Дата: 25 июля 2026 г.
|
||||||
|
|
||||||
|
На семинаре будет рассмотрено уравнение Шрёдингера:
|
||||||
|
|
||||||
|
$$ i\hbar \frac{\partial}{\partial t} \Psi = \hat{H} \Psi $$
|
||||||
|
|
||||||
|
Приглашаются все сотрудники и аспиранты.
|
||||||
6
content/staff/ivanov.md
Normal file
6
content/staff/ivanov.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Иванов Иван Иванович
|
||||||
|
|
||||||
|
**Должность:** Ведущий научный сотрудник
|
||||||
|
**Степень:** д.ф.-м.н.
|
||||||
|
|
||||||
|
Специалист в области математической физики.
|
||||||
Loading…
x
Reference in New Issue
Block a user