added description to all projekt

This commit is contained in:
2026-11-12 19:50:38 +01:00
parent 3f5438cb92
commit 7824ddb6dc
5 changed files with 110 additions and 4 deletions

View File

@@ -83,6 +83,37 @@ function sanitizeTasks(tasks) {
})).filter((t) => t.text.length > 0)
}
const MAX_DESCRIPTION = 4000
// First real paragraph(s) of the project's README - suggestion for the
// description in the Info tab. Skips headings, badges, images, tables, code.
function readmeIntro(projectPath) {
let text = ''
for (const f of ['README.md', 'readme.md', 'Readme.md', 'README.txt', 'README']) {
try { text = fs.readFileSync(path.join(projectPath, f), 'utf-8'); break } catch {}
}
if (!text) return ''
text = text.replace(/^---[\s\S]*?\n---\s*\n/, '').replace(/<!--[\s\S]*?-->/g, '').replace(/```[\s\S]*?```/g, '')
const paras = []
let cur = []
const flush = () => { if (cur.length) paras.push(cur.join(' ')); cur = [] }
for (const raw of text.split(/\r?\n/)) {
const line = raw.trim()
if (!line) { flush(); continue }
if (/^(#|\||!\[|\[!\[|<|>|---|===|\*\*\*)/.test(line)) { flush(); continue }
cur.push(line.replace(/^[-*]\s+/, '• '))
}
flush()
const clean = (p) => p.replace(/\*\*|__|`/g, '').replace(/\[([^\]]+)\]\([^)]+\)/g, '$1').trim()
let out = ''
for (const p of paras.map(clean).filter((p) => p.length > 20)) {
if (out && out.length + p.length > 600) break
out = out ? `${out}\n\n${p}` : p
if (out.length > 300) break
}
return out.length > 800 ? out.slice(0, 797).replace(/\s+\S*$/, '') + '…' : out
}
function readStatusFile(projectPath) {
const file = path.join(projectPath, STATUS_FILE)
try {
@@ -92,6 +123,7 @@ function readStatusFile(projectPath) {
status: STATUSES.includes(data.status) ? data.status : 'idea',
priority: PRIORITIES.includes(data.priority) ? data.priority : 'medium',
notes: typeof data.notes === 'string' ? data.notes : '',
description: typeof data.description === 'string' ? data.description.slice(0, MAX_DESCRIPTION) : '',
tags: Array.isArray(data.tags) ? data.tags.map(String).slice(0, 10) : [],
tasks: sanitizeTasks(data.tasks),
thumbnail: typeof data.thumbnail === 'string' ? data.thumbnail.slice(0, 300) : '',
@@ -101,7 +133,7 @@ function readStatusFile(projectPath) {
updatedAt: data.updatedAt ?? null,
}
} catch {
return { status: 'idea', priority: 'medium', notes: '', tags: [], tasks: [], thumbnail: '', start: '', program: '', itch: '', updatedAt: null }
return { status: 'idea', priority: 'medium', notes: '', description: '', tags: [], tasks: [], thumbnail: '', start: '', program: '', itch: '', updatedAt: null }
}
}
@@ -536,7 +568,7 @@ app.patch('/api/projects/:name', (req, res) => {
const projectPath = resolveProject(req.params.name)
if (!projectPath) return res.status(404).json({ error: 'unknown project' })
const current = readStatusFile(projectPath)
const { status, priority, notes, tags, tasks, thumbnail, start, program, itch: itchLink } = req.body ?? {}
const { status, priority, notes, description, tags, tasks, thumbnail, start, program, itch: itchLink } = req.body ?? {}
// itch: '' = automatic, '-' = not published, otherwise the game's page
let nextItch = current.itch
if (typeof itchLink === 'string') {
@@ -560,6 +592,7 @@ app.patch('/api/projects/:name', (req, res) => {
status: STATUSES.includes(status) ? status : current.status,
priority: PRIORITIES.includes(priority) ? priority : current.priority,
notes: typeof notes === 'string' ? notes : current.notes,
description: typeof description === 'string' ? description.trim().slice(0, MAX_DESCRIPTION) : current.description,
tags: Array.isArray(tags) ? tags.map(String).slice(0, 10) : current.tags,
tasks: tasks !== undefined ? sanitizeTasks(tasks) : current.tasks,
thumbnail: typeof thumbnail === 'string' ? thumbnail.slice(0, 300) : current.thumbnail,
@@ -616,6 +649,7 @@ app.get('/api/projects/:name/details', handle(async (req, res) => {
releaseDirs: archive.findReleaseDirs(projectPath),
archives: archive.listArchives(projectPath),
itchPack: itchpack.summary(projectPath),
readme: readmeIntro(projectPath),
})
}))