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

Commit a4ecfb4

Browse files
committed
Add CSS file download
1 parent f03b6b9 commit a4ecfb4

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Sources/swift-doc/Subcommands/Generate.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,22 @@ extension SwiftDoc {
110110
try $0.value.write(to: url, format: format, baseURL: options.baseURL)
111111
}
112112
}
113+
114+
if case .html = format {
115+
let cssData = try fetchRemoteCSS()
116+
let cssURL = outputDirectoryURL.appendingPathComponent("all.css")
117+
try writeFile(cssData, to: cssURL)
118+
}
119+
120+
113121
} catch {
114122
logger.error("\(error)")
115123
}
116124
}
117125
}
118126
}
127+
128+
func fetchRemoteCSS() throws -> Data {
129+
let url = URL(string: "https://raw.githubusercontent.com/kaishin/swift-doc/reda/css-build/Resources/all.css")!
130+
return try Data(contentsOf: url)
131+
}

Sources/swift-doc/Supporting Types/Layout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func layout(_ page: Page, baseURL: String) -> HTML {
1212
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1313
<title>\#(page.module.name) - \#(page.title)</title>
1414
<base href="\#(baseURL)"/>
15-
<link rel="stylesheet" href="index.css" media="all" />
15+
<link rel="stylesheet" type="text/css" href="all.css" media="all" />
1616
</head>
1717
<body>
1818
<header>

Sources/swift-doc/Supporting Types/Page.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ extension Page {
2828
data = layout(self, baseURL: baseURL).description.data(using: .utf8)
2929
}
3030

31-
let fileManager = FileManager.default
32-
try fileManager.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true, attributes: [.posixPermissions: 0o744])
31+
guard let filedata = data else { return }
3332

34-
try data?.write(to: url)
35-
try fileManager.setAttributes([.posixPermissions: 0o744], ofItemAtPath: url.path)
33+
try writeFile(filedata, to: url)
3634
}
3735
}
3836

@@ -43,3 +41,11 @@ func path(for symbol: Symbol) -> String {
4341
func path(for identifier: CustomStringConvertible) -> String {
4442
return "\(identifier)".replacingOccurrences(of: ".", with: "_")
4543
}
44+
45+
func writeFile(_ data: Data, to url: URL) throws {
46+
let fileManager = FileManager.default
47+
try fileManager.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true, attributes: [.posixPermissions: 0o744])
48+
49+
try data.write(to: url)
50+
try fileManager.setAttributes([.posixPermissions: 0o744], ofItemAtPath: url.path)
51+
}

0 commit comments

Comments
 (0)