Skip to content

Commit cc3bb28

Browse files
committed
Add OpenGraph meta data and landing page thumbnail
1 parent 8ce5adc commit cc3bb28

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

src/main/java/zone/nox/components/Components.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class Components {
1010

11-
public static Layout layout = new Layout(null, null, Optional.empty(), List.of());
11+
public static Layout layout = new Layout(null, null, null, Optional.empty(), List.of());
1212

1313
public static Header header = new Header();
1414

src/main/java/zone/nox/components/Layout.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import static zone.nox.components.Components.footer;
2323
import static zone.nox.components.Components.header;
2424

25-
public record Layout(String title, String description, Optional<String> thumbnail, List<? extends Element> content) implements Component {
25+
public record Layout(String slug, String title, String description, Optional<String> thumbnail, List<? extends Element> content) implements Component {
2626

2727
public record Style(Classes layout, Classes page, Classes header, Classes content, Classes footer, Css css) implements CssStyle { }
2828

@@ -137,11 +137,18 @@ public Element compose() {
137137
var metaElements = List.of(
138138
meta.name("viewport").content("width=device-width, initial-scale=1"),
139139
meta.name("description").content(description),
140+
meta.name("og:type").content("website"),
141+
// TODO: the root URL shouldn't be hard-coded
142+
meta.name("og:url").content("https://nox.zone/" + slug),
143+
meta.name("og:logo").content("https://nox.zone/favicon.ico"),
144+
meta.name("og:title").content(title),
140145
meta.name("twitter:title").content(title),
146+
meta.name("og:description").content(description),
141147
meta.name("twitter:description").content(description)
142148
);
143149
var card = thumbnail.map(thumb -> List.of(
144150
// TODO: the root URL shouldn't be hard-coded
151+
meta.name("og:image").content("https://nox.zone/thumbnails/" + thumb),
145152
meta.name("twitter:image").content("https://nox.zone/thumbnails/" + thumb),
146153
meta.name("twitter:card").content("summary_large_image")))
147154
.orElse(List.of(meta.name("twitter:card").content("summary")));
@@ -163,24 +170,28 @@ public Element compose() {
163170
footer.classes(STYLE.footer))));
164171
}
165172

173+
public Layout slug(String slug) {
174+
return new Layout(slug, this.title, this.description, this.thumbnail, this.content);
175+
}
176+
166177
public Layout title(String title) {
167-
return new Layout(title, this.description, this.thumbnail, this.content);
178+
return new Layout(this.slug, title, this.description, this.thumbnail, this.content);
168179
}
169180

170181
public Layout description(String description) {
171-
return new Layout(this.title, description, this.thumbnail, this.content);
182+
return new Layout(this.slug, this.title, description, this.thumbnail, this.content);
172183
}
173184

174185
public Layout thumbnail(Optional<String> thumbnail) {
175-
return new Layout(this.title, this.description, thumbnail, this.content);
186+
return new Layout(this.slug, this.title, this.description, thumbnail, this.content);
176187
}
177188

178189
public Layout content(List<? extends Element> children) {
179-
return new Layout(this.title, this.description, this.thumbnail, children);
190+
return new Layout(this.slug, this.title, this.description, this.thumbnail, children);
180191
}
181192

182193
public Layout content(Element... children) {
183-
return new Layout(this.title, this.description, this.thumbnail, List.of(children));
194+
return new Layout(this.slug, this.title, this.description, this.thumbnail, List.of(children));
184195
}
185196

186197
}

src/main/java/zone/nox/templates/FourOhFour.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public HtmlPage compose() {
1515
return new HtmlPage(
1616
new Slug("404", Slug.SlugStyle.FILE),
1717
layout
18+
.slug("404.html")
1819
.title("404")
1920
.description("Page not found")
2021
.content(

src/main/java/zone/nox/templates/LandingPage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import java.util.List;
1515
import java.util.Map.Entry;
16+
import java.util.Optional;
1617
import java.util.stream.Collectors;
1718
import java.util.stream.Stream;
1819

@@ -56,8 +57,10 @@ public HtmlPage compose(@ForAllIn("posts") List<Post> posts) {
5657
private Element composePage(List<Post> posts) {
5758
var postsByYear = posts.stream().collect(Collectors.groupingBy(post -> post.date().getYear()));
5859
return layout
60+
.slug("")
5961
.title("Radio Nox")
6062
.description("News from the Shadows of Neotropolis.")
63+
.thumbnail(Optional.of("landing.jpg"))
6164
.content(div
6265
.classes(STYLE.posts)
6366
.children(postsByYear

src/main/java/zone/nox/templates/PostPage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public HtmlPage compose(@ForEachIn("posts") Post post) {
3939

4040
private Element composePage(Post post) {
4141
return layout
42+
.slug(post.slug())
4243
.title(post.title())
4344
.description(post.summary())
4445
.thumbnail(post.thumbnail())
51.4 KB
Loading

0 commit comments

Comments
 (0)