Skip to content

Commit 2809e81

Browse files
authored
Update navigator image references to the correct relative path (#925)
rdar://128397787
1 parent b1c29d3 commit 2809e81

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -1017,12 +1017,11 @@ extension NavigatorIndex {
10171017
if emitJSONRepresentation {
10181018
let renderIndex = RenderIndex.fromNavigatorIndex(navigatorIndex, with: self)
10191019

1020-
let jsonEncoder = JSONEncoder()
1021-
if shouldPrettyPrintOutputJSON {
1022-
jsonEncoder.outputFormatting = [.sortedKeys, .prettyPrinted]
1023-
} else {
1024-
jsonEncoder.outputFormatting = [.sortedKeys]
1025-
}
1020+
let jsonEncoder = RenderJSONEncoder.makeEncoder(
1021+
prettyPrint: shouldPrettyPrintOutputJSON,
1022+
assetPrefixComponent: bundleIdentifier.split(separator: "/").joined(separator: "-")
1023+
)
1024+
jsonEncoder.outputFormatting.insert(.sortedKeys)
10261025

10271026
let jsonNavigatorIndexURL = outputURL.appendingPathComponent("index.json")
10281027
do {

Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift

+28-1
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,34 @@ Root
11621162
XCTAssertNil(availabilityDB.get(type: String.self, forKey: "content"))
11631163
}
11641164

1165-
func testNavigatorIndexDifferenHasherGeneration() throws {
1165+
func testCustomIconsInNavigator() throws {
1166+
let (bundle, context) = try testBundleAndContext(named: "BookLikeContent") // This content has a @PageImage with the "icon" purpose
1167+
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
1168+
let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext)
1169+
1170+
let targetURL = try createTemporaryDirectory()
1171+
let builder = NavigatorIndex.Builder(outputURL: targetURL, bundleIdentifier: bundle.identifier, sortRootChildrenByName: true)
1172+
builder.setup()
1173+
1174+
for identifier in context.knownPages {
1175+
let source = context.documentURL(for: identifier)
1176+
let entity = try context.entity(with: identifier)
1177+
let renderNode = try XCTUnwrap(converter.renderNode(for: entity, at: source))
1178+
try builder.index(renderNode: renderNode)
1179+
}
1180+
1181+
builder.finalize()
1182+
1183+
let renderIndexData = try Data(contentsOf: targetURL.appendingPathComponent("index.json"))
1184+
let renderIndex = try JSONDecoder().decode(RenderIndex.self, from: renderIndexData)
1185+
1186+
let imageReference = try XCTUnwrap(renderIndex.references["plus.svg"])
1187+
XCTAssertEqual(imageReference.asset.variants.values.map(\.path).sorted(), [
1188+
"/images/\(bundle.identifier)/plus.svg",
1189+
])
1190+
}
1191+
1192+
func testNavigatorIndexDifferentHasherGeneration() throws {
11661193
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
11671194
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
11681195
let converter = DocumentationContextConverter(bundle: bundle, context: context, renderContext: renderContext)

Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ final class RenderIndexTests: XCTestCase {
704704
"identifier" : "plus.svg",
705705
"variants" : [
706706
{
707-
"url" : "\/images\/plus.svg",
707+
"url" : "\/images\/org.swift.docc.Book\/plus.svg",
708708
"traits" : [
709709
"1x",
710710
"light"

0 commit comments

Comments
 (0)