Add article abstract

This commit is contained in:
relikd
2018-09-11 23:19:29 +02:00
parent 09794c92f7
commit 4228bc3d67
3 changed files with 27 additions and 35 deletions

View File

@@ -29,9 +29,9 @@
@property (nonatomic) NSMutableArray *attributesStack; @property (nonatomic) NSMutableArray *attributesStack;
@property (nonatomic, readonly) NSDictionary *currentAttributes; @property (nonatomic, readonly) NSDictionary *currentAttributes;
@property (nonatomic) NSMutableString *xhtmlString; @property (nonatomic) NSMutableString *xhtmlString;
@property (nonatomic) NSString *link; @property (nonatomic) NSString *feedLink;
@property (nonatomic) NSString *title; @property (nonatomic) NSString *feedTitle;
@property (nonatomic) NSString *subtitle; @property (nonatomic) NSString *feedSubtitle;
@property (nonatomic) NSMutableArray *articles; @property (nonatomic) NSMutableArray *articles;
@property (nonatomic) NSDate *dateParsed; @property (nonatomic) NSDate *dateParsed;
@property (nonatomic) RSSAXParser *parser; @property (nonatomic) RSSAXParser *parser;
@@ -110,8 +110,8 @@
[self parse]; [self parse];
RSParsedFeed *parsedFeed = [[RSParsedFeed alloc] initWithURLString:self.urlString title:self.title link:self.link articles:self.articles]; RSParsedFeed *parsedFeed = [[RSParsedFeed alloc] initWithURLString:self.urlString title:self.feedTitle link:self.feedLink articles:self.articles];
parsedFeed.subtitle = self.subtitle; parsedFeed.subtitle = self.feedSubtitle;
return parsedFeed; return parsedFeed;
} }
@@ -261,28 +261,28 @@ static const NSInteger kSelfLength = 5;
- (void)addFeedLink { - (void)addFeedLink {
if (self.link && self.link.length > 0) { if (self.feedLink && self.feedLink.length > 0) {
return; return;
} }
NSString *related = self.currentAttributes[kRelKey]; NSString *related = self.currentAttributes[kRelKey];
if (related == kAlternateValue) { if (related == kAlternateValue) {
self.link = self.currentAttributes[kHrefKey]; self.feedLink = self.currentAttributes[kHrefKey];
} }
} }
- (void)addFeedTitle { - (void)addFeedTitle {
if (self.title.length < 1) { if (self.feedTitle.length < 1) {
self.title = self.parser.currentStringWithTrimmedWhitespace; self.feedTitle = self.parser.currentStringWithTrimmedWhitespace;
} }
} }
- (void)addFeedSubtitle { - (void)addFeedSubtitle {
if (self.subtitle.length < 1) { if (self.feedSubtitle.length < 1) {
self.subtitle = self.parser.currentStringWithTrimmedWhitespace; self.feedSubtitle = self.parser.currentStringWithTrimmedWhitespace;
} }
} }
@@ -319,9 +319,7 @@ static const NSInteger kSelfLength = 5;
- (void)addSummary { - (void)addSummary {
if (!self.currentArticle.body) { self.currentArticle.abstract = [self currentStringWithHTMLEntitiesDecoded];
self.currentArticle.body = [self currentStringWithHTMLEntitiesDecoded];
}
} }
@@ -472,16 +470,12 @@ static const NSInteger kSelfLength = 5;
BOOL isContentTag = RSSAXEqualTags(localName, kContent, kContentLength); BOOL isContentTag = RSSAXEqualTags(localName, kContent, kContentLength);
BOOL isSummaryTag = RSSAXEqualTags(localName, kSummary, kSummaryLength); BOOL isSummaryTag = RSSAXEqualTags(localName, kSummary, kSummaryLength);
if (self.parsingArticle && (isContentTag || isSummaryTag)) { if (self.parsingArticle) {
if (isContentTag) { if (isContentTag) {
self.currentArticle.body = [self.xhtmlString copy]; self.currentArticle.body = [self.xhtmlString copy];
} }
else if (isSummaryTag) { else if (isSummaryTag) {
if (self.currentArticle.body.length < 1) { self.currentArticle.abstract = [self.xhtmlString copy];
self.currentArticle.body = [self.xhtmlString copy];
}
} }
} }

1
RSXML/RSParsedArticle.h Normal file → Executable file
View File

