1111import java .nio .charset .StandardCharsets ;
1212import java .util .List ;
1313import java .util .Locale ;
14+ import java .util .Optional ;
1415
1516import static dev .nipafx .ginevra .html .HtmlElement .body ;
1617import static dev .nipafx .ginevra .html .HtmlElement .div ;
1718import static dev .nipafx .ginevra .html .HtmlElement .document ;
1819import static dev .nipafx .ginevra .html .HtmlElement .head ;
1920import static dev .nipafx .ginevra .html .HtmlElement .meta ;
21+ import static dev .nipafx .ginevra .util .CollectionUtils .plus ;
2022import static zone .nox .components .Components .footer ;
2123import static zone .nox .components .Components .header ;
2224
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 {
2426
2527 public record Style (Classes layout , Classes page , Classes header , Classes content , Classes footer , Css css ) implements CssStyle { }
2628
@@ -132,14 +134,24 @@ public record Style(Classes layout, Classes page, Classes header, Classes conten
132134
133135 @ Override
134136 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+
135149 return document
136150 .language (Locale .US )
137151 .head (head
138152 .charset (StandardCharsets .UTF_8 )
139153 .title (title )
140- .children (
141- meta .name ("viewport" ).content ("width=device-width, initial-scale=1" ),
142- meta .name ("description" ).content (description )))
154+ .children (metaElements ))
143155 .body (body
144156 .classes (STYLE .layout )
145157 .children (div
@@ -151,19 +163,23 @@ public Element compose() {
151163 }
152164
153165 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 );
155167 }
156168
157169 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 );
159175 }
160176
161177 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 );
163179 }
164180
165181 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 ));
167183 }
168184
169185}
0 commit comments