1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/*
This source file is part of the Swift.org open source project
Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
/**
A structure containing indexing information for a ``RenderNode``.
*/
public struct IndexingRecord: Equatable {
/**
The location of the content for this record.
Top-level pages are an obvious kind of search result in a list-like UI. However,
we may want to put subsections or other important items in the same list of search results.
This location may point to a top-level page or somewhere deeper in the page.
For example, a ``Tutorial`` may have its own search result and each of its ``TutorialSection``s may be a search result as well.
*/
public enum Location: Equatable {
/**
A search result corresponds to a top-level page of documentation.
*/
case topLevelPage(ResolvedTopicReference)
/**
A search result corresponds to something on a page of documentation.
*/
case contained(ResolvedTopicReference, inPage: ResolvedTopicReference)
}
/**
The kind of documentation for a search result.
*/
public struct Kind: RawRepresentable, Equatable {
public var rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
/// A Technology "Overview" page.
public static let overview = Kind(rawValue: "overview")
/// A "Tutorial" page.
public static let tutorial = Kind(rawValue: "tutorial")
/// An "Article" page.
public static let article = Kind(rawValue: "article")
/// A tutorial section.
public static let tutorialSection = Kind(rawValue: "tutorialSection")
/// A symbol page.
public static let symbol = Kind(rawValue: "symbol")
}
/**
The kind of document or section whose text content this record collects.
*/
public let kind: Kind
/**
The location of a search result for this record.
*/
public let location: Location
/**
The title of the document or section.
*/
public let title: String
/**
A summary phrase, sentence, or abstract from a document or section for use in previewing content in search results.
*/
public let summary: String
/**
Headings and subheadings in the document or section.
*/
public let headings: [String]
/**
A concatenation of all other raw text content in the document or section.
> Note: Titles, headings, and abstracts are not included in this string.
*/
public let rawIndexableTextContent: String
/// The availability information for a platform.
public typealias PlatformAvailability = AvailabilityRenderItem
/// Information about the platforms for which the summarized element is available.
public let platforms: [PlatformAvailability]?
init(kind: Kind, location: Location, title: String, summary: String, headings: [String], rawIndexableTextContent: String, platforms: [PlatformAvailability]? = nil) {
self.kind = kind
self.location = location
self.title = title
self.summary = summary
self.headings = headings
self.rawIndexableTextContent = rawIndexableTextContent
self.platforms = platforms
}
}
// MARK: - Codable conformance
extension IndexingRecord: Codable {}
extension IndexingRecord.Location: Codable {
private enum LocationType: String, Codable {
case topLevelPage
case contained
}
private enum CodingKeys: CodingKey {
case type
case reference, inPage
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let type = try container.decode(LocationType.self, forKey: .type)
switch type {
case .topLevelPage:
let reference = try container.decode(ResolvedTopicReference.self, forKey: .reference)
self = .topLevelPage(reference)
case .contained:
let reference = try container.decode(ResolvedTopicReference.self, forKey: .reference)
let inPageReference = try container.decode(ResolvedTopicReference.self, forKey: .inPage)
self = .contained(reference, inPage: inPageReference)
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case .topLevelPage(let reference):
try container.encode(LocationType.topLevelPage, forKey: .type)
try container.encode(reference, forKey: .reference)
case .contained(let reference, let inPage):
try container.encode(LocationType.contained, forKey: .type)
try container.encode(reference, forKey: .reference)
try container.encode(inPage, forKey: .inPage)
}
}
}
extension IndexingRecord.Kind: Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawValue)
}
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
rawValue = try container.decode(String.self)
}
}
|