55 lines
1.4 KiB
Swift
55 lines
1.4 KiB
Swift
import Foundation
|
|
|
|
struct Site {
|
|
|
|
static let linkPreviewDesiredImageWidth = 1600
|
|
|
|
let elements: [SiteElement]
|
|
|
|
let metadata: Metadata
|
|
|
|
let inputFolder: URL
|
|
|
|
init?(folder: URL) throws {
|
|
self.inputFolder = folder
|
|
|
|
guard let metadata = try Metadata(in: folder) else {
|
|
return nil
|
|
}
|
|
guard !metadata.languages.isEmpty else {
|
|
throw GenerationError.invalidLanguageSpecification("No languages specified in site.json")
|
|
}
|
|
self.metadata = metadata
|
|
self.elements = try FileSystem.folders(in: folder)
|
|
.filter { !metadata.ignoredSubFolders.contains($0.lastPathComponent) }
|
|
.compactMap { sectionUrl in
|
|
return try Section(
|
|
folder: sectionUrl, path: sectionUrl.lastPathComponent)
|
|
}
|
|
print("Loaded site with \(elements.count) sections and \(metadata.languages.count) languages")
|
|
|
|
// Create example metadata
|
|
_ = try? Page.Metadata(in: folder)
|
|
_ = try? Section.Metadata(in: folder)
|
|
}
|
|
}
|
|
|
|
extension Site: LocalizedMetadataContainer {
|
|
|
|
}
|
|
|
|
extension Site: SiteElement {
|
|
|
|
var sortIndex: Int? { 0 }
|
|
|
|
var sortDate: Date? { nil }
|
|
|
|
var path: String { "" }
|
|
|
|
func cornerText(for language: String) -> String? { nil }
|
|
|
|
func backLinkText(for language: String) throws -> String? {
|
|
localized(for: language).backLinkText
|
|
}
|
|
}
|