2022-08-16 10:39:05 +02:00
|
|
|
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
|
2022-08-19 18:05:06 +02:00
|
|
|
//_ = try? Page.Metadata(in: folder)
|
|
|
|
//_ = try? Section.Metadata(in: folder)
|
2022-08-16 10:39:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|