@@ -18,6 +18,7 @@
@property (nonatomic, nullable) NSString *guid; @property (nonatomic, nullable) NSString *guid;
@property (nonatomic, nullable) NSString *title; @property (nonatomic, nullable) NSString *title;
@property (nonatomic, nullable) NSString *abstract;
@property (nonatomic, nullable) NSString *body; @property (nonatomic, nullable) NSString *body;
@property (nonatomic, nullable) NSString *link; @property (nonatomic, nullable) NSString *link;
@property (nonatomic, nullable) NSString *permalink; @property (nonatomic, nullable) NSString *permalink;

View File

@@ -29,9 +29,9 @@
@property (nonatomic) BOOL parsingChannelImage; @property (nonatomic) BOOL parsingChannelImage;
@property (nonatomic, readonly) NSDate *currentDate; @property (nonatomic, readonly) NSDate *currentDate;
@property (nonatomic) BOOL endRSSFound; @property (nonatomic) BOOL endRSSFound;
@property (nonatomic) NSString *link; @property (nonatomic) NSString *feedLink;
@property (nonatomic) NSString *title; @property (nonatomic) NSString *feedTitle;
@property (nonatomic) NSString *subtitle; @property (nonatomic) NSString *feedSubtitle;
@property (nonatomic) NSDate *dateParsed; @property (nonatomic) NSDate *dateParsed;
@end @end
@@ -105,8 +105,8 @@
[self parse]; [self parse];
RSParsedFeed *parsedFeed = [[RSParsedFeed alloc] initWithURLString:self.urlString title:self.title link:self.link articles:self.articles]; RSParsedFeed *parsedFeed = [[RSParsedFeed alloc] initWithURLString:self.urlString title:self.feedTitle link:self.feedLink articles:self.articles];
parsedFeed.subtitle = self.subtitle; parsedFeed.subtitle = self.feedSubtitle;
return parsedFeed; return parsedFeed;
} }
@@ -230,17 +230,17 @@ static const NSInteger kTrueLength = 5;
} }
if (RSSAXEqualTags(localName, kLink, kLinkLength)) { if (RSSAXEqualTags(localName, kLink, kLinkLength)) {
if (!self.link) { if (!self.feedLink) {
self.link = self.parser.currentStringWithTrimmedWhitespace; self.feedLink = self.parser.currentStringWithTrimmedWhitespace;
} }
} }
else if (RSSAXEqualTags(localName, kTitle, kTitleLength)) { else if (RSSAXEqualTags(localName, kTitle, kTitleLength)) {
self.title = self.parser.currentStringWithTrimmedWhitespace; self.feedTitle = self.parser.currentStringWithTrimmedWhitespace;
} }
else if (RSSAXEqualTags(localName, kDescription, kDescriptionLength)) { else if (RSSAXEqualTags(localName, kDescription, kDescriptionLength)) {
self.subtitle = self.parser.currentStringWithTrimmedWhitespace; self.feedSubtitle = self.parser.currentStringWithTrimmedWhitespace;
} }
} }
@@ -277,12 +277,12 @@ static const NSInteger kTrueLength = 5;
return s; return s;
} }
if (!self.link) { if (!self.feedLink) {
//TODO: get feed URL and use that to resolve URL.*/ //TODO: get feed URL and use that to resolve URL.*/
return s; return s;
} }
NSURL *baseURL = [NSURL URLWithString:self.link]; NSURL *baseURL = [NSURL URLWithString:self.feedLink];
if (!baseURL) { if (!baseURL) {
return s; return s;
} }
@@ -332,10 +332,7 @@ static const NSInteger kTrueLength = 5;
self.currentArticle.link = [self urlString:self.parser.currentStringWithTrimmedWhitespace]; self.currentArticle.link = [self urlString:self.parser.currentStringWithTrimmedWhitespace];
} }
else if (RSSAXEqualTags(localName, kDescription, kDescriptionLength)) { else if (RSSAXEqualTags(localName, kDescription, kDescriptionLength)) {
self.currentArticle.abstract = [self currentStringWithHTMLEntitiesDecoded];
if (!self.currentArticle.body) {
self.currentArticle.body = [self currentStringWithHTMLEntitiesDecoded];
}
} }
else if (RSSAXEqualTags(localName, kTitle, kTitleLength)) { else if (RSSAXEqualTags(localName, kTitle, kTitleLength)) {
self.currentArticle.title = [self currentStringWithHTMLEntitiesDecoded]; self.currentArticle.title = [self currentStringWithHTMLEntitiesDecoded];