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

Commit 44c3026

Browse files
authored
Load CSS from package resource when available (#192)
* Load CSS from package resource when available * Fix warning: using '_' to ignore the result of a Void-returning function is redundant * Add Changelog entry for #192
1 parent 6550c84 commit 44c3026

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
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",

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929

3030
- Changed GitHub Action to use prebuilt Docker image.
3131
#185 by @mattt and @MaxDesiatov.
32+
- Changed build command to load CSS from package resource when available.
33+
#192 by @mattt.
3234

3335
## [1.0.0-beta.4] - 2020-07-31
3436

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ let package = Package(
4040
.product(name: "SwiftSyntaxHighlighter", package: "SwiftSyntaxHighlighter"),
4141
.product(name: "Logging", package: "swift-log"),
4242
.product(name: "LoggingGitHubActions", package: "LoggingGitHubActions")
43+
],
44+
resources: [
45+
.copy("Resources")
4346
]
4447
),
4548
.target(

Sources/SwiftDoc/SourceFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public struct SourceFile: Hashable, Codable {
4545
sourceLocationConverter = SourceLocationConverter(file: url.path(relativeTo: directory), tree: tree)
4646
super.init()
4747

48-
_ = walk(tree)
48+
walk(tree)
4949

5050
assert(context.isEmpty)
5151
}
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)