Обновить build.py
This commit is contained in:
parent
7494c1c70e
commit
301d6f441e
44
build.py
44
build.py
@ -29,6 +29,12 @@ TEMPLATE = """<!DOCTYPE html>
|
|||||||
.person-details {{ color: #555; font-size: 0.95em; }}
|
.person-details {{ color: #555; font-size: 0.95em; }}
|
||||||
.back-link {{ display: inline-block; margin-bottom: 20px; color: #003366; text-decoration: none; }}
|
.back-link {{ display: inline-block; margin-bottom: 20px; color: #003366; text-decoration: none; }}
|
||||||
.back-link:hover {{ text-decoration: underline; }}
|
.back-link:hover {{ text-decoration: underline; }}
|
||||||
|
.pdf-link {{ display: inline-flex; align-items: center; padding: 8px 16px; background: #003366; color: white; text-decoration: none; border-radius: 4px; margin: 10px 0; }}
|
||||||
|
.pdf-link:hover {{ background: #004080; }}
|
||||||
|
.pdf-link::before {{ content: ""; margin-right: 8px; }}
|
||||||
|
.pdf-list {{ list-style: none; padding: 0; }}
|
||||||
|
.pdf-list li {{ margin: 10px 0; padding: 10px; background: #f9f9f9; border-left: 4px solid #003366; }}
|
||||||
|
img {{ max-width: 100%; height: auto; display: block; margin: 20px auto; }}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -38,6 +44,7 @@ TEMPLATE = """<!DOCTYPE html>
|
|||||||
<a href="/">Главная</a>
|
<a href="/">Главная</a>
|
||||||
<a href="/news.html">Новости</a>
|
<a href="/news.html">Новости</a>
|
||||||
<a href="/staff.html">Сотрудники</a>
|
<a href="/staff.html">Сотрудники</a>
|
||||||
|
<a href="/publications.html">Публикации</a>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
@ -50,7 +57,6 @@ TEMPLATE = """<!DOCTYPE html>
|
|||||||
</html>"""
|
</html>"""
|
||||||
|
|
||||||
def parse_front_matter(text):
|
def parse_front_matter(text):
|
||||||
"""Простой парсер для извлечения метаданных из начала файла"""
|
|
||||||
if text.strip().startswith('---'):
|
if text.strip().startswith('---'):
|
||||||
parts = text.split('---', 2)
|
parts = text.split('---', 2)
|
||||||
if len(parts) >= 3:
|
if len(parts) >= 3:
|
||||||
@ -87,7 +93,7 @@ def main():
|
|||||||
for md_file in news_files:
|
for md_file in news_files:
|
||||||
build_page(md_file, Path(f'public/news/{md_file.stem}.html'), md_file.stem.replace('-', ' ').title())
|
build_page(md_file, Path(f'public/news/{md_file.stem}.html'), md_file.stem.replace('-', ' ').title())
|
||||||
|
|
||||||
# 3. Страница сотрудников (с группировкой и ссылками!)
|
# 3. Страница сотрудников
|
||||||
staff_by_lab = {}
|
staff_by_lab = {}
|
||||||
unassigned = []
|
unassigned = []
|
||||||
|
|
||||||
@ -105,7 +111,6 @@ def main():
|
|||||||
if position: details.append(position)
|
if position: details.append(position)
|
||||||
details_str = ", ".join(details)
|
details_str = ", ".join(details)
|
||||||
|
|
||||||
# Создаем ссылку на персональную страницу
|
|
||||||
person_html = f'''<div class="person">
|
person_html = f'''<div class="person">
|
||||||
<div class="person-name"><a href="staff/{md_file.stem}.html">{name}</a></div>
|
<div class="person-name"><a href="staff/{md_file.stem}.html">{name}</a></div>
|
||||||
<div class="person-details">{details_str}</div>
|
<div class="person-details">{details_str}</div>
|
||||||
@ -118,7 +123,6 @@ def main():
|
|||||||
staff_by_lab[lab] = []
|
staff_by_lab[lab] = []
|
||||||
staff_by_lab[lab].append(person_html)
|
staff_by_lab[lab].append(person_html)
|
||||||
|
|
||||||
# Формируем HTML для страницы сотрудников
|
|
||||||
staff_html = "<h2>Наши сотрудники</h2>"
|
staff_html = "<h2>Наши сотрудники</h2>"
|
||||||
|
|
||||||
lab_order = [
|
lab_order = [
|
||||||
@ -147,27 +151,47 @@ def main():
|
|||||||
with open('public/staff.html', 'w', encoding='utf-8') as f:
|
with open('public/staff.html', 'w', encoding='utf-8') as f:
|
||||||
f.write(TEMPLATE.format(title="Сотрудники", content=staff_html))
|
f.write(TEMPLATE.format(title="Сотрудники", content=staff_html))
|
||||||
|
|
||||||
# 4. Создаем индивидуальные страницы для каждого сотрудника
|
# 4. Персональные страницы сотрудников
|
||||||
for md_file in Path('content/staff').glob('*.md'):
|
for md_file in Path('content/staff').glob('*.md'):
|
||||||
with open(md_file, 'r', encoding='utf-8') as f:
|
with open(md_file, 'r', encoding='utf-8') as f:
|
||||||
meta, body = parse_front_matter(f.read())
|
meta, body = parse_front_matter(f.read())
|
||||||
|
|
||||||
name = meta.get('name', md_file.stem.replace('-', ' ').title())
|
name = meta.get('name', md_file.stem.replace('-', ' ').title())
|
||||||
|
|
||||||
# Добавляем ссылку "Назад к списку" в начало страницы
|
|
||||||
full_content = f'<a href="/staff.html" class="back-link">← Назад к списку сотрудников</a>\n{body}'
|
full_content = f'<a href="/staff.html" class="back-link">← Назад к списку сотрудников</a>\n{body}'
|
||||||
html_content = markdown.markdown(full_content, extensions=['fenced_code', 'tables'])
|
html_content = markdown.markdown(full_content, extensions=['fenced_code', 'tables'])
|
||||||
|
|
||||||
with open(Path(f'public/staff/{md_file.stem}.html'), 'w', encoding='utf-8') as f:
|
with open(Path(f'public/staff/{md_file.stem}.html'), 'w', encoding='utf-8') as f:
|
||||||
f.write(TEMPLATE.format(title=name, content=html_content))
|
f.write(TEMPLATE.format(title=name, content=html_content))
|
||||||
|
|
||||||
# 5. Копирование статических файлов (картинки)
|
# 5. Страница с публикациями (PDF-файлы)
|
||||||
|
pdf_files = sorted(Path('static/pdf').glob('*.pdf'))
|
||||||
|
if pdf_files:
|
||||||
|
pdf_list_html = "<h2>Научные публикации и документы</h2><ul class='pdf-list'>"
|
||||||
|
for pdf in pdf_files:
|
||||||
|
# Получаем название из имени файла или из метаданных (если есть)
|
||||||
|
title = pdf.stem.replace('-', ' ').replace('_', ' ').title()
|
||||||
|
size_mb = pdf.stat().st_size / (1024 * 1024)
|
||||||
|
pdf_list_html += f"""
|
||||||
|
<li>
|
||||||
|
<a href="/static/pdf/{pdf.name}" class="pdf-link" target="_blank">{title}</a>
|
||||||
|
<span style="color: #666; font-size: 0.9em;">({size_mb:.1f} MB)</span>
|
||||||
|
</li>"""
|
||||||
|
pdf_list_html += "</ul>"
|
||||||
|
|
||||||
|
with open('public/publications.html', 'w', encoding='utf-8') as f:
|
||||||
|
f.write(TEMPLATE.format(title="Публикации", content=pdf_list_html))
|
||||||
|
else:
|
||||||
|
# Если 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)
|
||||||
if Path('static').exists():
|
if Path('static').exists():
|
||||||
shutil.rmtree('public/static', ignore_errors=True)
|
shutil.rmtree('public/static', ignore_errors=True)
|
||||||
shutil.copytree('static', 'public/static')
|
shutil.copytree('static', 'public/static')
|
||||||
print("✅ Статические файлы скопированы")
|
print("✅ Статические файлы скопированы (включая PDF)")
|
||||||
|
|
||||||
print("✅ Сайт успешно собран! Сотрудники сгруппированы и кликабельны.")
|
print("✅ Сайт успешно собран!")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
Loading…
x
Reference in New Issue
Block a user