Skip to content

Commit

Permalink
fix: Add versioning to site.yaml (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmorley authored Sep 1, 2023
1 parent b1f9300 commit d791ffa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/InContextCore/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,25 @@ import Foundation
struct Settings: Decodable {

private enum CodingKeys: String, CodingKey {
case version
case title
case author
case url
case metadata
}

let version: Int
let title: String
let author: String?
let url: URL
let metadata: [String: Any]

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.version = try container.decode(Int.self, forKey: .version)
guard version == 1 else {
throw InContextError.internalInconsistency("Unsupported settings version (\(version)).")
}
self.title = try container.decode(String.self, forKey: .title)
self.author = try container.decodeIfPresent(String.self, forKey: .author)
self.url = try container.decode(URL.self, forKey: .url)
Expand Down
1 change: 1 addition & 0 deletions Tests/InContextTests/Tests/ImageImporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ImageImporterTests: ContentTestCase {
func testExtractTitle() async throws {

_ = try defaultSourceDirectory.add("site.yaml", contents: """
version: 1
title: Example
url: http://example.com
build_steps:
Expand Down
2 changes: 2 additions & 0 deletions Tests/InContextTests/Tests/MarkdownImporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MarkdownImporterTests: ContentTestCase {

func testMarkdownTitleOverride() async throws {
_ = try defaultSourceDirectory.add("site.yaml", contents: """
version: 1
title: Example
url: http://example.com
build_steps:
Expand Down Expand Up @@ -59,6 +60,7 @@ These are the contents of the file.

func testMarkdownTitleFromFile() async throws {
_ = try defaultSourceDirectory.add("site.yaml", contents: """
version: 1
title: Example
url: http://example.com
build_steps:
Expand Down

0 comments on commit d791ffa

Please sign in to comment.