Improve video and image handling in markdown
This commit is contained in:
18
WebsiteGenerator/Templates/Elements/PageImageTemplate.swift
Normal file
18
WebsiteGenerator/Templates/Elements/PageImageTemplate.swift
Normal file
@ -0,0 +1,18 @@
|
||||
import Foundation
|
||||
|
||||
struct PageImageTemplate: Template {
|
||||
|
||||
enum Key: String, CaseIterable {
|
||||
case image = "IMAGE"
|
||||
case image2x = "IMAGE_2X"
|
||||
case width = "WIDTH"
|
||||
case height = "HEIGHT"
|
||||
case leftText = "LEFT_TEXT"
|
||||
case rightText = "RIGHT_TEXT"
|
||||
}
|
||||
|
||||
static let templateName = "image.html"
|
||||
|
||||
let raw: String
|
||||
|
||||
}
|
37
WebsiteGenerator/Templates/Elements/PageVideoTemplate.swift
Normal file
37
WebsiteGenerator/Templates/Elements/PageVideoTemplate.swift
Normal file
@ -0,0 +1,37 @@
|
||||
import Foundation
|
||||
|
||||
struct PageVideoTemplate: Template {
|
||||
|
||||
typealias VideoSource = (url: String, type: VideoType)
|
||||
|
||||
enum Key: String, CaseIterable {
|
||||
case options = "OPTIONS"
|
||||
case sources = "SOURCES"
|
||||
}
|
||||
|
||||
enum VideoOption: String {
|
||||
case controls
|
||||
case autoplay
|
||||
case muted
|
||||
case loop
|
||||
case playsinline
|
||||
case poster
|
||||
case preload
|
||||
}
|
||||
|
||||
static let templateName = "video.html"
|
||||
|
||||
let raw: String
|
||||
|
||||
func generate<T>(sources: [VideoSource], options: T) -> String where T: Sequence, T.Element == VideoOption {
|
||||
let sourcesCode = sources.map(makeSource).joined(separator: "\n")
|
||||
let optionCode = options.map { $0.rawValue }.joined(separator: " ")
|
||||
return generate([.sources: sourcesCode, .options: optionCode])
|
||||
}
|
||||
|
||||
private func makeSource(_ source: VideoSource) -> String {
|
||||
"""
|
||||
<source src="\(source.url)" type="\(source.type.htmlType)">
|
||||
"""
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user