extension Content { #warning("Get tag url prefix from settings") func tagLink(_ tag: Tag, language: ContentLanguage) -> String { "/tags/\(tag.localized(in: language).urlComponent).html" } func pageLink(_ page: Page, language: ContentLanguage) -> String { // TODO: Record link to trace connections between pages var prefix = settings.pages.pageUrlPrefix if !prefix.hasPrefix("/") { prefix = "/" + prefix } if !prefix.hasSuffix("/") { prefix.append("/") } 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 print("Missing page \(pageId) linked") return nil } return pageLink(page, language: language) } func pathToFile(_ fileId: String) -> String? { 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 pathToImage(_ image: FileResource) -> String { return "/images/\(image.id)" } 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 } } }