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

Commit f3e2185

Browse files
authored
Merge pull request #65 from kean/feature-base-url
Add baseURL option to generate command
2 parents 99acf1f + 3651c1f commit f3e2185

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

Changelog.md

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

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added `--base-url` option.
13+
#65 by @kean.
14+
1015
## [1.0.0-beta.2] - 2020-04-08
1116

1217
### Changed

Sources/swift-doc/Subcommands/Generate.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ extension SwiftDoc {
2929
default: .commonmark,
3030
help: "The output format")
3131
var format: Format
32+
33+
@Option(name: .customLong("base-url"),
34+
default: "/",
35+
help: "The base URL used for all relative URLs in generated documents.")
36+
var baseURL: String
3237
}
3338

3439
static var configuration = CommandConfiguration(abstract: "Generates Swift documentation")
@@ -79,7 +84,7 @@ extension SwiftDoc {
7984
}
8085

8186
let url = outputDirectoryURL.appendingPathComponent(filename)
82-
try page.write(to: url, format: format)
87+
try page.write(to: url, format: format, baseURL: options.baseURL)
8388
} else {
8489
switch format {
8590
case .commonmark:
@@ -102,7 +107,7 @@ extension SwiftDoc {
102107
}
103108

104109
let url = outputDirectoryURL.appendingPathComponent(filename)
105-
try $0.value.write(to: url, format: format)
110+
try $0.value.write(to: url, format: format, baseURL: options.baseURL)
106111
}
107112
}
108113
} catch {

Sources/swift-doc/Supporting Types/Components/Relationships.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct Relationships: Component {
113113
"""#
114114
} else {
115115
return #"""
116-
<dt class="\#(descriptor)"><code><a href="/\#(path(for: symbol))">\#(symbol.id)</a></code></dt>
116+
<dt class="\#(descriptor)"><code><a href="\#(path(for: symbol))">\#(symbol.id)</a></code></dt>
117117
<dd>\#(commonmark: symbol.documentation?.summary ?? "")</dd>
118118
"""#
119119
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public func linkCodeElements(of html: String, for symbol: Symbol, in module: Mod
1212
let candidate = candidates.filter({ $0 != symbol }).first
1313
{
1414
let a = Element(name: "a")
15-
a["href"] = "/" + path(for: candidate)
15+
a["href"] = path(for: candidate)
1616
element.wrap(inside: a)
1717
}
1818
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import HypertextLiteral
22
import Foundation
33

4-
func layout(_ page: Page) -> HTML {
4+
func layout(_ page: Page, baseURL: String) -> HTML {
55
let html = page.html
66

77
return #"""
@@ -11,13 +11,14 @@ func layout(_ page: Page) -> HTML {
1111
<meta charset="UTF-8">
1212
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1313
<title>\#(page.module.name) - \#(page.title)</title>
14+
<base href="\#(baseURL)"/>
1415
<style type="text/css">
1516
\#(unsafeUnescaped: css)
1617
</style>
1718
</head>
1819
<body>
1920
<header>
20-
<a href="/">
21+
<a href="\#(baseURL)">
2122
<strong>
2223
\#(page.module.name)
2324
</strong>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ extension Page {
1919
}
2020

2121
extension Page {
22-
func write(to url: URL, format: SwiftDoc.Generate.Format) throws {
22+
func write(to url: URL, format: SwiftDoc.Generate.Format, baseURL: String) throws {
2323
let data: Data?
2424
switch format {
2525
case .commonmark:
2626
data = document.render(format: .commonmark).data(using: .utf8)
2727
case .html:
28-
data = layout(self).description.data(using: .utf8)
28+
data = layout(self, baseURL: baseURL).description.data(using: .utf8)
2929
}
3030

3131
let fileManager = FileManager.default

0 commit comments

Comments
 (0)