68 lines
1.8 KiB
Dart
68 lines
1.8 KiB
Dart
// Copyright (C) 2022 WYATT GROUP
|
|
// Please see the AUTHORS file for details.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
import 'package:html/parser.dart';
|
|
import 'package:webfeed/webfeed.dart';
|
|
import 'package:wyatt_medium_feeds/src/reading_time.dart';
|
|
|
|
class MediumArticle {
|
|
final RssItem? _item;
|
|
|
|
RssItem get item {
|
|
if (_item == null) {
|
|
throw StateError('Feed has not been parsed yet.');
|
|
}
|
|
return _item!;
|
|
}
|
|
|
|
MediumArticle(this._item);
|
|
|
|
String get title => item.title ?? '';
|
|
|
|
String get link => item.link ?? '';
|
|
|
|
String get guid => item.guid ?? '';
|
|
|
|
String get author => item.dc?.creator ?? '';
|
|
|
|
DateTime? get publishDate => item.pubDate;
|
|
|
|
String get content => item.content?.value ?? '';
|
|
|
|
List<String> get images {
|
|
final images = <String>[];
|
|
for (final i in item.content?.images ?? <String>[]) {
|
|
images.add(i);
|
|
}
|
|
return images;
|
|
}
|
|
|
|
String get decoded {
|
|
final document = parse(content);
|
|
return document.firstChild?.text ?? '';
|
|
}
|
|
|
|
String get summary {
|
|
final regex = RegExp(r'^.*?[\.!\?](?:\s|$)');
|
|
final match = regex.firstMatch(decoded);
|
|
return match?.group(0) ?? '';
|
|
}
|
|
|
|
Duration get readingTime {
|
|
return decoded.readingTime();
|
|
}
|
|
}
|