Explicit asset property

This commit is contained in:
Christoph Hagen 2025-02-17 13:38:48 +01:00
parent 0cc0f76254
commit 964c644922
6 changed files with 42 additions and 31 deletions

View File

@ -43,6 +43,10 @@ final class FileResource: Item, LocalizedItem {
@Published @Published
var modifiedDate: Date var modifiedDate: Date
/// Identify this file as an asset to be placed in the `asset` folder on generation
@Published
var isAsset: Bool
/// The dimensions of the image /// The dimensions of the image
@Published @Published
var imageDimensions: CGSize? = nil var imageDimensions: CGSize? = nil
@ -63,7 +67,8 @@ final class FileResource: Item, LocalizedItem {
generatedImageVersions: Set<String> = [], generatedImageVersions: Set<String> = [],
customOutputPath: String? = nil, customOutputPath: String? = nil,
addedDate: Date = .now, addedDate: Date = .now,
modifiedDate: Date = .now) { modifiedDate: Date = .now,
isAsset: Bool = false) {
self.type = FileType(fileExtension: id.fileExtension) self.type = FileType(fileExtension: id.fileExtension)
self.isExternallyStored = isExternallyStored self.isExternallyStored = isExternallyStored
self.german = german self.german = german
@ -74,6 +79,7 @@ final class FileResource: Item, LocalizedItem {
self.customOutputPath = customOutputPath self.customOutputPath = customOutputPath
self.addedDate = addedDate self.addedDate = addedDate
self.modifiedDate = modifiedDate self.modifiedDate = modifiedDate
self.isAsset = isAsset
super.init(content: content, id: id) super.init(content: content, id: id)
} }
@ -91,6 +97,7 @@ final class FileResource: Item, LocalizedItem {
self.customOutputPath = nil self.customOutputPath = nil
self.addedDate = Date.now self.addedDate = Date.now
self.modifiedDate = Date.now self.modifiedDate = Date.now
self.isAsset = false
super.init(content: content, id: resourceImage) super.init(content: content, id: resourceImage)
} }
@ -306,6 +313,9 @@ final class FileResource: Item, LocalizedItem {
} }
private var pathPrefix: String { private var pathPrefix: String {
if isAsset {
return content.settings.paths.assetsOutputFolderPath
}
if type.isImage { if type.isImage {
return content.settings.paths.imagesOutputFolderPath return content.settings.paths.imagesOutputFolderPath
} }
@ -315,9 +325,6 @@ final class FileResource: Item, LocalizedItem {
if type.isAudio { if type.isAudio {
return content.settings.paths.audioOutputFolderPath return content.settings.paths.audioOutputFolderPath
} }
if type.isAsset {
return content.settings.paths.assetsOutputFolderPath
}
return content.settings.paths.filesOutputFolderPath return content.settings.paths.filesOutputFolderPath
} }
@ -365,7 +372,8 @@ extension FileResource: StorageItem {
generatedImageVersions: Set(data.generatedImages ?? []), generatedImageVersions: Set(data.generatedImages ?? []),
customOutputPath: data.customOutputPath, customOutputPath: data.customOutputPath,
addedDate: data.addedDate, addedDate: data.addedDate,
modifiedDate: data.modifiedDate) modifiedDate: data.modifiedDate,
isAsset: data.isAsset ?? false)
savedData = data savedData = data
} }
@ -378,7 +386,8 @@ extension FileResource: StorageItem {
version: version, version: version,
sourceUrl: sourceUrl, sourceUrl: sourceUrl,
addedDate: addedDate, addedDate: addedDate,
modifiedDate: modifiedDate) modifiedDate: modifiedDate,
isAsset: isAsset ? true : nil)
} }
/// This struct holds metadata about a file resource that is stored in the content folder. /// This struct holds metadata about a file resource that is stored in the content folder.
@ -391,6 +400,7 @@ extension FileResource: StorageItem {
let sourceUrl: String? let sourceUrl: String?
let addedDate: Date let addedDate: Date
let modifiedDate: Date let modifiedDate: Date
let isAsset: Bool?
} }
func saveToDisk(_ data: Data) -> Bool { func saveToDisk(_ data: Data) -> Bool {

View File

@ -8,7 +8,6 @@ enum FileTypeCategory: String, CaseIterable {
case text case text
case video case video
case resource case resource
case asset
case audio case audio
var text: String { var text: String {
@ -18,7 +17,6 @@ enum FileTypeCategory: String, CaseIterable {
case .model: return "Models" case .model: return "Models"
case .text: return "Text" case .text: return "Text"
case .video: return "Videos" case .video: return "Videos"
case .asset: return "Assets"
case .resource: return "Other" case .resource: return "Other"
case .audio: return "Audio" case .audio: return "Audio"
} }
@ -32,7 +30,6 @@ enum FileTypeCategory: String, CaseIterable {
case .text: .docText case .text: .docText
case .video: .video case .video: .video
case .resource: .docZipper case .resource: .docZipper
case .asset: .network
case .audio: .speakerWave2CircleFill case .audio: .speakerWave2CircleFill
} }
} }
@ -67,6 +64,8 @@ enum FileType: String {
case tiff case tiff
case ico
// MARK: Code // MARK: Code
case html case html
@ -77,15 +76,9 @@ enum FileType: String {
case sh case sh
// MARK: Assets
case css
case js case js
case ttf case css
case ico
// MARK: Text // MARK: Text
@ -131,6 +124,8 @@ enum FileType: String {
case noExtension case noExtension
case ttf
case zip case zip
case cddx case cddx
@ -163,21 +158,19 @@ enum FileType: String {
var category: FileTypeCategory { var category: FileTypeCategory {
switch self { switch self {
case .jpg, .png, .avif, .webp, .gif, .svg, .tiff: case .jpg, .png, .avif, .webp, .gif, .svg, .tiff, .ico:
return .image return .image
case .mp4, .m4v, .webm: case .mp4, .m4v, .webm:
return .video return .video
case .mp3, .aac, .m4b, .m4a: case .mp3, .aac, .m4b, .m4a:
return .audio return .audio
case .js, .css, .ttf, .ico:
return .asset
case .json, .conf, .yaml, .txt: case .json, .conf, .yaml, .txt:
return .text return .text
case .html, .cpp, .swift, .sh: case .html, .cpp, .swift, .sh, .js, .css:
return .code return .code
case .stl, .f3d, .step, .glb, .f3z: case .stl, .f3d, .step, .glb, .f3z:
return .model return .model
case .zip, .cddx, .pdf, .key, .psd: case .zip, .cddx, .pdf, .key, .psd, .ttf:
return .resource return .resource
case .noExtension, .unknown: case .noExtension, .unknown:
return .resource return .resource
@ -213,8 +206,11 @@ enum FileType: String {
category == .audio category == .audio
} }
var isAsset: Bool { var isLikelyAssetType: Bool {
category == .asset switch self {
case .js, .css, .ttf, .ico: true
default: false
}
} }
var isTextFile: Bool { var isTextFile: Bool {

View File

@ -39,7 +39,7 @@ struct FileContentView: View {
.font(.title) .font(.title)
} }
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
case .text, .code, .asset: case .text, .code:
TextFileContentView(file: file) TextFileContentView(file: file)
.id(file.id) .id(file.id)
case .video: case .video:

View File

@ -99,6 +99,11 @@ struct FileDetailView: View {
text: $file.customOutputPath, text: $file.customOutputPath,
footer: "A custom path where the file is stored in the output folder") footer: "A custom path where the file is stored in the output folder")
BoolPropertyView(
title: "Asset",
value: $file.isAsset,
footer: "Indicate that this file should be treated as an asset")
if let imageDimensions = file.imageDimensions { if let imageDimensions = file.imageDimensions {
GenericPropertyView(title: "Image dimensions") { GenericPropertyView(title: "Image dimensions") {
Text("\(Int(imageDimensions.width)) x \(Int(imageDimensions.height)) (\(file.aspectRatio))") Text("\(Int(imageDimensions.width)) x \(Int(imageDimensions.height)) (\(file.aspectRatio))")

View File

@ -25,13 +25,13 @@ struct AudioSettingsDetailView: View {
title: "Audio Player CSS File", title: "Audio Player CSS File",
footer: "The CSS file to provide the style for the audio player", footer: "The CSS file to provide the style for the audio player",
selectedFile: $audioPlayer.audioPlayerCssFile, selectedFile: $audioPlayer.audioPlayerCssFile,
allowedType: .asset) allowedType: .code)
FilePropertyView( FilePropertyView(
title: "Audio Player JavaScript File", title: "Audio Player JavaScript File",
footer: "The CSS file to provide the functionality for the audio player", footer: "The CSS file to provide the functionality for the audio player",
selectedFile: $audioPlayer.audioPlayerJsFile, selectedFile: $audioPlayer.audioPlayerJsFile,
allowedType: .asset) allowedType: .code)
LocalizedAudioSettingsDetailView(settings: audioPlayer.localized(in: language)) LocalizedAudioSettingsDetailView(settings: audioPlayer.localized(in: language))
.id(language) .id(language)

View File

@ -30,32 +30,32 @@ struct PageSettingsDetailView: View {
title: "Default CSS File", title: "Default CSS File",
footer: "The CSS file containing the styling of all pages", footer: "The CSS file containing the styling of all pages",
selectedFile: $pageSettings.defaultCssFile, selectedFile: $pageSettings.defaultCssFile,
allowedType: .asset) allowedType: .code)
FilePropertyView( FilePropertyView(
title: "Code Highlighting File", title: "Code Highlighting File",
footer: "The JavaScript file to provide syntax highlighting of code blocks", footer: "The JavaScript file to provide syntax highlighting of code blocks",
selectedFile: $pageSettings.codeHighlightingJsFile, selectedFile: $pageSettings.codeHighlightingJsFile,
allowedType: .asset) allowedType: .code)
FilePropertyView( FilePropertyView(
title: "3D Model Viewer File", title: "3D Model Viewer File",
footer: "The JavaScript file to provide the functionality for the 3D model viewer", footer: "The JavaScript file to provide the functionality for the 3D model viewer",
selectedFile: $pageSettings.modelViewerJsFile, selectedFile: $pageSettings.modelViewerJsFile,
allowedType: .asset) allowedType: .code)
FilePropertyView( FilePropertyView(
title: "Image Comparison CSS File", title: "Image Comparison CSS File",
footer: "The CSS file to provide image comparisons", footer: "The CSS file to provide image comparisons",
selectedFile: $pageSettings.imageCompareCssFile, selectedFile: $pageSettings.imageCompareCssFile,
allowedType: .asset) allowedType: .code)
FilePropertyView( FilePropertyView(
title: "Image Comparison JaveScript File", title: "Image Comparison JaveScript File",
footer: "The JavaScript file to provide image comparisons", footer: "The JavaScript file to provide image comparisons",
selectedFile: $pageSettings.imageCompareJsFile, selectedFile: $pageSettings.imageCompareJsFile,
allowedType: .asset) allowedType: .code)
LocalizedPageSettingsView(settings: pageSettings.localized(in: language)) LocalizedPageSettingsView(settings: pageSettings.localized(in: language))
.id(language) .id(language)