-
Notifications
You must be signed in to change notification settings - Fork 2
/
Theme+ItemDetail.swift
132 lines (123 loc) · 2.77 KB
/
Theme+ItemDetail.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
// Theme+ItemDetail.swift
//
//
// Created by Felizia Bernutz on 26.03.20.
//
import Publish
import Plot
extension Node where Context == HTML.BodyContext {
static func itemDetail(for item: Item<HimmelstraeumerinBlog>, on site: HimmelstraeumerinBlog) -> Node {
switch item.sectionID {
case .posts,
.iOS:
return .article(
.blogPostDetail(item),
.if(item.tags.count > 0,
.div(
.class("tags"),
.span("Tagged with: "),
.tagList(for: item, on: site)
)
)
)
case .sketchnotes:
return .article(
.sketchnoteDetail(item),
.if(item.tags.count > 0,
.div(
.class("tags"),
.span("Tagged with: "),
.tagList(for: item, on: site)
)
)
)
case .about:
return .article(
.cvDetail(item)
)
}
}
}
private extension Node where Context == HTML.BodyContext {
static func blogPostDetail(_ item: Item<HimmelstraeumerinBlog>) -> Self {
let blogMetadata = item.date.formatted
+ " ⋅ "
+ "\(Int(item.readingTime.minutes))"
+ " min read"
return .div(
.class("content post-detail"),
.p(
.class("release-date"),
.text(blogMetadata)
),
.contentBody(item.body)
)
}
static func sketchnoteDetail(_ item: Item<HimmelstraeumerinBlog>) -> Self {
return .div(
.class("content sketchnote-detail"),
.h1(.text(item.title)),
.metaData(for: item),
.sketchnoteOriginal(for: item),
.contentBody(item.body)
)
}
static func sketchnoteOriginal(for item: Item<HimmelstraeumerinBlog>) -> Self {
return .p(
.class("sketchnote-detail-image"),
.unwrap(item.imagePath) {
.a(
.href($0.absoluteString.originalImagePath),
.target(.blank),
.img(
.src($0.absoluteString.originalImagePath),
.alt(item.description)
)
)
}
)
}
static func metaData(for item: Item<HimmelstraeumerinBlog>) -> Self {
let contentByDescription = "Content by"
return .div(
.class("metadata"),
.unwrap(item.metadata.sketchnoteMetadata?.contentCreator) { contentCreator in
.if(item.metadata.sketchnoteMetadata?.linkToContentCreator != nil,
.p(
.text(contentByDescription),
.a(
.href(item.metadata.sketchnoteMetadata?.linkToContentCreator ?? ""),
.text(contentCreator),
.target(.blank),
.rel(.noreferrer)
)
), else:
.p(
.text("\(contentByDescription) \(contentCreator)")
)
)
},
.p(
.text("Sketch by"),
.a(
.href("https://twitter.com/felibe444"),
.text("@felibe444"),
.target(.blank),
.rel(.noreferrer)
)
),
.unwrap(item.date.formatted) { date in
.p(
.text("Created on \(date)")
)
}
)
}
static func cvDetail(_ item: Item<HimmelstraeumerinBlog>) -> Self {
.div(
.class("content about"),
.contentBody(item.body)
)
}
}