Skip to content

Commit dfd729b

Browse files
authored
Add metadata to tags page (StubbornJava#86)
1 parent 7fdec6f commit dfd729b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

stubbornjava-webapp/src/main/java/com/stubbornjava/webapp/post/PostRoutes.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.List;
44

5+
import org.jooq.lambda.Seq;
6+
57
import com.stubbornjava.common.undertow.Exchange;
68
import com.stubbornjava.webapp.PageRoutes;
79
import com.stubbornjava.webapp.Response;
@@ -36,11 +38,18 @@ public static void recentPostsWithTag(HttpServerExchange exchange) {
3638
exchange.setStatusCode(StatusCodes.NOT_FOUND);
3739
}
3840

41+
String metaDesc = "View " + posts.size() + " " + tag +
42+
" examples and guides in Java" +
43+
Seq.seq(posts)
44+
.findFirst()
45+
.map(p -> " including " + p.getTitle() + ".")
46+
.orElse(".");
3947
Response response = Response.fromExchange(exchange)
4048
.with("posts", posts)
4149
.with("type", "Tag")
4250
.with("value", tag)
4351
.with("noData", noData)
52+
.with("metaDesc", metaDesc)
4453
.withLibCounts()
4554
.withRecentPosts();
4655
Exchange.body().sendHtmlTemplate(exchange, "templates/src/pages/tagOrLibSearch", response);

stubbornjava-webapp/ui/src/pages/tagOrLibSearch.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{#> templates/src/common/_base-layout}}
1+
{{#> templates/src/common/_base-layout metaDesc=metaDesc}}
22
{{#*inline "title"}}{{value}} Related Posts{{/inline}}
33
{{#*inline "content"}}
44
<div class="container">

0 commit comments

Comments
 (0)