Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/InContextCore/Handler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension Handler: Fingerprintable {
}

func process(file: File, outputURL: URL) async throws -> ImporterResult {
return try await importer.process(file: file, settings: settings, outputURL: outputURL)
return try await T.process(file: file, settings: settings, outputURL: outputURL)
}

}
6 changes: 3 additions & 3 deletions Sources/InContextCore/Importers/CopyImporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class CopyImporter: Importer {
return EmptySettings()
}

func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {
static func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {
// TODO: Consider whether these actually get a tracking context that lets them add to the site instead of
// returning documents. That feels like it might be cleaner and more flexible?
// That approach would have the benefit of meaning that we don't really need to do significant path
Expand Down
6 changes: 3 additions & 3 deletions Sources/InContextCore/Importers/IgnoreImporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class IgnoreImporter: Importer {
return EmptySettings()
}

func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {
static func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {
return ImporterResult()
}

Expand Down
12 changes: 6 additions & 6 deletions Sources/InContextCore/Importers/ImageImporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ class ImageImporter {

extension ImageImporter: Importer {

func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {
static func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {

throw InContextError.internalInconsistency("Unsupported")

Expand All @@ -364,9 +364,9 @@ extension ImageImporter: Importer {

extension ImageImporter: Importer {

func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {
static func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {

let fileURL = file.url

Expand Down
6 changes: 3 additions & 3 deletions Sources/InContextCore/Importers/Importer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ protocol Importer {
var version: Int { get }

func settings(for configuration: [String: Any]) throws -> Settings
func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult
static func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult

}

Expand Down
14 changes: 7 additions & 7 deletions Sources/InContextCore/Importers/MarkdownImporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ class MarkdownImporter: Importer {
defaultTemplate: try configuration.requiredValue(for: "defaultTemplate"))
}

func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {

static func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {
let fileURL = file.url
let details = fileURL.basenameDetails()
let frontmatter = try FrontmatterDocument(contentsOf: fileURL, generateHTML: true)

// Merge the details and metadata.
var metadata = [AnyHashable: Any]()
metadata["title"] = details.title
metadata.merge(frontmatter.metadata) { $1 }

let category: String = try metadata.value(for: "category", default: settings.defaultCategory)

let document = try Document(url: fileURL.siteURL,
parent: fileURL.parentURL,
category: category,
Expand Down
1 change: 0 additions & 1 deletion Sources/InContextCore/Importers/VideoImporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ class VideoImporter {
}

}

6 changes: 3 additions & 3 deletions Sources/InContextCore/Importers/VideoImporterLinux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import Foundation

extension VideoImporter: Importer {

func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {
static func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {

throw InContextError.internalInconsistency("Unsupported")
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/InContextCore/Importers/VideoImporterMac.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import Foundation

extension VideoImporter: Importer {

func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {
static func process(file: File,
settings: Settings,
outputURL: URL) async throws -> ImporterResult {

let fileURL = file.url

Expand Down Expand Up @@ -134,7 +134,7 @@ extension VideoImporter: Importer {
return ImporterResult(document: document, assets: [Asset(fileURL: videoURL), Asset(fileURL: thumbnailURL)])
}

func thumbnail(asset: AVAsset, destinationURL: URL) async throws {
static func thumbnail(asset: AVAsset, destinationURL: URL) async throws {
let generator = AVAssetImageGenerator(asset: asset)
generator.appliesPreferredTrackTransform = true
let time = CMTime(seconds: 1, preferredTimescale: 1)
Expand All @@ -154,10 +154,10 @@ extension VideoImporter: Importer {
}

// https://developer.apple.com/documentation/avfoundation/media_reading_and_writing/exporting_video_to_alternative_formats
func export(video: AVAsset,
withPreset preset: String = AVAssetExportPresetHighestQuality,
toFileType outputFileType: AVFileType = .mov,
atURL outputURL: URL) async throws {
static func export(video: AVAsset,
withPreset preset: String = AVAssetExportPresetHighestQuality,
toFileType outputFileType: AVFileType = .mov,
atURL outputURL: URL) async throws {

// Check the compatibility of the preset to export the video to the output file type.
guard await AVAssetExportSession.compatibility(ofExportPreset: preset,
Expand Down
18 changes: 8 additions & 10 deletions Tests/InContextTests/Tests/MarkdownImporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ title: Fromage

These are the contents of the file.
""")
let importer = MarkdownImporter()
let result = try await importer.process(file: file,
settings: .init(defaultCategory: "general",
defaultTemplate: "posts.html"),
outputURL: defaultSourceDirectory.site.filesURL)
let result = try await MarkdownImporter.process(file: file,
settings: .init(defaultCategory: "general",
defaultTemplate: "posts.html"),
outputURL: defaultSourceDirectory.site.filesURL)
XCTAssertNotNil(result.document)
XCTAssertEqual(result.document!.metadata["title"] as? String, "Fromage")
}
Expand All @@ -68,11 +67,10 @@ steps:
defaultTemplate: posts.html
""")
let file = try defaultSourceDirectory.add("cheese/index.markdown", location: .content, contents: "Contents!")
let importer = MarkdownImporter()
let result = try await importer.process(file: file,
settings: .init(defaultCategory: "general",
defaultTemplate: "posts.html"),
outputURL: defaultSourceDirectory.site.filesURL)
let result = try await MarkdownImporter.process(file: file,
settings: .init(defaultCategory: "general",
defaultTemplate: "posts.html"),
outputURL: defaultSourceDirectory.site.filesURL)
XCTAssertNotNil(result.document)
XCTAssertEqual(result.document!.metadata["title"] as? String, "Cheese")
}
Expand Down