mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Get twitter:image:src from HTML metadata.
This commit is contained in:
@@ -71,7 +71,8 @@ static NSString *kTypeKey = @"type";
|
||||
_feedLinks = objectsOfClassWithTags([RSHTMLMetadataFeedLink class], feedLinkTags, urlString);
|
||||
|
||||
_openGraphProperties = [[RSHTMLOpenGraphProperties alloc] initWithURLString:urlString tags:tags];
|
||||
|
||||
_twitterProperties = [[RSHTMLTwitterProperties alloc] initWithURLString:urlString tags:tags];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -382,4 +383,38 @@ static NSString *ogContentKey = @"content";
|
||||
|
||||
@end
|
||||
|
||||
@implementation RSHTMLTwitterProperties
|
||||
|
||||
static NSString *twitterNameKey = @"name";
|
||||
static NSString *twitterContentKey = @"content";
|
||||
static NSString *twitterImageSrc = @"twitter:image:src";
|
||||
|
||||
- (instancetype)initWithURLString:(NSString *)urlString tags:(NSArray <RSHTMLTag *> *)tags {
|
||||
|
||||
self = [super init];
|
||||
if (!self) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
for (RSHTMLTag *tag in tags) {
|
||||
|
||||
if (tag.type != RSHTMLTagTypeMeta) {
|
||||
continue;
|
||||
}
|
||||
NSString *name = tag.attributes[twitterNameKey];
|
||||
if (!name || ![name isEqualToString:twitterImageSrc]) {
|
||||
continue;
|
||||
}
|
||||
NSString *content = tag.attributes[twitterContentKey];
|
||||
if (!content || content.length < 1) {
|
||||
continue;
|
||||
}
|
||||
_imageURL = content;
|
||||
break;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user