import Foundation final class Settings: ObservableObject { @Published var paths: PathSettings /// The items to show in the navigation bar @Published var navigation: NavigationSettings @Published var posts: PostSettings @Published var pages: PageSettings @Published var audioPlayer: AudioPlayerSettings init(paths: PathSettings, navigation: NavigationSettings, posts: PostSettings, pages: PageSettings, audioPlayer: AudioPlayerSettings) { self.paths = paths self.navigation = navigation self.posts = posts self.pages = pages self.audioPlayer = audioPlayer } func remove(_ file: FileResource) { pages.remove(file) posts.remove(file) audioPlayer.remove(file) } } // MARK: Storage extension Settings { convenience init(context: LoadingContext, data: Settings.Data) { self.init( paths: .init(data: data.paths), navigation: .init(context: context, data: data.navigation), posts: .init(context: context, data: data.posts), pages: .init(context: context, data: data.pages), audioPlayer: .init(context: context, data: data.audioPlayer)) } func data(tagOverview: Tag?) -> Data { .init( paths: paths.data, navigation: navigation.data, posts: posts.data, pages: pages.data, audioPlayer: audioPlayer.data, tagOverview: tagOverview?.data) } struct Data: Codable { let paths: PathSettings.Data let navigation: NavigationSettings.Data let posts: PostSettings.Data let pages: PageSettings.Data let audioPlayer: AudioPlayerSettings.Data let tagOverview: Tag.Data? } } extension Settings { static let `default`: Settings = .init( paths: .default, navigation: .default, posts: .default, pages: .default, audioPlayer: .default) } extension AudioPlayerSettings { static let `default`: AudioPlayerSettings = .init( playlistCoverImageSize: 280, smallCoverImageSize: 78, audioPlayerJsFile: nil, audioPlayerCssFile: nil, german: .init(playlistText: "Wiedergabeliste"), english: .init(playlistText: "Playlist")) } extension PostSettings { static var `default`: PostSettings { .init(postsPerPage: 25, contentWidth: 600, swiperCssFile: nil, swiperJsFile: nil, defaultCssFile: nil, german: .init( title: "Beiträge", description: "Alle Beiträge", feedUrlPrefix: "blog", defaultPageLinkText: "Anzeigen"), english: .init( title: "Blog posts", description: "All blog posts", feedUrlPrefix: "blog", defaultPageLinkText: "View")) } } extension PathSettings { static var `default`: PathSettings { .init( assetsOutputFolderPath: "asset", pagesOutputFolderPath: "page", imagesOutputFolderPath: "image", filesOutputFolderPath: "file", videosOutputFolderPath: "video", audioOutputFolderPath: "audio", tagsOutputFolderPath: "tag") } } extension PageSettings { static var `default`: PageSettings { .init(contentWidth: 600, largeImageWidth: 1200, pageLinkImageSize: 180, defaultCssFile: nil, codeHighlightingJsFile: nil, modelViewerJsFile: nil, imageCompareJsFile: nil, imageCompareCssFile: nil, german: .init( emptyPageTitle: "Leere Seite", emptyPageText: "Diese Seite ist leer"), english: .init( emptyPageTitle: "Empty page", emptyPageText: "This page is empty")) } }