Compare commits

...

2 Commits

Author SHA1 Message Date
Wesley R. Elsberry 9b6aea946a Add theme, templates, docs, license 2025-10-15 02:49:05 -04:00
Wesley R. Elsberry 6648269557 Initial scripts/ files 2025-10-15 00:42:12 -04:00
10 changed files with 341 additions and 6 deletions

View File

@ -1,9 +1,5 @@
MIT License
Copyright (c) 2025 welsberr
Copyright (c) 2024 evo-edu.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Permission is hereby granted... [standard MIT text]

19
docs/USAGE.md Normal file
View File

@ -0,0 +1,19 @@
# Using the evo-edu Framework
## 1. Copy Theme Files
Copy `/theme/` into your sites root.
## 2. Create Pages
Use `base.html` as a template. Replace `{{ }}` placeholders with actual content.
## 3. Add Dynamic Behavior (Optional)
Include `/theme/main.js` for:
- Year auto-update
- Language switching
## 4. Customize Styling
Edit `style.css` to match your projects visual identity.
## 5. Multilingual Support
- Organize content under `/en/`, `/es/`, etc.
- Update language switcher options in `base.html`

31
scripts/README.md Normal file
View File

@ -0,0 +1,31 @@
# SciSiteForge Scripts
## 🛠️ Build & Translate
This site framework supports offline multilingual translation using Llamafile.
### Prerequisites
- Download a multilingual GGUF model (e.g., `mistral-7b-instruct.Q5_K_M.gguf`)
- Install [Llamafile](https://github.com/Mozilla-Ocho/llamafile)
- Python 3 with `requests` and `beautifulsoup4`
### Steps
1. Launch Llamafile:
```bash
./mistral-7b-instruct.Q5_K_M.llamafile --port 8080
```
2. Run translation:
```bash
python scripts/translate_site.py --langs es,fr
```
3. Commit translated content:
```bash
git add es/ fr/
```
> Translated files are saved to `/es/`, `/fr/`, etc., and served alongside English content.
```
#### 📁 `example/content/scripts/glossary_es.json`
→ Language-specific scientific term mappings

6
scripts/glossary_es.json Normal file
View File

@ -0,0 +1,6 @@
{
"genetic drift": "deriva genética",
"natural selection": "selección natural",
"punctuated equilibrium": "equilibrio puntuado",
"allele": "alelo"
}

119
scripts/translate_site.py Normal file
View File

@ -0,0 +1,119 @@
#!/usr/bin/env python3
"""
Offline multilingual translation for evo-edu.org using Llamafile.
Requires: BeautifulSoup4, requests
Install with: pip install beautifulsoup4 requests
"""
import os
import json
import argparse
import time
from pathlib import Path
from bs4 import BeautifulSoup, NavigableString
import requests
# --- Configuration ---
MODEL_API_URL = "http://localhost:8080/completion"
LANGUAGES = {
"es": "Spanish",
"fr": "French",
"pt": "Portuguese",
"de": "German"
}
def translate_text(text, target_lang_name, glossary=None):
"""Translate a block of text using Llamafile."""
if not text.strip():
return text
glossary_text = ""
if glossary:
glossary_text = "Use these translations:\n" + "\n".join(f"'{k}' → '{v}'" for k, v in glossary.items()) + "\n\n"
prompt = f"""You are a scientific translator. Translate the following English text into {target_lang_name}.
Preserve technical terms like "genetic drift" or "natural selection" unless a standard translation exists.
Maintain paragraph structure. Do not add commentary.
{glossary_text}Text:
"{text}"
Translation:"""
try:
response = requests.post(MODEL_API_URL, json={
"prompt": prompt,
"temperature": 0.1,
"stop": ["\n\n", "Text:", "Translation:"],
"n_predict": 1024
}, timeout=120)
response.raise_for_status()
result = response.json()["content"].strip()
return result
except Exception as e:
print(f" âš ï¸ Translation failed: {e}")
return text # fallback to original
def extract_translatable_text(soup):
"""Extract text nodes for translation, preserving structure."""
texts = []
for elem in soup.descendants:
if isinstance(elem, NavigableString) and elem.parent.name not in ['script', 'style']:
if elem.strip():
texts.append(elem)
return texts
def translate_html_file(src_path, dest_path, target_lang_code):
"""Translate an HTML file."""
print(f"Translating {src_path} → {dest_path}")
with open(src_path, 'r', encoding='utf-8') as f:
html = f.read()
soup = BeautifulSoup(html, 'html.parser')
text_nodes = extract_translatable_text(soup)
# Optional: load glossary for this language
glossary = {}
glossary_path = Path(__file__).parent / f"glossary_{target_lang_code}.json"
if glossary_path.exists():
with open(glossary_path, 'r') as f:
glossary = json.load(f)
# Translate each text node
for node in text_nodes:
original = str(node)
translated = translate_text(original, LANGUAGES[target_lang_code], glossary)
node.replace_with(translated)
time.sleep(0.1) # be gentle on CPU
# Save translated HTML
dest_path.parent.mkdir(parents=True, exist_ok=True)
with open(dest_path, 'w', encoding='utf-8') as f:
f.write(str(soup))
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--langs", required=True, help="Comma-separated language codes (e.g., es,fr)")
parser.add_argument("--src", default="content/en", help="Source directory (English)")
parser.add_argument("--dest", default="content", help="Base destination directory")
args = parser.parse_args()
lang_codes = args.langs.split(',')
src_base = Path(args.src)
dest_base = Path(args.dest)
for lang_code in lang_codes:
if lang_code not in LANGUAGES:
print(f"Unsupported language: {lang_code}")
continue
print(f"\n=== Translating to {LANGUAGES[lang_code]} ({lang_code}) ===")
for html_file in src_base.rglob("*.html"):
rel_path = html_file.relative_to(src_base)
dest_file = dest_base / lang_code / rel_path
translate_html_file(html_file, dest_file, lang_code)
print("\n✅ Translation complete.")
if __name__ == "__main__":
main()

5
templates/app-card.html Normal file
View File

@ -0,0 +1,5 @@
<article class="card">
<h3>{{ app_title }}</h3>
<p>{{ app_description }}</p>
<a href="/{{ lang }}/apps/{{ app_slug }}/" class="btn">Launch App</a>
</article>

View File

@ -0,0 +1,7 @@
<div class="section-card">
<h3>{{ section_title }}</h3>
<p class="meta">{{ section_meta }}</p>
<p class="excerpt">{{ section_excerpt }}</p>
<button class="expand-btn" data-src="/{{ lang }}/notebook/{{ section_path }}">Show</button>
<div class="content"></div>
</div>

49
theme/base.html Normal file
View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="{{ lang }}">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>{{ title }} — {{ site_title }}</title>
<link rel="stylesheet" href="/theme/style.css">
</head>
<body>
<header>
<div class="container">
<a href="/{{ lang }}/">{{ site_title }}</a>
<div style="display:flex;align-items:center;gap:1rem;">
<nav>
<ul>
<li><a href="/{{ lang }}/">Home</a></li>
<li><a href="/{{ lang }}/apps/">Apps</a></li>
<li><a href="/{{ lang }}/notebook/">Notebook</a></li>
<li><a href="/{{ lang }}/resources/">Resources</a></li>
</ul>
</nav>
<select id="lang-switch" onchange="switchLanguage(this.value)">
{{#each languages}}
<option value="{{code}}" {{#if (eq code ../lang)}}selected{{/if}}>{{name}}</option>
{{/each}}
</select>
</div>
</div>
</header>
<main class="container">
{{> content }}
</main>
<footer>
<div class="container">
<p>&copy; <span id="year">2024</span> {{ site_title }}. {{ license }}</p>
<p>
<a href="{{ github_url }}">GitHub</a>
<a href="mailto:{{ contact_email }}">Contact</a>
<a href="/{{ lang }}/disclaimer/">Disclaimer</a>
</p>
</div>
</footer>
<script src="/theme/main.js"></script>
</body>
</html>

15
theme/main.js Normal file
View File

@ -0,0 +1,15 @@
// Auto-update year
document.getElementById('year')?.textContent = new Date().getFullYear();
// Language switcher
function switchLanguage(lang) {
const currentPath = window.location.pathname;
let newPath = currentPath.replace(new RegExp(`^/${window.langCode}/|^/`), `/${lang}/`);
if (!currentPath.startsWith(`/${lang}/`)) {
newPath = `/${lang}${currentPath}`;
}
window.location.href = newPath;
}
// Optional: expose langCode for JS logic
window.langCode = document.documentElement.lang || 'en';

88
theme/style.css Normal file
View File

@ -0,0 +1,88 @@
:root {
--primary: #2c6fbb;
--light: #f8f9fa;
--dark: #212529;
--gray: #6c757d;
--border: #dee2e6;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
line-height: 1.6;
color: var(--dark);
background-color: #fff;
}
.container {
width: 100%;
max-width: 960px;
margin: 0 auto;
padding: 0 1rem;
}
header {
background-color: var(--primary);
color: white;
padding: 1rem 0;
}
header .container {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 1rem;
}
header a { color: white; text-decoration: none; font-weight: bold; }
nav ul {
display: flex;
list-style: none;
gap: 1.5rem;
margin: 0;
padding: 0;
}
nav a { color: white; text-decoration: none; }
main { padding: 2rem 0; }
footer {
background-color: var(--light);
color: var(--gray);
padding: 1.5rem 0;
border-top: 1px solid var(--border);
font-size: 0.9rem;
}
h1, h2, h3 { margin: 1.5rem 0 1rem; }
.card {
background: var(--light);
padding: 1.25rem;
border-radius: 8px;
margin-bottom: 1rem;
border: 1px solid var(--border);
}
.btn {
display: inline-block;
background-color: var(--primary);
color: white;
padding: 0.5rem 1rem;
text-decoration: none;
border-radius: 4px;
font-weight: bold;
margin-top: 0.5rem;
}
.btn:hover { background-color: #1e5aa8; }
.topic { margin-bottom: 2.5rem; }
.cards-grid {
display: flex;
flex-direction: column;
gap: 1rem;
}
#lang-switch {
background: white;
color: var(--primary);
border: 1px solid white;
border-radius: 4px;
padding: 0.25rem 0.5rem;
font-weight: bold;
}
@media (min-width: 768px) {
.cards-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
}
}