fixed code highlight
This commit is contained in:
@@ -35,6 +35,16 @@ import AdminLayout from '../../layouts/AdminLayout.astro';
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="summary" class="block text-sm font-medium text-subtext1 mb-2">Custom Summary (Optional)</label>
|
||||
<textarea
|
||||
id="summary"
|
||||
rows="2"
|
||||
placeholder="A brief description of this post for the frontpage..."
|
||||
class="w-full bg-crust border border-surface1 rounded-lg px-4 py-3 text-text focus:outline-none focus:border-mauve transition-colors resize-none"
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<div class="relative">
|
||||
<div class="flex flex-col md:flex-row justify-between items-start md:items-end mb-2 gap-2">
|
||||
<label for="content" class="block text-sm font-medium text-subtext1 italic">Tip: Type '/' to browse your assets</label>
|
||||
@@ -108,6 +118,7 @@ import AdminLayout from '../../layouts/AdminLayout.astro';
|
||||
const token = e.detail.token;
|
||||
|
||||
const slugInput = document.getElementById('slug') as HTMLInputElement;
|
||||
const summaryInput = document.getElementById('summary') as HTMLTextAreaElement;
|
||||
const contentInput = document.getElementById('content') as HTMLTextAreaElement;
|
||||
const fileInput = document.getElementById('file-upload') as HTMLInputElement;
|
||||
const saveBtn = document.getElementById('save-btn');
|
||||
@@ -267,8 +278,8 @@ import AdminLayout from '../../layouts/AdminLayout.astro';
|
||||
}
|
||||
});
|
||||
|
||||
fileInput?.addEventListener('change', async (e) => {
|
||||
const file = (e.target as HTMLInputElement).files?.[0];
|
||||
fileInput?.addEventListener('change', async (ev) => {
|
||||
const file = (ev.target as HTMLInputElement).files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
const formData = new FormData();
|
||||
@@ -289,14 +300,18 @@ import AdminLayout from '../../layouts/AdminLayout.astro';
|
||||
const err = await res.json();
|
||||
showAlert(`Upload failed: ${err.error}`, 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (err) {
|
||||
showAlert('Network error during upload.', 'error');
|
||||
}
|
||||
fileInput.value = '';
|
||||
});
|
||||
|
||||
saveBtn?.addEventListener('click', async () => {
|
||||
const payload = { slug: slugInput.value, content: editor.getValue() };
|
||||
const payload = {
|
||||
slug: slugInput.value,
|
||||
summary: summaryInput.value || null,
|
||||
content: editor.getValue()
|
||||
};
|
||||
if (!payload.slug || !payload.content) {
|
||||
showAlert('Slug and content are required.', 'error');
|
||||
return;
|
||||
@@ -312,7 +327,7 @@ import AdminLayout from '../../layouts/AdminLayout.astro';
|
||||
});
|
||||
if (res.ok) showAlert('Post saved!', 'success');
|
||||
else showAlert('Error saving post.', 'error');
|
||||
} catch (e) {
|
||||
} catch (err) {
|
||||
showAlert('Failed to connect to server.', 'error');
|
||||
}
|
||||
});
|
||||
@@ -326,7 +341,7 @@ import AdminLayout from '../../layouts/AdminLayout.astro';
|
||||
});
|
||||
if (res.ok) window.location.href = '/admin';
|
||||
else showAlert('Error deleting post.', 'error');
|
||||
} catch (e) {
|
||||
} catch (err) {
|
||||
showAlert('Connection error.', 'error');
|
||||
}
|
||||
}
|
||||
@@ -341,6 +356,9 @@ import AdminLayout from '../../layouts/AdminLayout.astro';
|
||||
fetch(`/api/posts/${encodeURIComponent(editSlug)}`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.summary) {
|
||||
summaryInput.value = data.summary;
|
||||
}
|
||||
if (data.content) {
|
||||
editor.setValue(data.content);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user