11
11
import java .nio .charset .StandardCharsets ;
12
12
import java .util .List ;
13
13
import java .util .Locale ;
14
+ import java .util .Optional ;
14
15
15
16
import static dev .nipafx .ginevra .html .HtmlElement .body ;
16
17
import static dev .nipafx .ginevra .html .HtmlElement .div ;
17
18
import static dev .nipafx .ginevra .html .HtmlElement .document ;
18
19
import static dev .nipafx .ginevra .html .HtmlElement .head ;
19
20
import static dev .nipafx .ginevra .html .HtmlElement .meta ;
21
+ import static dev .nipafx .ginevra .util .CollectionUtils .plus ;
20
22
import static zone .nox .components .Components .footer ;
21
23
import static zone .nox .components .Components .header ;
22
24
23
- public record Layout (String title , String description , List <? extends Element > content ) implements Component {
25
+ public record Layout (String title , String description , Optional < String > thumbnail , List <? extends Element > content ) implements Component {
24
26
25
27
public record Style (Classes layout , Classes page , Classes header , Classes content , Classes footer , Css css ) implements CssStyle { }
26
28
@@ -132,14 +134,24 @@ public record Style(Classes layout, Classes page, Classes header, Classes conten
132
134
133
135
@ Override
134
136
public Element compose () {
137
+ var metaElements = List .of (
138
+ meta .name ("viewport" ).content ("width=device-width, initial-scale=1" ),
139
+ meta .name ("description" ).content (description ),
140
+ meta .name ("twitter:title" ).content (title ),
141
+ meta .name ("twitter:description" ).content (description )
142
+ );
143
+ var card = thumbnail .map (thumb -> List .of (
144
+ meta .name ("twitter:image" ).content ("https://nox.zone/thumbnails/" + thumb ),
145
+ meta .name ("twitter:card" ).content ("summary_large_image" )))
146
+ .orElse (List .of (meta .name ("twitter:card" ).content ("summary" )));
147
+ metaElements = plus (metaElements , card );
148
+
135
149
return document
136
150
.language (Locale .US )
137
151
.head (head
138
152
.charset (StandardCharsets .UTF_8 )
139
153
.title (title )
140
- .children (
141
- meta .name ("viewport" ).content ("width=device-width, initial-scale=1" ),
142
- meta .name ("description" ).content (description )))
154
+ .children (metaElements ))
143
155
.body (body
144
156
.classes (STYLE .layout )
145
157
.children (div
@@ -151,19 +163,23 @@ public Element compose() {
151
163
}
152
164
153
165
public Layout title (String title ) {
154
- return new Layout (title , this .description , this .content );
166
+ return new Layout (title , this .description , this .thumbnail , this . content );
155
167
}
156
168
157
169
public Layout description (String description ) {
158
- return new Layout (this .title , description , this .content );
170
+ return new Layout (this .title , description , this .thumbnail , this .content );
171
+ }
172
+
173
+ public Layout thumbnail (Optional <String > thumbnail ) {
174
+ return new Layout (this .title , this .description , thumbnail , this .content );
159
175
}
160
176
161
177
public Layout content (List <? extends Element > children ) {
162
- return new Layout (this .title , this .description , children );
178
+ return new Layout (this .title , this .description , this . thumbnail , children );
163
179
}
164
180
165
181
public Layout content (Element ... children ) {
166
- return new Layout (this .title , this .description , List .of (children ));
182
+ return new Layout (this .title , this .description , this . thumbnail , List .of (children ));
167
183
}
168
184
169
185
}
0 commit comments