|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Simple template updater for LIM Lab website. |
| 4 | +This script helps maintain consistency across all pages. |
| 5 | +""" |
| 6 | + |
| 7 | +import os |
| 8 | +import re |
| 9 | + |
| 10 | +# Common header template |
| 11 | +HEADER_TEMPLATE = ''' <header class="site-header"> |
| 12 | + <div class="header-container"> |
| 13 | + <div class="brand"> |
| 14 | + <div class="logo-container"> |
| 15 | + <div class="logo-text"> |
| 16 | + <div class="logo-main">IM</div> |
| 17 | + <div class="logo-sub">Lab</div> |
| 18 | + </div> |
| 19 | + <div class="logo-full">Learning Inference Memory</div> |
| 20 | + </div> |
| 21 | + </div> |
| 22 | + <nav class="nav"> |
| 23 | + <a href="/">HOME</a> |
| 24 | + <a href="/research">RESEARCH</a> |
| 25 | + <a href="/people">PEOPLE</a> |
| 26 | + <a href="/publications">PUBLICATIONS</a> |
| 27 | + <a href="/labnews">LAB NEWS</a> |
| 28 | + <a href="/join">JOIN</a> |
| 29 | + </nav> |
| 30 | + </div> |
| 31 | + </header>''' |
| 32 | + |
| 33 | +# Common footer template |
| 34 | +FOOTER_TEMPLATE = ''' <footer class="site-footer"> |
| 35 | + <div class="footer-content"> |
| 36 | + <div class="footer-brand">LIM Lab</div> |
| 37 | + <div class="footer-logos"> |
| 38 | + <a href="https://www.ucl.ac.uk/swc" target="_blank" rel="noreferrer"> |
| 39 | + <img src="https://www.sainsburywellcome.org/sites/default/files/2021-05/swc-logo.png" alt="Sainsbury Wellcome Centre logo"> |
| 40 | + </a> |
| 41 | + <a href="https://www.ucl.ac.uk" target="_blank" rel="noreferrer"> |
| 42 | + <img src="https://www.ucl.ac.uk/sites/default/files/ucl-logo.png" alt="UCL logo"> |
| 43 | + </a> |
| 44 | + </div> |
| 45 | + </div> |
| 46 | + </footer>''' |
| 47 | + |
| 48 | +def update_page(page_path, active_nav): |
| 49 | + """Update a single page with the common template.""" |
| 50 | + with open(page_path, 'r', encoding='utf-8') as f: |
| 51 | + content = f.read() |
| 52 | + |
| 53 | + # Replace header |
| 54 | + header_pattern = r'<header class="site-header">.*?</header>' |
| 55 | + content = re.sub(header_pattern, HEADER_TEMPLATE, content, flags=re.DOTALL) |
| 56 | + |
| 57 | + # Replace footer |
| 58 | + footer_pattern = r'<footer class="site-footer">.*?</footer>' |
| 59 | + content = re.sub(footer_pattern, FOOTER_TEMPLATE, content, flags=re.DOTALL) |
| 60 | + |
| 61 | + # Set active navigation |
| 62 | + if active_nav: |
| 63 | + content = content.replace(f'href="{active_nav}"', f'href="{active_nav}" class="active"') |
| 64 | + |
| 65 | + with open(page_path, 'w', encoding='utf-8') as f: |
| 66 | + f.write(content) |
| 67 | + |
| 68 | + print(f"Updated {page_path}") |
| 69 | + |
| 70 | +def main(): |
| 71 | + """Update all pages with the common template.""" |
| 72 | + pages = [ |
| 73 | + ('index.html', '/'), |
| 74 | + ('research.html', '/research'), |
| 75 | + ('people.html', '/people'), |
| 76 | + ('publications.html', '/publications'), |
| 77 | + ('labnews.html', '/labnews'), |
| 78 | + ('join.html', '/join'), |
| 79 | + ] |
| 80 | + |
| 81 | + for page_path, active_nav in pages: |
| 82 | + if os.path.exists(page_path): |
| 83 | + update_page(page_path, active_nav) |
| 84 | + else: |
| 85 | + print(f"Warning: {page_path} not found") |
| 86 | + |
| 87 | +if __name__ == "__main__": |
| 88 | + main() |
0 commit comments