Update documentation system: improve structure, search, and editor

This commit is contained in:
dev
2026-11-01 14:44:05 +03:00
parent 9a509fa742
commit 773e092253
6 changed files with 40 additions and 30 deletions
+1
View File
@@ -204,6 +204,7 @@
.docs-imglib-item:hover { border-color: var(--accent); }
.docs-imglib-item img { width: 100%; height: 90px; object-fit: cover; border-radius: 6px; display: block; }
.docs-imglib-name { font-size: .72rem; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docs-imglib-caption { font-size: .68rem; color: var(--text); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docs-caption-row { display: flex; gap: 4px; margin-top: 4px; }
.docs-caption-input { flex: 1; font-size: .75rem; padding: 3px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.docs-caption-row button { padding: 3px 8px; font-size: .75rem; }
+8 -5
View File
@@ -189,7 +189,7 @@
<div class="docs-body">${WhatIDoMD.render(article.body)}</div>
${(article.files && article.files.length) ? `<div class="docs-attachments">
<div class="docs-attachments-title">Вложения</div>
<ul class="docs-attachments-list">${article.files.map(f => `<li><a href="${esc(f.path)}" target="_blank" rel="noopener">${esc(f.name)}</a> <span class="docs-attach-size">${fmtBytes(f.size_bytes)}</span></li>`).join('')}</ul>
<ul class="docs-attachments-list">${article.files.map(f => { const isImg = f._kind === 'image'; const captionInput = isImg ? `<div class="docs-caption-row"><input class="docs-caption-input" data-caption-for="${f.id}" value="${esc(f.caption || '')}" placeholder="Подпись (alt/title)" maxlength="300"><button type="button" class="btn-primary ghost" data-file-act="caption" title="Сохранить подпись">✓</button></div>` : ''; return `<li><a href="${esc(f.path)}" target="_blank" rel="noopener">${esc(f.name)}</a>${captionInput} <span class="docs-attach-size">${fmtBytes(f.size_bytes)}</span></li>`; }).join('')}</ul>
</div>` : ''}
</article>`;
}
@@ -583,7 +583,8 @@
return /\.(jpe?g|png|gif|webp|bmp|avif|ico|jfif)$/i.test(String(f.name || f.path || ''));
}
function insertDocFileLink(f) {
const md = isImageFile(f) ? `![${f.name}](${f.path})` : `[${f.name}](${f.path})`;
const alt = (f.caption || f.name || 'картинка').replace(/\\./g, '\\.');
const md = isImageFile(f) ? `![${alt}](${f.path})` : `[${f.name}](${f.path})`;
insertBlock(md);
}
@@ -612,9 +613,10 @@
return;
}
imgLibGrid.innerHTML = items.map(it => `
<div class="docs-imglib-item" data-img-path="${esc(it.path)}" title="${esc(it.path)}">
<div class="docs-imglib-item" data-img-path="${esc(it.path)}" data-img-caption="${esc(it.caption || '')}" title="${esc(it.path)}">
<img src="${esc('/uploads/thumb/' + it.path.split('/').pop())}" alt="" loading="lazy">
<div class="docs-imglib-name">${esc(it.path.split('/').pop())}</div>
${it.caption ? '<div class="docs-imglib-caption">' + esc(it.caption) + '</div>' : ''}
</div>`).join('');
} catch (e) {
imgLibGrid.innerHTML = '<div class="docs-empty">' + esc(e.message) + '</div>';
@@ -887,8 +889,9 @@
if (!item) return;
const p = item.dataset.imgPath;
if (!p) return;
const name = p.split('/').pop().replace(/\.[^.]+$/, '');
insertBlock(`![${name}](${p})`);
const caption = item.dataset.imgCaption || '';
const alt = caption || p.split("/").pop().replace(/\.[^.]+$/, "");
insertBlock(`![${alt}](${p})`);
if (imgLibModal) imgLibModal.classList.remove('open');
showToast('Картинка вставлена');
});
+3 -4
View File
@@ -27,12 +27,11 @@
return `\u0000${codes.length - 1}\u0000`;
});
text = esc(text);
text = text.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (m, alt, src, title) => {
text = text.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (m, alt, src) => {
const url = safeUrl(src.replace(/&amp;/g, '&'));
if (!url) return alt;
const t = title ? title.replace(/&amp;/g, '&') : '';
const img = `<img src="${esc(thumbUrl(url))}" data-img="${esc(url)}" alt="${esc(alt)}"${t ? ` title="${esc(t)}"` : ''} loading="lazy">`;
if (t) return `<figure class="md-figure">${img}<figcaption>${esc(t)}</figcaption></figure>`;
const img = `<img src="${esc(thumbUrl(url))}" data-img="${esc(url)}" alt="${esc(alt)}" loading="lazy">`;
if (alt) return `<figure class="md-figure">${img}<figcaption>${esc(alt)}</figcaption></figure>`;
return img;
});
text = text.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (m, label, href) => {