refactor: update templates for new frontend structure

- Extract inline JavaScript from index.templ
- Replace with external script include for theme.js
- All templates reference /static/ for assets
- Cleaner separation of concerns between markup and logic
This commit is contained in:
2026-01-29 14:09:29 -05:00
parent 16cb9bd89a
commit b887c38abf
7 changed files with 8 additions and 53 deletions
+2 -53
View File
@@ -8,6 +8,7 @@ templ Index(loggedIn bool) {
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bookmann - Home</title>
<script src="/static/htmx.min.js"></script>
<script src="/static/toast.js"></script>
<link href="/static/style.css" rel="stylesheet">
<style>
:root {
@@ -238,59 +239,7 @@ templ Index(loggedIn bool) {
</div>
}
<script>
function applyTheme(theme) {
document.body.className = `theme-${theme}`;
localStorage.setItem('theme', theme);
}
function loadTheme() {
const theme = localStorage.getItem('theme') || 'tokyo-night';
applyTheme(theme);
}
function changeTheme() {
const theme = document.getElementById('theme-select').value;
applyTheme(theme);
// Save to server if logged in
fetch('/api/auth/theme', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.getItem('token')
},
body: JSON.stringify({ theme })
}).catch(err => console.log('Theme save failed', err));
}
function loadUserTheme() {
// If logged in, load from profile
const token = localStorage.getItem('token');
if (token) {
fetch('/api/auth/profile', {
headers: { 'Authorization': 'Bearer ' + token }
}).then(res => res.json()).then(data => {
if (data.theme) applyTheme(data.theme);
}).catch(() => {});
}
}
document.addEventListener('DOMContentLoaded', () => {
loadTheme();
loadUserTheme();
document.getElementById('theme-select').value = localStorage.getItem('theme') || 'tokyo-night';
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
});
</script>
<script src="/static/theme.js"></script>
</body>
</html>
}