Skip to content

Commit 917e8a0

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

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-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: 16 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,17 @@ 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:title").content(title),
140144
meta.name("twitter:title").content(title),
145+
meta.name("og:description").content(description),
141146
meta.name("twitter:description").content(description)
142147
);
143148
var card = thumbnail.map(thumb -> List.of(
144149
// TODO: the root URL shouldn't be hard-coded
150+
meta.name("og:image").content("https://nox.zone/thumbnails/" + thumb),
145151
meta.name("twitter:image").content("https://nox.zone/thumbnails/" + thumb),
146152
meta.name("twitter:card").content("summary_large_image")))
147153
.orElse(List.of(meta.name("twitter:card").content("summary")));
@@ -163,24 +169,28 @@ public Element compose() {
163169
footer.classes(STYLE.footer))));
164170
}
165171

172+
public Layout slug(String slug) {
173+
return new Layout(slug, this.title, this.description, this.thumbnail, this.content);
174+
}
175+
166176
public Layout title(String title) {
167-
return new Layout(title, this.description, this.thumbnail, this.content);
177+
return new Layout(this.slug, title, this.description, this.thumbnail, this.content);
168178
}
169179

170180
public Layout description(String description) {
171-
return new Layout(this.title, description, this.thumbnail, this.content);
181+
return new Layout(this.slug, this.title, description, this.thumbnail, this.content);
172182
}
173183

174184
public Layout thumbnail(Optional<String> thumbnail) {
175-
return new Layout(this.title, this.description, thumbnail, this.content);
185+
return new Layout(this.slug, this.title, this.description, thumbnail, this.content);
176186
}
177187

178188
public Layout content(List<? extends Element> children) {
179-
return new Layout(this.title, this.description, this.thumbnail, children);
189+
return new Layout(this.slug, this.title, this.description, this.thumbnail, children);
180190
}
181191

182192
public Layout content(Element... children) {
183-
return new Layout(this.title, this.description, this.thumbnail, List.of(children));
193+
return new Layout(this.slug, this.title, this.description, this.thumbnail, List.of(children));
184194
}
185195

186196
}

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)