feat(albums): show formatted editorial descriptions

This commit is contained in:
zarzet
2026-09-26 03:50:37 +07:00
parent 0e1881d837
commit 7d7716cd6f
13 changed files with 465 additions and 25 deletions
+30
View File
@@ -0,0 +1,30 @@
import 'package:html/dom.dart';
import 'package:html/parser.dart' as html;
/// Editorial text is display-only. Never load embedded media or execute markup.
DocumentFragment parseEditorialNotes(String value) {
final fragment = html.parseFragment(value);
for (final element in fragment.querySelectorAll(
'script, style, iframe, object, template',
)) {
element.remove();
}
return fragment;
}
String? albumDescriptionFromMetadata(Map<String, dynamic>? metadata) {
final notes =
metadata?['editorial_notes'] ??
metadata?['editorialNotes'] ??
metadata?['description'];
final candidates = notes is Map
? [notes['standard'], notes['short']]
: [notes];
for (final candidate in candidates) {
if (candidate is String &&
(parseEditorialNotes(candidate).text ?? '').trim().isNotEmpty) {
return candidate.trim();
}
}
return null;
}