External files, improve page generation
This commit is contained in:
@@ -18,6 +18,10 @@ extension Content {
|
||||
return prefix + page.localized(in: language).urlString
|
||||
}
|
||||
|
||||
func page(_ pageId: String) -> Page? {
|
||||
pages.first { $0.id == pageId }
|
||||
}
|
||||
|
||||
func pageLink(pageId: String, language: ContentLanguage) -> String? {
|
||||
guard let page = pages.first(where: { $0.id == pageId }) else {
|
||||
// TODO: Note missing link
|
||||
@@ -31,18 +35,42 @@ extension Content {
|
||||
guard let file = file(id: fileId) else {
|
||||
return nil
|
||||
}
|
||||
switch file.type {
|
||||
case .image: return pathToImage(file)
|
||||
case .video: return pathToVideo(file)
|
||||
default: return pathToFile(file)
|
||||
}
|
||||
}
|
||||
|
||||
func pathToFile(_ file: FileResource) -> String {
|
||||
#warning("Add files path to settings")
|
||||
return "/files/\(file.id)"
|
||||
}
|
||||
|
||||
func image(_ imageId: String) -> FileResource? {
|
||||
files.first { $0.id == imageId }
|
||||
func pathToImage(_ image: FileResource) -> String {
|
||||
return "/images/\(image.id)"
|
||||
}
|
||||
|
||||
func imageLink(imageId: String) {
|
||||
|
||||
func image(_ imageId: String) -> FileResource? {
|
||||
files.first { $0.id == imageId && $0.type.isImage }
|
||||
}
|
||||
|
||||
func video(_ videoId: String) -> FileResource? {
|
||||
files.first { $0.id == videoId && $0.type.isVideo }
|
||||
}
|
||||
|
||||
func pathToVideo(_ videoId: String) -> String? {
|
||||
guard let video = video(videoId) else {
|
||||
return nil
|
||||
}
|
||||
return pathToVideo(video)
|
||||
}
|
||||
|
||||
func pathToVideo(_ video: FileResource) -> String {
|
||||
"/videos/\(video.id)"
|
||||
}
|
||||
|
||||
|
||||
func file(id: String) -> FileResource? {
|
||||
files.first { $0.id == id }
|
||||
}
|
||||
|
Reference in New Issue
Block a user