Fix mock content build

This commit is contained in:
Christoph Hagen
2025-04-06 13:29:24 +02:00
parent 80e90c4055
commit 01c49433cd
10 changed files with 42 additions and 26 deletions

View File

@ -1,25 +0,0 @@
import Foundation
extension FileManager {
var documentDirectory: URL {
try! url(
for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil, create: true)
}
}
extension Content {
static let mock: Content = {
let content = Content()
content.files = FileResource.Mock.mockData(content: content)
content.tags = Tag.Mock.mockData(content: content)
content.posts = Post.Mock.mockData(content: content)
content.pages = Page.Mock.mockData(content: content)
return content
}()
}

View File

@ -1,25 +0,0 @@
extension FileResource {
enum Mock {
static func mockData(content: Content) -> [FileResource] {
[
FileResource(content: content, resourceImage: "image1", type: .jpg),
FileResource(content: content, resourceImage: "image2", type: .jpg),
FileResource(content: content, resourceImage: "image3", type: .jpg),
FileResource(content: content, resourceImage: "image4", type: .jpg),
FileResource(
content: content,
id: "my-file.txt",
isExternallyStored: true,
english: "Some text file",
german: "Eine Textdatei")
]
}
}
static var mock: FileResource {
Content.mock.files.first(where: { $0.id == "my-file.txt" })!
}
}

View File

@ -1,40 +0,0 @@
import Foundation
extension Page {
enum Mock {
static func mockData(content: Content) -> [Page] {
[
Page(
content: content,
id: "my-id",
externalLink: nil,
isDraft: true,
createdDate: Date(),
hideDate: false,
startDate: Date().addingTimeInterval(-86400),
endDate: nil,
german: LocalizedPage(
content: content,
urlString: "mein-projekt",
title: "Mein Erstes Projekt",
lastModified: nil,
originalUrl: "projects/electronics/my-first-project/de.html"),
english: LocalizedPage(
content: content,
urlString: "my-project",
title: "My First Project",
lastModified: nil,
originalUrl: "projects/electronics/my-first-project/en.html"),
tags: [
content.tags.first(where: { $0.id == "electronics" })!
])
]
}
static var empty: Page {
Content.mock.pages.first(where: { $0.id == "my-id" })!
}
}
}

View File

@ -1,90 +0,0 @@
extension Post {
enum Mock {
static func mockData(content: Content) -> [Post] {
[
Post(content: content,
id: "empty",
isDraft: true,
createdDate: .now,
startDate: .now,
endDate: nil,
tags: [],
german: .init(
content: content,
text: "Text"),
english: .init(
content: content,
text: "Text"),
linkedPage: nil),
Post(
content: content,
id: "hike",
isDraft: false,
createdDate: .now,
startDate: .now,
endDate: nil,
tags: [
content.tags.first(where: { $0.id == "nature" })!,
content.tags.first(where: { $0.id == "sports" })!,
content.tags.first(where: { $0.id == "hiking" })!
],
german: .init(
content: content,
title: "Eine Wanderung",
text: "Sehr schöne und einsame Tour von Oberau zum Krottenkopf. Abwechslungsreich und stellenweise fordernd, aufgrund der Länge und der Höhenmeter auch anstrengend."),
english: .init(
content: content,
title: "A hike",
text: "Very nice and solitary hike from Oberau to Krottenkopf. Challenging and rewarding, due to the length and height")
),
Post(
content: content,
id: "hike2",
isDraft: true,
createdDate: .now,
startDate: .now.addingTimeInterval(-86400), endDate: .now,
tags: [
content.tags.first(where: { $0.id == "nature" })!,
content.tags.first(where: { $0.id == "sports" })!,
content.tags.first(where: { $0.id == "hiking" })!,
content.tags.first(where: { $0.id == "mountains" })!
],
german: LocalizedPost(
content: content,
title: "Eine lange Wanderung",
text: "Sehr schöne und einsame Tour von Oberau zum Krottenkopf. Abwechslungsreich und stellenweise fordernd, aufgrund der Länge und der Höhenmeter auch anstrengend.",
images: [
content.files.first(where: { $0.id == "image1" })!,
content.files.first(where: { $0.id == "image2" })!,
content.files.first(where: { $0.id == "image3" })!,
content.files.first(where: { $0.id == "image4" })!
]),
english: LocalizedPost(
content: content,
title: "A longer hike",
text: "Very nice and solitary hike from Oberau to Krottenkopf. Challenging and rewarding, due to the length and height.",
images: [
content.files.first(where: { $0.id == "image1" })!,
content.files.first(where: { $0.id == "image2" })!,
content.files.first(where: { $0.id == "image3" })!,
content.files.first(where: { $0.id == "image4" })!
]))
]
}
static var empty: Post {
Content.mock.posts.first(where: { $0.id == "empty" })!
}
static var hike: Post {
Content.mock.posts.first(where: { $0.id == "hike" })!
}
static var hike2: Post {
Content.mock.posts.first(where: { $0.id == "hike2" })!
}
}
}

View File

@ -1,75 +0,0 @@
import Foundation
extension Tag {
enum Mock {
static func mockData(content: Content) -> [Tag] {
[
Tag(content: content,
id: "electronics",
german: .init(
content: content,
urlComponent: "elektronik",
name: "Elektronik",
linkPreview: .init(description: "Eine Beschreibung des Tags",
image: content.files.first(where: { $0.id == "image2" })!),
originalUrl: "projects/electronics"
),
english: .init(
content: content,
urlComponent: "electronics",
name: "Electronics",
linkPreview: .init(
description: "Some description of the tag",
image: content.files.first(where: { $0.id == "image1" })!),
originalUrl: "projects/electronics")
),
Tag(
content: content,
id: "nature",
german: .init(content: content, urlComponent: "natur", name: "Natur"),
english: .init(content: content, urlComponent: "nature", name: "Nature")
),
Tag(
content: content,
id: "sports",
german: .init(content: content, urlComponent: "sport", name: "Sport"),
english: .init(content: content, urlComponent: "sports", name: "Sports")
),
Tag(
content: content,
id: "hiking",
german: .init(content: content, urlComponent: "wandern", name: "Wandern"),
english: .init(content: content, urlComponent: "hiking", name: "Hiking")
),
Tag(
content: content,
id: "mountains",
german: .init(content: content, urlComponent: "berge", name: "Berge"),
english: .init(content: content, urlComponent: "mountains", name: "Mountains")
)
]
}
static var electronics: Tag {
Content.mock.tags.first(where: { $0.id == "electronics" })!
}
static var nature: Tag {
Content.mock.tags.first(where: { $0.id == "nature" })!
}
static var sports: Tag {
Content.mock.tags.first(where: { $0.id == "sports" })!
}
static var hiking: Tag {
Content.mock.tags.first(where: { $0.id == "hiking" })!
}
static var mountains: Tag {
Content.mock.tags.first(where: { $0.id == "mountains" })!
}
}
}