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

Bugfix/relative links #127

Merged
merged 13 commits into from
Jul 27, 2020
Merged
18 changes: 2 additions & 16 deletions Sources/swift-doc/Supporting Types/Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ func path(for symbol: Symbol, with baseURL: String) -> String {
}

func path(for identifier: CustomStringConvertible, with baseURL: String) -> String {
var urlComponents = URLComponents(string: baseURL)
urlComponents = urlComponents?.appendingPathComponent("\(identifier)")
guard let string = urlComponents?.string else {
let url = URL(string: baseURL)?.appendingPathComponent("\(identifier)")
guard let string = url?.absoluteString else {
logger.critical("Unable to construct path for \(identifier) with baseURL \(baseURL)")
fatalError()
}
Expand All @@ -65,16 +64,3 @@ func writeFile(_ data: Data, to url: URL) throws {
try data.write(to: url)
try fileManager.setAttributes([.posixPermissions: 0o744], ofItemAtPath: url.path)
}

// MARK: -

fileprivate extension URLComponents {
func appendingPathComponent(_ component: String) -> URLComponents? {
var urlComponents = self
var pathComponents = urlComponents.path.split(separator: "/").map { "\($0)" }
pathComponents.append(component)
urlComponents.path = "/" + pathComponents.joined(separator: "/")

return urlComponents
}
}
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
format:
description: "The output format (commonmark or html)"
default: "commonmark"
base-url:
description: "The base URL for all relative URLs generated in documents"
required: false
default: "./"
output:
description: "The path for generated output"
required: true
Expand All @@ -26,6 +30,8 @@ runs:
"${{ inputs.inputs }}",
--format,
"${{ inputs.format }}",
--base-url,
"${{ inputs.base-url }}",
--module-name,
"${{ inputs.module-name }}",
--output,
Expand Down