diff --git a/frontend/src/components/PostCard.astro b/frontend/src/components/PostCard.astro index f0ebba6..42d886b 100644 --- a/frontend/src/components/PostCard.astro +++ b/frontend/src/components/PostCard.astro @@ -14,7 +14,7 @@ const { slug, excerpt, formatSlug } = Astro.props;
+
{excerpt || `Read more about ${formatSlug(slug)}...`}
diff --git a/frontend/src/layouts/AdminLayout.astro b/frontend/src/layouts/AdminLayout.astro index eada2e3..546efc4 100644 --- a/frontend/src/layouts/AdminLayout.astro +++ b/frontend/src/layouts/AdminLayout.astro @@ -9,12 +9,18 @@ const { title } = Astro.props; ---Create a new masterpiece.
@@ -123,6 +128,7 @@ import AdminLayout from '../../layouts/AdminLayout.astro'; const fileInput = document.getElementById('file-upload') as HTMLInputElement; const saveBtn = document.getElementById('save-btn'); const delBtn = document.getElementById('delete-btn'); + const viewPostBtn = document.getElementById('view-post-btn') as HTMLAnchorElement; const browseBtn = document.getElementById('browse-btn'); const assetsModal = document.getElementById('assets-modal'); const closeModal = document.getElementById('close-modal'); @@ -150,8 +156,8 @@ import AdminLayout from '../../layouts/AdminLayout.astro'; if (res.ok) { allAssets = await res.json(); } - } catch (e) { - console.error("Failed to fetch assets", e); + } catch (err) { + console.error("Failed to fetch assets", err); } } @@ -272,8 +278,8 @@ import AdminLayout from '../../layouts/AdminLayout.astro'; autocomplete?.classList.add('hidden'); } - window.addEventListener('click', (e) => { - if (!autocomplete?.contains(e.target as Node)) { + window.addEventListener('click', (ev) => { + if (!autocomplete?.contains(ev.target as Node)) { hideAutocomplete(); } }); @@ -325,8 +331,16 @@ import AdminLayout from '../../layouts/AdminLayout.astro'; }, body: JSON.stringify(payload) }); - if (res.ok) showAlert('Post saved!', 'success'); - else showAlert('Error saving post.', 'error'); + if (res.ok) { + showAlert('Post saved!', 'success'); + if (viewPostBtn) { + viewPostBtn.href = `/posts/${payload.slug}`; + viewPostBtn.classList.remove('hidden'); + viewPostBtn.classList.add('inline-flex'); + } + } else { + showAlert('Error saving post.', 'error'); + } } catch (err) { showAlert('Failed to connect to server.', 'error'); } @@ -353,6 +367,13 @@ import AdminLayout from '../../layouts/AdminLayout.astro'; slugInput.value = editSlug; slugInput.disabled = true; // Protect slug on edit delBtn?.classList.remove('hidden'); + + if (viewPostBtn) { + viewPostBtn.href = `/posts/${editSlug}`; + viewPostBtn.classList.remove('hidden'); + viewPostBtn.classList.add('inline-flex'); + } + fetch(`/api/posts/${encodeURIComponent(editSlug)}`) .then(res => res.json()) .then(data => { diff --git a/frontend/src/pages/posts/[slug].astro b/frontend/src/pages/posts/[slug].astro index ae3230a..3e99f2f 100644 --- a/frontend/src/pages/posts/[slug].astro +++ b/frontend/src/pages/posts/[slug].astro @@ -42,7 +42,7 @@ function formatSlug(slug: string) {