extractPublishDate static method
Extract publication date
Implementation
static String? extractPublishDate(String html) {
final strategies = [
r'<time[^>]*datetime=[\"\x27]([^\"\x27]*)[\"\x27]',
r'<meta[^>]*property=[\"\x27]article:published_time[\"\x27][^>]*content=[\"\x27]([^\"\x27]*)[\"\x27]',
r'<[^>]*class=[\"\x27][^\"\x27]*date[^\"\x27]*[\"\x27][^>]*>([^<]*)<',
r'(\d{4}-\d{2}-\d{2})',
];
for (final pattern in strategies) {
final match = RegExp(pattern, caseSensitive: false).firstMatch(html);
if (match != null) {
final date = _cleanText(match.group(1) ?? '');
if (date.isNotEmpty) return date;
}
}
return null;
}