Skip to content

Commit

Permalink
Redirect with meta
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Oct 10, 2024
1 parent 5640b47 commit 33e67ee
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
13 changes: 5 additions & 8 deletions blog/src/test/java/io/quarkiverse/roq/it/RoqTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class RoqTest {
@Test
public void testIndex() {
given().when().get("/").then().statusCode(200).body(containsString(
"I provide you with all the tools to generate static websites out of your Quarkus web application."))
"I provide you with all the tools to generate static websites out of your Quarkus web application."))
.body(containsString("Hello, world! I'm Roq")).body(containsString("minute read"))
.body(containsString("Page 1 of")).body(containsString("2024 © ROQ"));
}
Expand All @@ -25,7 +25,7 @@ public void testTag() {
@Test
public void testPosts() {
given().when().get("/posts/2024-08-29-welcome-to-roq").then().statusCode(200).body(containsString(
"I provide you with all the tools to generate static websites out of your Quarkus web application."))
"I provide you with all the tools to generate static websites out of your Quarkus web application."))
.body(containsString("<p>Hello folks,</p>"))
.body(containsString("<h1 class=\"page-title\">Welcome to Roq!</h1>"))
.body(containsString("2024 &copy; ROQ"));
Expand All @@ -34,17 +34,14 @@ public void testPosts() {
@Test
public void testPage() {
given().when().get("/events").then().statusCode(200).body(containsString(
"I provide you with all the tools to generate static websites out of your Quarkus web application."))
"I provide you with all the tools to generate static websites out of your Quarkus web application."))
.body(containsString("<h2 class=\"event-title\">Roq 1.0 Beta</h2>"))
.body(containsString("2024 &copy; ROQ"));
}

@Test
public void testAlias() {
given().when().get("/first-roq-article-ever").then().statusCode(200).body(containsString(
"I provide you with all the tools to generate static websites out of your Quarkus web application."))
.body(containsString("<p>Hello folks,</p>"))
.body(containsString("<h1 class=\"page-title\">Welcome to Roq!</h1>"))
.body(containsString("2024 &copy; ROQ"));
given().when().get("/first-roq-article-ever").then().statusCode(200)
.body(containsString("url=\"/posts/2024-08-29-welcome-to-roq\""));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void consumeTemplates(
for (String alias : aliasesName) {
String aliasLink = TemplateLink.pageLink(config.rootPath(), alias, new TemplateLink.PageLinkData(
item.raw().info(), item.raw().collection(), item.data()));
aliasMap.put(aliasLink, url.path());
aliasMap.put(aliasLink, url.absolute());
}
}

Expand All @@ -81,7 +81,7 @@ public void createVertxRedirects(
for (RoqFrontMatterAliasesBuildItem item : aliases) {
routes.produce(RouteBuildItem.builder()
.route(httpRootPath.relativePath(item.alias()))
.handler(recorder.addRedirect(item.target()))
.handler(recorder.sendRedirectPage(item.target()))
.build());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
package io.quarkiverse.roq.plugin.aliases.runtime;

import java.util.Map;

import io.quarkus.qute.Qute;
import io.quarkus.runtime.annotations.Recorder;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;

@Recorder
public class RoqFrontMatterAliasesRecorder {

public Handler<RoutingContext> addRedirect(String url) {
return ctx -> ctx.redirect(url);
public Handler<RoutingContext> sendRedirectPage(String url) {
return ctx -> {
// language=html
String html = Qute.fmt("""
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>Redirecting&hellip;</title>
<link rel="canonical" href="{url}">
<meta http-equiv="refresh" content="0; url="{url}">
<meta name="robots" content="noindex">
</head>
<body>
<h1>Redirecting&hellip;</h1>
<a href="{url}">Click here if you are not redirected.</a>
<script>location="{url}"</script>
</body>
</html>
""", Map.of("url", url));

ctx.response()
.putHeader("content-type", "text/html")
.end(html);
};
}
}

0 comments on commit 33e67ee

Please sign in to comment.