Skip to content

Commit 165309d

Browse files
chore: documentation folder should be driven by variable (#386)
Cleans up all references to the `”documentation”` and `”tutorial`”’ subpaths to be driven by the property in `NodeURLGenerator`.
1 parent 5208c8d commit 165309d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ struct PathHierarchy {
434434
/// - Returns: The node to start the relative search relative to.
435435
private func findRoot(parentID: ResolvedIdentifier?, remaining: inout ArraySlice<PathComponent>, isAbsolute: Bool, onlyFindSymbols: Bool) throws -> Node {
436436
// If the first path component is "tutorials" or "documentation" then that
437-
let isKnownTutorialPath = remaining.first!.full == "tutorials"
438-
let isKnownDocumentationPath = remaining.first!.full == "documentation"
437+
let isKnownTutorialPath = remaining.first!.full == NodeURLGenerator.Path.tutorialsFolderName
438+
let isKnownDocumentationPath = remaining.first!.full == NodeURLGenerator.Path.documentationFolderName
439439
if isKnownDocumentationPath || isKnownTutorialPath {
440440
// Drop that component since it isn't represented in the path hierarchy.
441441
remaining.removeFirst()
@@ -626,7 +626,9 @@ extension PathHierarchy {
626626
static func parse(path: String) -> (components: [PathComponent], isAbsolute: Bool) {
627627
guard !path.isEmpty else { return ([], true) }
628628
var components = path.split(separator: "/", omittingEmptySubsequences: true)
629-
let isAbsolute = path.first == "/" || components.first == "documentation" || components.first == "tutorials"
629+
let isAbsolute = path.first == "/"
630+
|| String(components.first ?? "") == NodeURLGenerator.Path.documentationFolderName
631+
|| String(components.first ?? "") == NodeURLGenerator.Path.tutorialsFolderName
630632

631633
if let hashIndex = components.last?.firstIndex(of: "#") {
632634
let last = components.removeLast()

Sources/SwiftDocC/Infrastructure/NodeURLGenerator.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ public struct NodeURLGenerator {
165165
public func urlForReference(_ reference: ResolvedTopicReference, fileSafePath safePath: String) -> URL {
166166
if safePath.isEmpty {
167167
// Return the root path for the conversion: /documentation.json
168-
return baseURL.appendingPathComponent("documentation", isDirectory: false)
168+
return baseURL.appendingPathComponent(
169+
NodeURLGenerator.Path.documentationFolderName,
170+
isDirectory: false
171+
)
169172
} else {
170173
let url = baseURL.appendingPathComponent(safePath, isDirectory: false)
171174
return url.withFragment(reference.url.fragment)

0 commit comments

Comments
 (0)