@@ -2456,6 +2456,91 @@ class ConvertActionTests: XCTestCase {
2456
2456
expectedOutput. assertExist ( at: result. outputs [ 0 ] , fileManager: FileManager . default)
2457
2457
}
2458
2458
2459
+ // Tests that custom templates are injected into the extra index.html files generated for static hosting.
2460
+ func testConvertWithCustomTemplatesForStaticHosting( ) throws {
2461
+ let info = InfoPlist ( displayName: " TestConvertWithCustomTemplatesForStaticHosting " , identifier: " com.test.example " )
2462
+ let index = TextFile ( name: " index.html " , utf8Content: """
2463
+ <!DOCTYPE html>
2464
+ <html lang= " en " >
2465
+ <head>
2466
+ <title>Test</title>
2467
+ </head>
2468
+ <body data-color-scheme= " auto " ><p>test for custom templates in static hosting</p></body>
2469
+ </html>
2470
+ """ )
2471
+ let template = Folder ( name: " template " , content: [ index] )
2472
+ let header = TextFile ( name: " header.html " , utf8Content: """
2473
+ <header>custom text for header</header>
2474
+ """ )
2475
+ let footer = TextFile ( name: " footer.html " , utf8Content: """
2476
+ <footer>custom text for footer</footer>
2477
+ """ )
2478
+
2479
+ // Adding this page will generate a file named:
2480
+ // /documentation/testconvertwithcustomtemplatesforstatichosting/index.html
2481
+ // ...which should have the custom header/footer if they're propagated correctly.
2482
+ let technologyPage = TextFile ( name: " TestConvertWithCustomTemplatesForStaticHosting.md " , utf8Content: """
2483
+ # TestConvertWithCustomTemplatesForStaticHosting
2484
+
2485
+ @Metadata {
2486
+ @TechnologyRoot
2487
+ }
2488
+
2489
+ An abstract.
2490
+
2491
+ ## Overview
2492
+
2493
+ Text for a paragraph.
2494
+ """ )
2495
+ let bundle = Folder ( name: " TestConvertWithCustomTemplatesForStaticHosting.docc " , content: [
2496
+ info,
2497
+ header,
2498
+ footer,
2499
+ technologyPage
2500
+ ] )
2501
+
2502
+ let tempURL = try createTemporaryDirectory ( )
2503
+ let targetURL = tempURL. appendingPathComponent ( " target " , isDirectory: true )
2504
+
2505
+ let bundleURL = try bundle. write ( inside: tempURL)
2506
+ let templateURL = try template. write ( inside: tempURL)
2507
+
2508
+ let dataProvider = try LocalFileSystemDataProvider ( rootURL: bundleURL)
2509
+
2510
+ var action = try ConvertAction (
2511
+ documentationBundleURL: bundleURL,
2512
+ outOfProcessResolver: nil ,
2513
+ analyze: false ,
2514
+ targetDirectory: targetURL,
2515
+ htmlTemplateDirectory: templateURL,
2516
+ emitDigest: false ,
2517
+ currentPlatforms: nil ,
2518
+ dataProvider: dataProvider,
2519
+ fileManager: FileManager . default,
2520
+ temporaryDirectory: createTemporaryDirectory ( ) ,
2521
+ experimentalEnableCustomTemplates: true ,
2522
+ transformForStaticHosting: true
2523
+ )
2524
+ let result = try action. perform ( logHandle: . standardOutput)
2525
+
2526
+ // The custom template contents should be wrapped in <template> tags and
2527
+ // prepended to the <body>
2528
+ let expectedIndex = TextFile ( name: " index.html " , utf8Content: """
2529
+ <!DOCTYPE html>
2530
+ <html lang= " en " >
2531
+ <head>
2532
+ <title>Test</title>
2533
+ </head>
2534
+ <body data-color-scheme= " auto " ><template id= " custom-footer " > \( footer. utf8Content) </template><template id= " custom-header " > \( header. utf8Content) </template><p>test for custom templates in static hosting</p></body>
2535
+ </html>
2536
+ """ )
2537
+
2538
+ let expectedTechnologyFolder = Folder ( name: " TestConvertWithCustomTemplatesForStaticHosting " . lowercased ( ) , content: [ expectedIndex] )
2539
+ let expectedDocsFolder = Folder ( name: " documentation " , content: [ expectedTechnologyFolder] )
2540
+ let expectedOutput = Folder ( name: " .docc-build " , content: [ expectedDocsFolder] )
2541
+ expectedOutput. assertExist ( at: result. outputs [ 0 ] , fileManager: FileManager . default)
2542
+ }
2543
+
2459
2544
func testConvertWithThemeSettings( ) throws {
2460
2545
let info = InfoPlist ( displayName: " TestConvertWithThemeSettings " , identifier: " com.test.example " )
2461
2546
let index = TextFile ( name: " index.html " , utf8Content: """
0 commit comments