Implemented the DocC archives support for the middleware #2

Merged
javier merged 29 commits from middleware/xcode-documentation into main 2025-09-26 23:54:08 +00:00
2 changed files with 19 additions and 13 deletions
Showing only changes of commit a5305e3e6f - Show all commits
@@ -18,8 +18,8 @@ struct PrepareURIPathUseCase {
// MARK: Type aliases
/// A pseudo-type that contains the archive name and URI path, plus the resource URI paths used for routing the documentation contents.
typealias PreparedURIPaths = (archiveName: String, archivePath: String, resourcePath: String)
/// A pseudo-type that contains the archive name, reference and URI path, plus the resource URI and relative paths used for routing the documentation contents.
typealias PreparedURIPaths = (archiveName: String, archiveReference: String, archivePath: String, resourcePath: String)
// MARK: Properties
@@ -43,35 +43,41 @@ struct PrepareURIPathUseCase {
///
/// The necessary data to extract from a given URI path is:
/// 1. the `DocC` documentation archive name;
/// 2. the `DocC` documentation archive URI path;
/// 3. the `DocC` documentation resource URI path.
/// 2. the `DocC` documentation archive reference;
/// 3. the `DocC` documentation archive URI path;
/// 4. the `DocC` documentation resource URI path.
///
/// > important: It is assumed that the `uriPath` parameter is a URI path that does not contain any percent encoded strings.
///
/// - Parameter uriPath: A URI path to extract the data from.
/// - Returns: A pseudo-type that contains the archive' name and URI path, plus the resource URI paths.
/// - Returns: A pseudo-type that contains the archive' name, reference and URI path, plus the resource URI paths.
func callAsFunction(_ uriPath: String) -> PreparedURIPaths? {
guard let uriRest = restOfURIPath(from: uriPath) else {
return nil
}
let documentationName = uriRest
let archiveName = uriRest
.split(separator: .Path.forwardSlash)
.map(String.init)
.first
let archiveName: String = if let documentationName {
documentationName.lowercased()
let archiveReference: String = if let archiveName {
archiveName.lowercased()
} else {
.empty
}
let archivePath: String = if let documentationName {
.init(format: .Format.Path.archive, documentationName)
let archivePath: String = if let archiveName {
.init(format: .Format.Path.archive, archiveName)
} else {
.empty
}
return (archiveName, archivePath, uriRest)
return (
archiveName ?? .empty,
archiveReference,
archivePath,
uriRest
)
}
}
@@ -134,8 +134,8 @@ private extension Input {
private extension Output {
/// A list of expected outputs for the URI path samples, regardless their match against suffixed or not suffixed root URI paths.
static let prepareURIPaths: [PrepareURIPathUseCase.PreparedURIPaths?] = [
("somearchive", "/SomeArchive.doccarchive", "/SomeArchive/some/content/path"),
(.empty, .empty, .Path.forwardSlash),
("SomeArchive", "somearchive", "/SomeArchive.doccarchive", "/SomeArchive/some/content/path"),
(.empty, .empty, .empty, .Path.forwardSlash),
nil
]
}