Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 7d31509

Browse files
committed
Load CSS from package resource when available
1 parent 006dddc commit 7d31509

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

.node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"not dead"
66
],
77
"scripts": {
8-
"watch": "postcss -w ../Assets/**/*.css -o ../Resources/all.min.css --config ./postcss.config.js"
8+
"watch": "postcss -w ../Assets/**/*.css -o ../Sources/swift-doc/Resources/all.min.css --config ./postcss.config.js"
99
},
1010
"dependencies": {
1111
"cssnano": "^4.1.10",

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ let package = Package(
4343
.product(name: "SwiftSyntaxHighlighter", package: "SwiftSyntaxHighlighter"),
4444
.product(name: "Logging", package: "swift-log"),
4545
.product(name: "LoggingGitHubActions", package: "LoggingGitHubActions")
46+
],
47+
resources: [
48+
.copy("Resources")
4649
]
4750
),
4851
.target(
File renamed without changes.

Sources/swift-doc/Subcommands/Generate.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,26 @@ extension SwiftDoc {
120120
}
121121

122122
if case .html = format {
123-
let cssData = try fetchRemoteCSS()
124-
let cssURL = outputDirectoryURL.appendingPathComponent("all.css")
125-
try writeFile(cssData, to: cssURL)
123+
let destinationURL = outputDirectoryURL.appendingPathComponent("all.css")
124+
125+
func fetchRemoteCSS() throws -> Data {
126+
let url = URL(string: "https://raw.githubusercontent.com/SwiftDocOrg/swift-doc/master/Resources/all.min.css")!
127+
return try Data(contentsOf: url)
128+
}
129+
130+
#if swift(>=5.3)
131+
if let resourceURL = Bundle.module.url(forResource: "all.min", withExtension: "css") {
132+
if !fileManager.fileExists(atPath: destinationURL.path) {
133+
try fileManager.copyItem(at: resourceURL, to: destinationURL)
134+
}
135+
} else {
136+
let cssData = try fetchRemoteCSS()
137+
try writeFile(cssData, to: destinationURL)
138+
}
139+
#else
140+
let cssData = try fetchRemoteCSS()
141+
try writeFile(cssData, to: destinationURL)
142+
#endif
126143
}
127144

128145
} catch {
@@ -131,8 +148,3 @@ extension SwiftDoc {
131148
}
132149
}
133150
}
134-
135-
func fetchRemoteCSS() throws -> Data {
136-
let url = URL(string: "https://raw.githubusercontent.com/SwiftDocOrg/swift-doc/master/Resources/all.min.css")!
137-
return try Data(contentsOf: url)
138-
}

0 commit comments

Comments
 (0)