Fixing Bugs & Adding subtitle to feeds

This commit is contained in:
relikd
2018-08-19 23:30:48 +02:00
parent 5ebeab17d2
commit 09794c92f7
6 changed files with 35 additions and 2 deletions

21
RSXML/RSAtomParser.m Normal file → Executable file
View File

@@ -31,6 +31,7 @@
@property (nonatomic) NSMutableString *xhtmlString; @property (nonatomic) NSMutableString *xhtmlString;
@property (nonatomic) NSString *link; @property (nonatomic) NSString *link;
@property (nonatomic) NSString *title; @property (nonatomic) NSString *title;
@property (nonatomic) NSString *subtitle;
@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,6 +111,7 @@
[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.title link:self.link articles:self.articles];
parsedFeed.subtitle = self.subtitle;
return parsedFeed; return parsedFeed;
} }
@@ -141,6 +143,9 @@ static const NSInteger kIDLength = 3;
static const char *kTitle = "title"; static const char *kTitle = "title";
static const NSInteger kTitleLength = 6; static const NSInteger kTitleLength = 6;
static const char *kSubtitle = "subtitle";
static const NSInteger kSubtitleLength = 9;
static const char *kContent = "content"; static const char *kContent = "content";
static const NSInteger kContentLength = 8; static const NSInteger kContentLength = 8;
@@ -274,6 +279,13 @@ static const NSInteger kSelfLength = 5;
} }
} }
- (void)addFeedSubtitle {
if (self.subtitle.length < 1) {
self.subtitle = self.parser.currentStringWithTrimmedWhitespace;
}
}
- (void)addLink { - (void)addLink {
NSString *urlString = self.currentAttributes[kHrefKey]; NSString *urlString = self.currentAttributes[kHrefKey];
@@ -498,8 +510,13 @@ static const NSInteger kSelfLength = 5;
self.parsingSource = NO; self.parsingSource = NO;
} }
else if (!self.parsingArticle && !self.parsingSource && RSSAXEqualTags(localName, kTitle, kTitleLength)) { else if (!self.parsingArticle && !self.parsingSource) {
[self addFeedTitle]; if (RSSAXEqualTags(localName, kTitle, kTitleLength)) {
[self addFeedTitle];
}
else if (RSSAXEqualTags(localName, kSubtitle, kSubtitleLength)) {
[self addFeedSubtitle];
}
} }
[self.attributesStack removeLastObject]; [self.attributesStack removeLastObject];
} }

4
RSXML/RSParsedArticle.m Normal file → Executable file
View File

@@ -97,5 +97,9 @@
(void)self.articleID; (void)self.articleID;
} }
- (NSString*)description {
return [NSString stringWithFormat:@"{%@ '%@', guid: %@}", [self class], self.title, self.guid];
}
@end @end

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

@@ -17,6 +17,7 @@
@property (nonatomic, readonly, nonnull) NSString *urlString; @property (nonatomic, readonly, nonnull) NSString *urlString;
@property (nonatomic, readonly, nullable) NSString *title; @property (nonatomic, readonly, nullable) NSString *title;
@property (nonatomic, readonly, nullable) NSString *link; @property (nonatomic, readonly, nullable) NSString *link;
@property (nonatomic, nullable) NSString *subtitle;
@property (nonatomic, readonly, nonnull) NSSet <RSParsedArticle *>*articles; @property (nonatomic, readonly, nonnull) NSSet <RSParsedArticle *>*articles;
@end @end

4
RSXML/RSParsedFeed.m Normal file → Executable file
View File

@@ -25,5 +25,9 @@
return self; return self;
} }
- (NSString*)description {
return [NSString stringWithFormat:@"{%@ (%@), title: '%@', subtitle: '%@', entries: %@}",
[self class], _link, _title, _subtitle, _articles];
}
@end @end

6
RSXML/RSRSSParser.m Normal file → Executable file
View File

@@ -31,6 +31,7 @@
@property (nonatomic) BOOL endRSSFound; @property (nonatomic) BOOL endRSSFound;
@property (nonatomic) NSString *link; @property (nonatomic) NSString *link;
@property (nonatomic) NSString *title; @property (nonatomic) NSString *title;
@property (nonatomic) NSString *subtitle;
@property (nonatomic) NSDate *dateParsed; @property (nonatomic) NSDate *dateParsed;
@end @end
@@ -105,6 +106,7 @@
[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.title link:self.link articles:self.articles];
parsedFeed.subtitle = self.subtitle;
return parsedFeed; return parsedFeed;
} }
@@ -236,6 +238,10 @@ static const NSInteger kTrueLength = 5;
else if (RSSAXEqualTags(localName, kTitle, kTitleLength)) { else if (RSSAXEqualTags(localName, kTitle, kTitleLength)) {
self.title = self.parser.currentStringWithTrimmedWhitespace; self.title = self.parser.currentStringWithTrimmedWhitespace;
} }
else if (RSSAXEqualTags(localName, kDescription, kDescriptionLength)) {
self.subtitle = self.parser.currentStringWithTrimmedWhitespace;
}
} }

View File

@@ -8,6 +8,7 @@
#import <libxml/tree.h> #import <libxml/tree.h>
#import <libxml/xmlstring.h> #import <libxml/xmlstring.h>
#import <libxml/parser.h>
#import "RSSAXParser.h" #import "RSSAXParser.h"
#import "RSXMLInternal.h" #import "RSXMLInternal.h"