diff --git a/Changelog.md b/Changelog.md index 7eb28fcf..12c639eb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed public extensions exposing nested code of all access levels. #195 by @Tunous. +- Fixed broken links in the relationship graph. + #226 by @Lukas-Stuehrk. ### Changed diff --git a/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift b/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift index fac1bcd4..a25fa93f 100644 --- a/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift +++ b/Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift @@ -36,13 +36,13 @@ extension Symbol { return node } - func graph(in module: Module, baseURL: String) -> Graph { + func graph(in module: Module, baseURL: String, includingChildren symbolFilter: (Symbol) -> Bool) -> Graph { var graph = Graph(directed: true) do { var node = self.node - if !(api is Unknown) { + if !(api is Unknown) && symbolFilter(self) { node.href = path(for: self, with: baseURL) } @@ -61,7 +61,7 @@ extension Symbol { guard self != symbol else { continue } var node = symbol.node - if !(symbol.api is Unknown) { + if !(symbol.api is Unknown) && symbolFilter(symbol) { node.href = path(for: symbol, with: baseURL) } graph.append(node) diff --git a/Sources/swift-doc/Supporting Types/Components/Relationships.swift b/Sources/swift-doc/Supporting Types/Components/Relationships.swift index 8febf849..7e647134 100644 --- a/Sources/swift-doc/Supporting Types/Components/Relationships.swift +++ b/Sources/swift-doc/Supporting Types/Components/Relationships.swift @@ -30,16 +30,18 @@ struct Relationships: Component { var symbol: Symbol let baseURL: String var inheritedTypes: [Symbol] + let symbolFilter: (Symbol) -> Bool - init(of symbol: Symbol, in module: Module, baseURL: String) { + init(of symbol: Symbol, in module: Module, baseURL: String, includingChildren symbolFilter: @escaping (Symbol) -> Bool) { self.module = module self.symbol = symbol self.inheritedTypes = module.interface.typesInherited(by: symbol) + module.interface.typesConformed(by: symbol) self.baseURL = baseURL + self.symbolFilter = symbolFilter } var graphHTML: HypertextLiteral.HTML? { - var graph = symbol.graph(in: module, baseURL: baseURL) + var graph = symbol.graph(in: module, baseURL: baseURL, includingChildren: symbolFilter) guard !graph.edges.isEmpty else { return nil } graph.aspectRatio = 0.125 diff --git a/Sources/swift-doc/Supporting Types/Pages/TypePage.swift b/Sources/swift-doc/Supporting Types/Pages/TypePage.swift index b3bee3f7..345acefb 100644 --- a/Sources/swift-doc/Supporting Types/Pages/TypePage.swift +++ b/Sources/swift-doc/Supporting Types/Pages/TypePage.swift @@ -28,7 +28,7 @@ struct TypePage: Page { Heading { symbol.id.description } Documentation(for: symbol, in: module, baseURL: baseURL) - Relationships(of: symbol, in: module, baseURL: baseURL) + Relationships(of: symbol, in: module, baseURL: baseURL, includingChildren: symbolFilter) Members(of: symbol, in: module, baseURL: baseURL, symbolFilter: symbolFilter) Requirements(of: symbol, in: module, baseURL: baseURL) } @@ -42,7 +42,7 @@ struct TypePage: Page { \#(Documentation(for: symbol, in: module, baseURL: baseURL).html) - \#(Relationships(of: symbol, in: module, baseURL: baseURL).html) + \#(Relationships(of: symbol, in: module, baseURL: baseURL, includingChildren: symbolFilter).html) \#(Members(of: symbol, in: module, baseURL: baseURL, symbolFilter: symbolFilter).html) \#(Requirements(of: symbol, in: module, baseURL: baseURL).html) """#