39 lines
1.1 KiB
Swift
39 lines
1.1 KiB
Swift
extension Content {
|
|
|
|
private func makeCleanAbsolutePath(_ path: String) -> String {
|
|
("/" + path).replacingOccurrences(of: "//", with: "/")
|
|
}
|
|
|
|
// MARK: Paths to items
|
|
|
|
func absoluteUrlPrefixForTag(_ tag: Tag, language: ContentLanguage) -> String {
|
|
makeCleanAbsolutePath(settings.paths.tagsOutputFolderPath + "/" + tag.localized(in: language).urlComponent)
|
|
}
|
|
|
|
func absoluteUrlToTag(_ tag: Tag, language: ContentLanguage) -> String {
|
|
absoluteUrlPrefixForTag(tag, language: language) + ".html"
|
|
}
|
|
|
|
// MARK: Find items by id
|
|
|
|
func page(_ pageId: String) -> Page? {
|
|
pages.first { $0.id == pageId }
|
|
}
|
|
|
|
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 file(_ fileId: String) -> FileResource? {
|
|
files.first { $0.id == fileId }
|
|
}
|
|
|
|
func tag(_ tagId: String) -> Tag? {
|
|
tags.first { $0.id == tagId }
|
|
}
|
|
}
|