fixed invalid post title breaking links

This commit is contained in:
2026-05-09 05:59:56 +02:00
parent bd18b96846
commit 801df057e0
6 changed files with 23 additions and 16 deletions
@@ -78,7 +78,7 @@ export default function Dashboard() {
<p className="text-xs text-subtext0" style={{ color: 'var(--subtext0)' }}>/posts/{post.slug}</p>
</div>
<div className="flex gap-3">
<a href={`/admin/editor?edit=${post.slug}`} className="p-2 text-blue hover:bg-blue/10 rounded transition-colors" title="Edit">
<a href={`/admin/editor?edit=${encodeURIComponent(post.slug)}`} className="p-2 text-blue hover:bg-blue/10 rounded transition-colors" title="Edit">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg>
</a>
<button onClick={() => handleDelete(post.slug)} className="p-2 text-red hover:bg-red/10 rounded transition-colors" title="Delete">
@@ -218,7 +218,7 @@ export default function Editor({ editSlug }: Props) {
.map(t => t.trim())
.filter(Boolean);
try {
await savePost({
const saved = await savePost({
slug,
old_slug: originalSlug || null,
date,
@@ -228,7 +228,8 @@ export default function Editor({ editSlug }: Props) {
content,
});
showAlertMsg('Post saved!', 'success');
setOriginalSlug(slug);
if (saved?.slug && saved.slug !== slug) setSlug(saved.slug);
setOriginalSlug(saved?.slug ?? slug);
} catch (e) {
showAlertMsg(e instanceof ApiError ? `Error: ${e.message}` : 'Failed to connect to server.', 'error');
}
@@ -274,7 +275,7 @@ export default function Editor({ editSlug }: Props) {
</button>
{originalSlug && (
<a
href={`/posts/${originalSlug}`}
href={`/posts/${encodeURIComponent(originalSlug)}`}
target="_blank"
rel="noreferrer"
className="bg-blue text-crust font-bold py-3 px-8 rounded-lg hover:bg-sky transition-all transform hover:scale-105 whitespace-nowrap inline-flex items-center justify-center gap-2"