mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Rename file.
This commit is contained in:
56
Shared/Images/HTMLMetadata+Extension.swift
Normal file
56
Shared/Images/HTMLMetadata+Extension.swift
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// HTMLMetadata+Extension.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Brent Simmons on 11/26/17.
|
||||
// Copyright © 2017 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Parser
|
||||
|
||||
extension HTMLMetadata {
|
||||
|
||||
func largestAppleTouchIcon() -> String? {
|
||||
|
||||
guard let icons = appleTouchIcons, !icons.isEmpty else {
|
||||
return nil
|
||||
}
|
||||
|
||||
var bestImage: HTMLMetadataAppleTouchIcon? = nil
|
||||
|
||||
for image in icons {
|
||||
if let size = image.size {
|
||||
if size.width / size.height > 2 {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if bestImage == nil {
|
||||
bestImage = image
|
||||
continue
|
||||
}
|
||||
if let size = image.size, let bestImageSize = bestImage!.size {
|
||||
if size.height > bestImageSize.height && size.width > bestImageSize.width {
|
||||
bestImage = image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bestImage?.urlString
|
||||
}
|
||||
|
||||
func bestWebsiteIconURL() -> String? {
|
||||
|
||||
// TODO: metadata icons — sometimes they’re large enough to use here.
|
||||
|
||||
if let appleTouchIcon = largestAppleTouchIcon() {
|
||||
return appleTouchIcon
|
||||
}
|
||||
|
||||
if let openGraphImageURL = openGraphProperties?.image?.url {
|
||||
return openGraphImageURL
|
||||
}
|
||||
|
||||
return twitterProperties?.imageURL
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user