fixed backend errors, added delete and more configuration
This commit is contained in:
@@ -12,46 +12,62 @@ import Layout from '../../layouts/Layout.astro';
|
||||
<h1 class="text-4xl font-extrabold text-mauve mt-4">
|
||||
Site Settings
|
||||
</h1>
|
||||
<p class="text-subtext1 mt-2">Configure how your blog looks and feels globally.</p>
|
||||
</header>
|
||||
|
||||
<form id="settings-form" class="space-y-6">
|
||||
<form id="settings-form" class="space-y-8">
|
||||
<div id="alert" class="hidden p-4 rounded-lg mb-6"></div>
|
||||
|
||||
<div>
|
||||
<label for="title" class="block text-sm font-medium text-subtext1 mb-2">Blog Title</label>
|
||||
<input
|
||||
type="text"
|
||||
id="title"
|
||||
required
|
||||
class="w-full bg-crust border border-surface1 rounded-lg px-4 py-3 text-text focus:outline-none focus:border-mauve transition-colors"
|
||||
/>
|
||||
</div>
|
||||
<section class="space-y-6">
|
||||
<h2 class="text-xl font-bold text-lavender border-l-4 border-lavender pl-4">General Identity</h2>
|
||||
<div class="grid md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label for="title" class="block text-sm font-medium text-subtext1 mb-2">Blog Title</label>
|
||||
<input type="text" id="title" required class="w-full bg-crust border border-surface1 rounded-lg px-4 py-3 text-text focus:outline-none focus:border-mauve transition-colors" />
|
||||
<p class="text-[10px] text-subtext0 mt-1">Main name of your blog.</p>
|
||||
</div>
|
||||
<div>
|
||||
<label for="subtitle" class="block text-sm font-medium text-subtext1 mb-2">Subtitle</label>
|
||||
<input type="text" id="subtitle" required class="w-full bg-crust border border-surface1 rounded-lg px-4 py-3 text-text focus:outline-none focus:border-mauve transition-colors" />
|
||||
<p class="text-[10px] text-subtext0 mt-1">Short description shown under the title.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label for="favicon" class="block text-sm font-medium text-subtext1 mb-2">Favicon URL</label>
|
||||
<input type="text" id="favicon" required class="w-full bg-crust border border-surface1 rounded-lg px-4 py-3 text-text focus:outline-none focus:border-mauve transition-colors" />
|
||||
<p class="text-[10px] text-subtext0 mt-1">URL to the icon shown in browser tabs.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div>
|
||||
<label for="favicon" class="block text-sm font-medium text-subtext1 mb-2">Favicon URL</label>
|
||||
<input
|
||||
type="text"
|
||||
id="favicon"
|
||||
required
|
||||
class="w-full bg-crust border border-surface1 rounded-lg px-4 py-3 text-text focus:outline-none focus:border-mauve transition-colors"
|
||||
/>
|
||||
</div>
|
||||
<section class="space-y-6">
|
||||
<h2 class="text-xl font-bold text-blue border-l-4 border-blue pl-4">Appearance</h2>
|
||||
<div>
|
||||
<label for="theme" class="block text-sm font-medium text-subtext1 mb-2">Color Theme (Catppuccin)</label>
|
||||
<select id="theme" class="w-full bg-crust border border-surface1 rounded-lg px-4 py-3 text-text focus:outline-none focus:border-mauve transition-colors">
|
||||
<option value="mocha">Mocha (Dark, High Contrast)</option>
|
||||
<option value="macchiato">Macchiato (Dark, Medium Contrast)</option>
|
||||
<option value="frappe">Frappe (Dark, Low Contrast)</option>
|
||||
<option value="latte">Latte (Light Mode)</option>
|
||||
</select>
|
||||
<p class="text-[10px] text-subtext0 mt-1">Select a predefined Catppuccin color palette.</p>
|
||||
</div>
|
||||
<div>
|
||||
<label for="custom_css" class="block text-sm font-medium text-subtext1 mb-2">Custom CSS</label>
|
||||
<textarea id="custom_css" rows="4" class="w-full bg-crust border border-surface1 rounded-lg px-4 py-3 text-text focus:outline-none focus:border-mauve transition-colors font-mono text-xs" placeholder="body { ... }"></textarea>
|
||||
<p class="text-[10px] text-subtext0 mt-1">Inject custom CSS styles globally.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div>
|
||||
<label for="theme" class="block text-sm font-medium text-subtext1 mb-2">Theme</label>
|
||||
<input
|
||||
type="text"
|
||||
id="theme"
|
||||
required
|
||||
class="w-full bg-crust border border-surface1 rounded-lg px-4 py-3 text-text focus:outline-none focus:border-mauve transition-colors"
|
||||
/>
|
||||
</div>
|
||||
<section class="space-y-6">
|
||||
<h2 class="text-xl font-bold text-teal border-l-4 border-teal pl-4">Footer</h2>
|
||||
<div>
|
||||
<label for="footer" class="block text-sm font-medium text-subtext1 mb-2">Footer Text</label>
|
||||
<input type="text" id="footer" required class="w-full bg-crust border border-surface1 rounded-lg px-4 py-3 text-text focus:outline-none focus:border-mauve transition-colors" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
class="bg-blue text-crust font-bold py-3 px-8 rounded-lg hover:bg-sky transition-colors"
|
||||
>
|
||||
Save Settings
|
||||
<button type="submit" class="w-full md:w-auto bg-mauve text-crust font-bold py-4 px-12 rounded-lg hover:bg-pink transition-all transform hover:scale-[1.02] active:scale-[0.98]">
|
||||
Save Site Configuration
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -71,11 +87,14 @@ import Layout from '../../layouts/Layout.astro';
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
(document.getElementById('title') as HTMLInputElement).value = data.title || '';
|
||||
(document.getElementById('subtitle') as HTMLInputElement).value = data.subtitle || '';
|
||||
(document.getElementById('footer') as HTMLInputElement).value = data.footer || '';
|
||||
(document.getElementById('favicon') as HTMLInputElement).value = data.favicon || '';
|
||||
(document.getElementById('theme') as HTMLInputElement).value = data.theme || '';
|
||||
(document.getElementById('theme') as HTMLSelectElement).value = data.theme || 'mocha';
|
||||
(document.getElementById('custom_css') as HTMLTextAreaElement).value = data.custom_css || '';
|
||||
}
|
||||
} catch (e) {
|
||||
showAlert('Failed to load settings.', 'error');
|
||||
showAlert('Failed to load settings from server.', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,11 +102,15 @@ import Layout from '../../layouts/Layout.astro';
|
||||
e.preventDefault();
|
||||
const payload = {
|
||||
title: (document.getElementById('title') as HTMLInputElement).value,
|
||||
subtitle: (document.getElementById('subtitle') as HTMLInputElement).value,
|
||||
footer: (document.getElementById('footer') as HTMLInputElement).value,
|
||||
favicon: (document.getElementById('favicon') as HTMLInputElement).value,
|
||||
theme: (document.getElementById('theme') as HTMLInputElement).value,
|
||||
theme: (document.getElementById('theme') as HTMLSelectElement).value,
|
||||
custom_css: (document.getElementById('custom_css') as HTMLTextAreaElement).value,
|
||||
};
|
||||
|
||||
try {
|
||||
// Now using relative path which will be proxied
|
||||
const res = await fetch('/api/config', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -98,13 +121,13 @@ import Layout from '../../layouts/Layout.astro';
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
showAlert('Settings saved successfully!', 'success');
|
||||
showAlert('Settings saved successfully! Refresh to see changes.', 'success');
|
||||
} else {
|
||||
const err = await res.json();
|
||||
showAlert(`Error: ${err.error}`, 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
showAlert('Failed to save settings.', 'error');
|
||||
showAlert('Failed to save settings. Please check your connection.', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -114,6 +137,7 @@ import Layout from '../../layouts/Layout.astro';
|
||||
alertEl.textContent = msg;
|
||||
alertEl.className = `p-4 rounded-lg mb-6 ${type === 'success' ? 'bg-green/20 text-green border border-green/30' : 'bg-red/20 text-red border border-red/30'}`;
|
||||
alertEl.classList.remove('hidden');
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user