···310310}
311311312312// GetRepositoryMetadata retrieves metadata for a repository from its most recent manifest
313313+// Prioritizes manifests with non-empty metadata fields
313314func GetRepositoryMetadata(db *sql.DB, did string, repository string) (title, description, sourceURL, documentationURL, licenses, iconURL, readmeURL string, err error) {
314315 var titleNull, descriptionNull, sourceURLNull, documentationURLNull, licensesNull, iconURLNull, readmeURLNull sql.NullString
315316317317+ // Try to find a manifest with metadata first (prefer manifests with any non-empty annotation field)
316318 err = db.QueryRow(`
317319 SELECT title, description, source_url, documentation_url, licenses, icon_url, readme_url
318320 FROM manifests
319321 WHERE did = ? AND repository = ?
322322+ AND (
323323+ (title IS NOT NULL AND title != '')
324324+ OR (description IS NOT NULL AND description != '')
325325+ OR (source_url IS NOT NULL AND source_url != '')
326326+ OR (documentation_url IS NOT NULL AND documentation_url != '')
327327+ OR (licenses IS NOT NULL AND licenses != '')
328328+ OR (icon_url IS NOT NULL AND icon_url != '')
329329+ OR (readme_url IS NOT NULL AND readme_url != '')
330330+ )
320331 ORDER BY created_at DESC
321332 LIMIT 1
322333 `, did, repository).Scan(&titleNull, &descriptionNull, &sourceURLNull, &documentationURLNull, &licensesNull, &iconURLNull, &readmeURLNull)
334334+335335+ // If no manifest with metadata found, fall back to latest manifest (any type)
336336+ if err == sql.ErrNoRows {
337337+ err = db.QueryRow(`
338338+ SELECT title, description, source_url, documentation_url, licenses, icon_url, readme_url
339339+ FROM manifests
340340+ WHERE did = ? AND repository = ?
341341+ ORDER BY created_at DESC
342342+ LIMIT 1
343343+ `, did, repository).Scan(&titleNull, &descriptionNull, &sourceURLNull, &documentationURLNull, &licensesNull, &iconURLNull, &readmeURLNull)
344344+ }
323345324346 if err == sql.ErrNoRows {
325347 // No manifests found - return empty strings