작품 파일명 연-월-제목 + 작품별 이미지 폴더(assets/img/<slug>/)

This commit is contained in:
koreafood committed 2026-10-31 11:18:55 +09:00
1 parent 4dff91b483
commit 767b2a30a3
19 files changed
+163 -40

No files matched your search

+7 -4
View File
@@ -391,7 +391,7 @@ function fieldHtml(f, value) {
'<span class="img-line"><input type="text" id="' + id + '" data-key="' + f.key + '" value="' + esc(value) + '">' +
'<img class="img-preview" id="' + id + '_prev" src="' + (value ? '/media/' + encodeURI(value) : '') + '" alt="">' +
'<button type="button" class="ghost" id="' + id + '_pick">올리기</button></span>' +
'<span class="drop-hint" id="' + id + '_hint">JPG를 여기로 끌어다 놓아도 됩니다 (assets/img 에 저장)</span></label>';
'<span class="drop-hint" id="' + id + '_hint">JPG를 끌어다 놓으면 assets/img/&lt;슬러그&gt;/ 에 저장됩니다</span></label>';
}
const type = f.type === 'number' ? 'number' : (f.type === 'date' ? 'date' : (f.type === 'url' ? 'url' : 'text'));
return '<label class="field' + wide + '"><span class="lbl">' + esc(f.label) + '</span>' +
@@ -403,8 +403,8 @@ function renderEditor(p) {
const isDraft = !!p.draft;
if (isDraft) state.current = null;
const slugField = isDraft
? '<label class="field wide"><span class="lbl">슬러그 (주소·파일명, 영문 소문자·하이픈)</span>' +
'<input type="text" id="f_slug" value="' + esc(p.slug || '') + '" placeholder="예: magnolia-tea-mat"></label>'
? '<label class="field wide"><span class="lbl">슬러그 · 파일명 (연-월-제목, 영문 소문자)</span>' +
'<input type="text" id="f_slug" value="' + esc(p.slug || '') + '" placeholder="예: 2026-11-magnolia-tea-mat"></label>'
: '';
const grid = slugField + state.fields.map((f) => fieldHtml(f, values[f.key])).join('');
const extraKeys = p.extra_keys || [];
@@ -455,8 +455,11 @@ function pickImage(target) {
}
async function uploadImage(file, target) {
const slugEl = $('f_slug');
const slug = (slugEl ? slugEl.value.trim() : '') || state.current || '';
if (!slug) { toast('슬러그를 먼저 정해야 이미지를 넣을 수 있습니다', 'err'); return; }
$('state').textContent = '이미지 올리는 중…';
const res = await fetch('/api/upload?name=' + encodeURIComponent(file.name), {
const res = await fetch('/api/upload?name=' + encodeURIComponent(file.name) + '&slug=' + encodeURIComponent(slug), {
method: 'POST', headers: { 'Content-Type': 'application/octet-stream' }, body: file,
});
const data = await res.json().catch(() => ({ ok: false, error: '업로드 실패' }));