Skip to content

Commit 71a0dc2

Browse files
committed
Use GutenbergKitResources in GutenbergKit
This had been in my local setup all this time, but got lost in the many `ios/Sources` diff lines
1 parent 2308e7a commit 71a0dc2

1 file changed

Lines changed: 2 additions & 18 deletions

File tree

ios/Sources/GutenbergKit/Sources/Views/HTMLPreview/HTMLPreviewManager.swift

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import CryptoKit
55
import ImageIO
66
import UniformTypeIdentifiers
77
import SwiftUI
8+
import GutenbergKitResources
89

910
/// Renders HTML content to images using a pool of WKWebView instances.
1011
///
@@ -52,7 +53,7 @@ public final class HTMLPreviewManager: ObservableObject {
5253
// MARK: - Initialization
5354

5455
public init(themeStyles: String? = nil) {
55-
let gutenbergCSS = Self.loadGutenbergCSS() ?? ""
56+
let gutenbergCSS = GutenbergKitResources.loadGutenbergCSS() ?? ""
5657
assert(!gutenbergCSS.isEmpty, "Failed to load Gutenberg CSS from bundle. Previews will not render correctly.")
5758

5859
self.editorStyles = gutenbergCSS
@@ -67,23 +68,6 @@ public final class HTMLPreviewManager: ObservableObject {
6768
self.urlCache = HTMLPreviewManager.makeCache()
6869
}
6970

70-
/// Loads the Gutenberg CSS from the bundled assets
71-
private static func loadGutenbergCSS() -> String? {
72-
guard let assetsURL = Bundle.module.url(forResource: "Gutenberg", withExtension: nil) else {
73-
assertionFailure("Gutenberg resource not found in bundle")
74-
return nil
75-
}
76-
77-
let assetsDirectory = assetsURL.appendingPathComponent("assets")
78-
guard let files = try? FileManager.default.contentsOfDirectory(at: assetsDirectory, includingPropertiesForKeys: nil),
79-
let cssURL = files.first(where: { $0.lastPathComponent.hasPrefix("index-") && $0.lastPathComponent.hasSuffix(".css") }),
80-
let css = try? String(contentsOf: cssURL, encoding: .utf8) else {
81-
assertionFailure("Failed to load Gutenberg CSS from bundle")
82-
return nil
83-
}
84-
return css
85-
}
86-
8771
// MARK: - Public API
8872

8973
/// Renders HTML content to an image

0 commit comments

Comments
 (0)