Обновить build.py
This commit is contained in:
parent
4ab60a6622
commit
740c6afe4a
36
build.py
36
build.py
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import markdown
|
import markdown
|
||||||
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
TEMPLATE = """<!DOCTYPE html>
|
TEMPLATE = """<!DOCTYPE html>
|
||||||
@ -22,7 +23,11 @@ TEMPLATE = """<!DOCTYPE html>
|
|||||||
nav a:hover {{ text-decoration: underline; }}
|
nav a:hover {{ text-decoration: underline; }}
|
||||||
.person {{ margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px dashed #ddd; }}
|
.person {{ margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px dashed #ddd; }}
|
||||||
.person-name {{ font-weight: bold; font-size: 1.1em; color: #222; }}
|
.person-name {{ font-weight: bold; font-size: 1.1em; color: #222; }}
|
||||||
|
.person-name a {{ color: #003366; text-decoration: none; }}
|
||||||
|
.person-name a:hover {{ text-decoration: underline; }}
|
||||||
.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:hover {{ text-decoration: underline; }}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -81,7 +86,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 = []
|
||||||
|
|
||||||
@ -99,7 +104,11 @@ 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"><div class="person-name">{name}</div><div class="person-details">{details_str}</div></div>'
|
# Создаем ссылку на персональную страницу
|
||||||
|
person_html = f'''<div class="person">
|
||||||
|
<div class="person-name"><a href="staff/{md_file.stem}.html">{name}</a></div>
|
||||||
|
<div class="person-details">{details_str}</div>
|
||||||
|
</div>'''
|
||||||
|
|
||||||
if lab == 'Без подразделения' or not lab:
|
if lab == 'Без подразделения' or not lab:
|
||||||
unassigned.append(person_html)
|
unassigned.append(person_html)
|
||||||
@ -111,7 +120,6 @@ def main():
|
|||||||
# Формируем HTML для страницы сотрудников
|
# Формируем HTML для страницы сотрудников
|
||||||
staff_html = "<h2>Наши сотрудники</h2>"
|
staff_html = "<h2>Наши сотрудники</h2>"
|
||||||
|
|
||||||
# Сначала лаборатории в заданном порядке (можно отсортировать)
|
|
||||||
lab_order = [
|
lab_order = [
|
||||||
"Лаборатория математики и телекоммуникаций",
|
"Лаборатория математики и телекоммуникаций",
|
||||||
"Лаборатория теоретической и вычислительной физики",
|
"Лаборатория теоретической и вычислительной физики",
|
||||||
@ -124,7 +132,6 @@ def main():
|
|||||||
for p in staff_by_lab[lab]:
|
for p in staff_by_lab[lab]:
|
||||||
staff_html += p
|
staff_html += p
|
||||||
|
|
||||||
# Остальные лаборатории (если появятся новые)
|
|
||||||
for lab, people in staff_by_lab.items():
|
for lab, people in staff_by_lab.items():
|
||||||
if lab not in lab_order:
|
if lab not in lab_order:
|
||||||
staff_html += f"<h3>{lab}</h3>"
|
staff_html += f"<h3>{lab}</h3>"
|
||||||
@ -139,18 +146,27 @@ 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. Создаем индивидуальные страницы для каждого сотрудника
|
||||||
for md_file in Path('content/staff').glob('*.md'):
|
for md_file in Path('content/staff').glob('*.md'):
|
||||||
build_page(md_file, Path(f'public/staff/{md_file.stem}.html'), meta.get('name', md_file.stem))
|
with open(md_file, 'r', encoding='utf-8') as f:
|
||||||
|
meta, body = parse_front_matter(f.read())
|
||||||
|
|
||||||
# 4. Копирование статических файлов (картинки, CSS и т.д.)
|
name = meta.get('name', md_file.stem.replace('-', ' ').title())
|
||||||
|
|
||||||
|
# Добавляем ссылку "Назад к списку" в начало страницы
|
||||||
|
full_content = f'<a href="/staff.html" class="back-link">← Назад к списку сотрудников</a>\n{body}'
|
||||||
|
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:
|
||||||
|
f.write(TEMPLATE.format(title=name, content=html_content))
|
||||||
|
|
||||||
|
# 5. Копирование статических файлов (картинки)
|
||||||
if Path('static').exists():
|
if Path('static').exists():
|
||||||
import shutil
|
|
||||||
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("✅ Статические файлы скопированы")
|
||||||
|
|
||||||
print("✅ Сайт успешно собран! Сотрудники сгруппированы.")
|
print("✅ Сайт успешно собран! Сотрудники сгруппированы и кликабельны.")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
Loading…
x
Reference in New Issue
Block a user