cms: Publizieren nimmt Beitrag automatisch aus Entwurf (draft:false)
Bisher blieb ein Beitrag mit gesetztem Entwurf-Haken beim Publizieren aus dem Live-Build ausgeschlossen → ging nie live. Jetzt setzt Publizieren draft:false, speichert (Haken verschwindet, Status → Veröffentlicht), dann baut es live. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+14
-12
@@ -170,23 +170,24 @@ function Editor({ initial, onSaved, onMsg }) {
|
|||||||
}, []);
|
}, []);
|
||||||
function startDrag(e) { dragging.current = true; document.body.style.cursor = 'col-resize'; document.body.style.userSelect = 'none'; e.preventDefault(); }
|
function startDrag(e) { dragging.current = true; document.body.style.cursor = 'col-resize'; document.body.style.userSelect = 'none'; e.preventDefault(); }
|
||||||
|
|
||||||
function currentPath() {
|
function currentPath(data = f) {
|
||||||
if (!f.isNew) return f.path;
|
if (!data.isNew) return data.path;
|
||||||
const slug = (f.slug || '').trim();
|
const slug = (data.slug || '').trim();
|
||||||
if (!slug) return '';
|
if (!slug) return '';
|
||||||
return f.type === 'beitrag' ? `library/${f.section}/${slug}.md` : `${slug}.md`;
|
return data.type === 'beitrag' ? `library/${data.section}/${slug}.md` : `${slug}.md`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function save() {
|
// overrides erlauben z.B. { draft: false } beim Publizieren.
|
||||||
const path = currentPath();
|
async function save(overrides = {}) {
|
||||||
|
const data = { ...f, ...overrides };
|
||||||
|
const path = currentPath(data);
|
||||||
if (!path) { onMsg({ type: 'err', text: 'Bitte einen Slug angeben.' }); return null; }
|
if (!path) { onMsg({ type: 'err', text: 'Bitte einen Slug angeben.' }); return null; }
|
||||||
if (!f.title.trim()) { onMsg({ type: 'err', text: 'Titel fehlt.' }); return null; }
|
if (!data.title.trim()) { onMsg({ type: 'err', text: 'Titel fehlt.' }); return null; }
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
try {
|
try {
|
||||||
await api.save(path, buildFrontmatter(f), f.body);
|
await api.save(path, buildFrontmatter(data), data.body);
|
||||||
const loaded = fromRead(await api.read(path));
|
const loaded = fromRead(await api.read(path));
|
||||||
onSaved(loaded); setF(loaded);
|
onSaved(loaded); setF(loaded);
|
||||||
onMsg({ type: 'ok', text: 'Gespeichert.' });
|
|
||||||
return path;
|
return path;
|
||||||
} catch (e) { onMsg({ type: 'err', text: e.message }); return null; }
|
} catch (e) { onMsg({ type: 'err', text: e.message }); return null; }
|
||||||
finally { setBusy(false); }
|
finally { setBusy(false); }
|
||||||
@@ -199,8 +200,9 @@ function Editor({ initial, onSaved, onMsg }) {
|
|||||||
finally { setBusy(false); }
|
finally { setBusy(false); }
|
||||||
}
|
}
|
||||||
async function publish() {
|
async function publish() {
|
||||||
const path = await save(); if (!path) return;
|
if (!confirm('Live publizieren? Der Beitrag wird aus „Entwurf“ genommen.')) return;
|
||||||
if (!confirm('Diesen Eintrag live publizieren?')) return;
|
const path = await save({ draft: false }); // Publizieren = nicht mehr Entwurf
|
||||||
|
if (!path) return;
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
try { const res = await api.publish(path); onMsg({ type: 'ok', text: `Live: ${res.url}` }); }
|
try { const res = await api.publish(path); onMsg({ type: 'ok', text: `Live: ${res.url}` }); }
|
||||||
catch (e) { onMsg({ type: 'err', text: e.message }); }
|
catch (e) { onMsg({ type: 'err', text: e.message }); }
|
||||||
@@ -217,7 +219,7 @@ function Editor({ initial, onSaved, onMsg }) {
|
|||||||
<button className="toggle" onClick={() => setShowPreview((v) => !v)} title="Vorschau ein/aus">
|
<button className="toggle" onClick={() => setShowPreview((v) => !v)} title="Vorschau ein/aus">
|
||||||
{showPreview ? 'Vorschau ⤫' : 'Vorschau ⤢'}
|
{showPreview ? 'Vorschau ⤫' : 'Vorschau ⤢'}
|
||||||
</button>
|
</button>
|
||||||
<button onClick={save} disabled={busy}>Speichern</button>
|
<button onClick={() => save().then((p) => p && onMsg({ type: 'ok', text: 'Gespeichert.' }))} disabled={busy}>Speichern</button>
|
||||||
<button onClick={preview} disabled={busy}>Vorschau</button>
|
<button onClick={preview} disabled={busy}>Vorschau</button>
|
||||||
<button className="primary" onClick={publish} disabled={busy}>Publizieren</button>
|
<button className="primary" onClick={publish} disabled={busy}>Publizieren</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user