-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix/#152 ์ธ์คํ๊ทธ๋จ ์ด๋ฏธ์ง ์กฐํ ๋ฌธ์ ์์
- Loading branch information
Showing
30 changed files
with
763 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
Projects/CoreKit/Sources/Data/Client/SwiftSoupClient/SwiftSoupProvider.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// SwiftSoupProvider.swift | ||
// CoreKit | ||
// | ||
// Created by ๊น๋ํ on 11/17/24. | ||
// | ||
|
||
import SwiftUI | ||
import SwiftSoup | ||
|
||
final class SwiftSoupProvider { | ||
func parseOGTitle(_ url: URL) async throws -> String? { | ||
try await parseOGMeta(url: url, type: "og:title") | ||
} | ||
|
||
func parseOGImageURL(_ url: URL) async throws -> String? { | ||
try await parseOGMeta(url: url, type: "og:image") | ||
} | ||
|
||
func parseOGMeta(url: URL, type: String) async throws -> String? { | ||
let html = try String(contentsOf: url) | ||
let document = try SwiftSoup.parse(html) | ||
|
||
if let metaData = try document.select("meta[property=\(type)]").first()?.attr("content") { | ||
return metaData | ||
} else { | ||
var request = URLRequest(url: url) | ||
request.setValue( | ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36", | ||
forHTTPHeaderField: "User-Agent" | ||
) | ||
|
||
let (data, _) = try await URLSession.shared.data(for: request) | ||
guard let html = String(data: data, encoding: .utf8) else { | ||
return nil | ||
} | ||
let document = try SwiftSoup.parse(html) | ||
let metaData = try document.select("meta[property=\(type)]").first()?.attr("content") | ||
|
||
return metaData | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.