Add link out URL for link only reddit articles

This commit is contained in:
Maurice Parker 2020-05-05 21:23:42 -05:00
parent 6c698c5b94
commit cce420b31d
1 changed files with 10 additions and 1 deletions

View File

@ -98,6 +98,7 @@ struct RedditLinkData: Codable {
html += "width=\"\(width)\" height=\"\(height)\" "
}
html += "src=\"\(videoPreviewURL)\"></video>"
html += linkOutURL(url)
return html
}
@ -107,10 +108,18 @@ struct RedditLinkData: Codable {
html += "width=\"\(width)\" height=\"\(height)\" "
}
html += "></a></figure>"
html += linkOutURL(url)
return html
}
return nil
return linkOutURL(url)
}
func linkOutURL(_ url: String) -> String {
guard let urlComponents = URLComponents(string: url), let host = urlComponents.host, !host.hasSuffix("reddit.com") else {
return ""
}
return "<div><a href=\"\(url)\">\(url)</a></div>"
}
}