forked from quarkiverse/quarkus-roq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkiverse#166 from ia3andy/fix-aliases-redirect
Redirect with meta
- Loading branch information
Showing
3 changed files
with
35 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 28 additions & 2 deletions
30
...rc/main/java/io/quarkiverse/roq/plugin/aliases/runtime/RoqFrontMatterAliasesRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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…</title> | ||
<link rel="canonical" href="{url}"> | ||
<meta http-equiv="refresh" content="0; url="{url}"> | ||
<meta name="robots" content="noindex"> | ||
</head> | ||
<body> | ||
<h1>Redirecting…</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); | ||
}; | ||
} | ||
} |