Change cross posts to pull from current link if original link is sparse
This commit is contained in:
parent
4d9975f28a
commit
73627a60ca
|
@ -268,10 +268,10 @@ private extension RedditFeedProvider {
|
|||
switch result {
|
||||
case .success(let response):
|
||||
|
||||
// let jsonString = String(data: response.data, encoding: .utf8)
|
||||
// let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("reddit.json")
|
||||
// print("******** writing to: \(url.path)")
|
||||
// try? jsonString?.write(toFile: url.path, atomically: true, encoding: .utf8)
|
||||
let jsonString = String(data: response.data, encoding: .utf8)
|
||||
let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("reddit.json")
|
||||
print("******** writing to: \(url.path)")
|
||||
try? jsonString?.write(toFile: url.path, atomically: true, encoding: .utf8)
|
||||
|
||||
if let remaining = response.response.value(forHTTPHeaderField: "X-Ratelimit-Remaining") {
|
||||
self.rateLimitRemaining = Int(remaining)
|
||||
|
|
|
@ -61,30 +61,33 @@ final class RedditLinkData: Codable {
|
|||
return Date(timeIntervalSince1970: created)
|
||||
}
|
||||
|
||||
func renderAsHTML() -> String? {
|
||||
var html = String()
|
||||
if let selfHTML = selfHTML {
|
||||
html += selfHTML
|
||||
}
|
||||
if let urlHTML = renderURLAsHTML() {
|
||||
html += urlHTML
|
||||
}
|
||||
return html
|
||||
}
|
||||
|
||||
func renderURLAsHTML() -> String? {
|
||||
guard let url = url else { return nil }
|
||||
|
||||
func renderAsHTML() -> String {
|
||||
if let parent = crossPostParents?.first {
|
||||
var html = "<blockquote>"
|
||||
if let subreddit = parent.subredditNamePrefixed {
|
||||
html += "<p><a href=\"https://www.reddit.com/\(subreddit)\">\(subreddit)</a></p>"
|
||||
}
|
||||
html += parent.renderAsHTML() ?? ""
|
||||
let parentHTML = parent.renderAsHTML()
|
||||
if parentHTML.isEmpty {
|
||||
html += renderURLAsHTML()
|
||||
} else {
|
||||
html += parentHTML
|
||||
}
|
||||
html += "</blockquote>"
|
||||
return html
|
||||
}
|
||||
|
||||
var html = String()
|
||||
if let selfHTML = selfHTML {
|
||||
html += selfHTML
|
||||
}
|
||||
html += renderURLAsHTML()
|
||||
return html
|
||||
}
|
||||
|
||||
func renderURLAsHTML() -> String {
|
||||
guard let url = url else { return "" }
|
||||
|
||||
if url.hasSuffix(".gif") {
|
||||
return "<img src=\"\(url)\">"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue