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

Load CSS from package resource when available #192

Merged
merged 3 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"not dead"
],
"scripts": {
"watch": "postcss -w ../Assets/**/*.css -o ../Resources/all.min.css --config ./postcss.config.js"
"watch": "postcss -w ../Assets/**/*.css -o ../Sources/swift-doc/Resources/all.min.css --config ./postcss.config.js"
},
"dependencies": {
"cssnano": "^4.1.10",
Expand Down
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

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

Expand Down
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ let package = Package(
.product(name: "SwiftSyntaxHighlighter", package: "SwiftSyntaxHighlighter"),
.product(name: "Logging", package: "swift-log"),
.product(name: "LoggingGitHubActions", package: "LoggingGitHubActions")
],
resources: [
.copy("Resources")
]
),
.target(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDoc/SourceFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public struct SourceFile: Hashable, Codable {
sourceLocationConverter = SourceLocationConverter(file: url.path(relativeTo: directory), tree: tree)
super.init()

_ = walk(tree)
walk(tree)

assert(context.isEmpty)
}
Expand Down
28 changes: 20 additions & 8 deletions Sources/swift-doc/Subcommands/Generate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,26 @@ extension SwiftDoc {
}

if case .html = format {
let cssData = try fetchRemoteCSS()
let cssURL = outputDirectoryURL.appendingPathComponent("all.css")
try writeFile(cssData, to: cssURL)
let destinationURL = outputDirectoryURL.appendingPathComponent("all.css")

func fetchRemoteCSS() throws -> Data {
let url = URL(string: "https://raw.githubusercontent.com/SwiftDocOrg/swift-doc/master/Resources/all.min.css")!
return try Data(contentsOf: url)
}

#if swift(>=5.3)
if let resourceURL = Bundle.module.url(forResource: "all.min", withExtension: "css") {
if !fileManager.fileExists(atPath: destinationURL.path) {
try fileManager.copyItem(at: resourceURL, to: destinationURL)
}
} else {
let cssData = try fetchRemoteCSS()
try writeFile(cssData, to: destinationURL)
}
#else
let cssData = try fetchRemoteCSS()
try writeFile(cssData, to: destinationURL)
#endif
}

} catch {
Expand All @@ -131,8 +148,3 @@ extension SwiftDoc {
}
}
}

func fetchRemoteCSS() throws -> Data {
let url = URL(string: "https://raw.githubusercontent.com/SwiftDocOrg/swift-doc/master/Resources/all.min.css")!
return try Data(contentsOf: url)
}