| 1 | | /// The front page of a run that has no coverage (DESIGN.md D8): it says so, and why. |
| 2 | | public struct UnavailablePage: Sendable { |
| 3 | | public static let sitePath = IndexPage.sitePath |
| 4 | | public static let notice = "Coverage is not available for this commit." |
| 5 | | |
| 6 | | private let title: String |
| 7 | | private let reason: String |
| 8 | | private let commit: String? |
| 9 | | private let subject: String? |
| 10 | | |
| 11 | | /// - Parameters: |
| 12 | | /// - title: the project's name, shown as given. |
| 13 | | /// - reason: why there is no coverage; escaped, since CI supplies it. |
| 14 | | /// - commit: the commit the run was built from, shown as given. |
| 15 | | /// - subject: the commit's first message line. |
| 16 | 7 | public init(title: String, reason: String, commit: String?, subject: String?) { |
| 17 | 7 | self.title = title |
| 18 | 7 | self.reason = reason |
| 19 | 7 | self.commit = commit |
| 20 | 7 | self.subject = subject |
| 21 | 7 | } |
| 22 | | |
| 23 | 7 | public var html: String { |
| 24 | 7 | """ |
| 25 | 7 | <!doctype html> |
| 26 | 7 | <html lang="en"> |
| 27 | 7 | <head> |
| 28 | 7 | <meta charset="utf-8"> |
| 29 | 7 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 30 | 7 | <title>\(escapingHTML(title))</title> |
| 31 | 7 | <link rel="stylesheet" href="\(SiteStylesheet.fileName)"> |
| 32 | 7 | </head> |
| 33 | 7 | <body class="unavailable-page"> |
| 34 | 7 | <header class="page-header"> |
| 35 | 7 | <h1 class="site-title">\(escapingHTML(title))</h1> |
| 36 | 7 | \(commitMarkup) |
| 37 | 7 | </header> |
| 38 | 7 | <main> |
| 39 | 7 | <p class="notice">\(Self.notice)</p> |
| 40 | 7 | <p class="reason">\(escapingHTML(reason))</p> |
| 41 | 7 | </main> |
| 42 | 7 | </body> |
| 43 | 7 | </html> |
| 44 | 7 | |
| 45 | 7 | """ |
| 46 | 7 | } |
| 47 | | |
| 48 | 7 | private var commitMarkup: String { |
| 49 | 14 | let parts = [commit, subject].compactMap { $0 }.map(escapingHTML) |
| 50 | 7 | guard !parts.isEmpty else { return "" } |
| 51 | 6 | return #"<p class="totals">"# + parts.joined(separator: " · ") + "</p>" |
| 52 | 7 | } |
| 53 | | } |