diff --git a/src/main/java/eu/m724/talkpages/IndexResource.java b/src/main/java/eu/m724/talkpages/IndexResource.java index 893f252..87267a7 100644 --- a/src/main/java/eu/m724/talkpages/IndexResource.java +++ b/src/main/java/eu/m724/talkpages/IndexResource.java @@ -1,5 +1,8 @@ package eu.m724.talkpages; +import eu.m724.talkpages.orm.entity.content.Page; +import eu.m724.talkpages.orm.entity.content.PageRevision; +import eu.m724.talkpages.page.PageResource; import eu.m724.talkpages.theme.ThemeService; import io.quarkus.qute.CheckedTemplate; import io.quarkus.qute.TemplateInstance; @@ -13,21 +16,27 @@ import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.NewCookie; import jakarta.ws.rs.core.Response; +import org.eclipse.microprofile.config.inject.ConfigProperty; import org.jboss.resteasy.reactive.RestResponse.Status; import java.net.URI; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.List; @Path("/") public class IndexResource { @Inject - RedirectService redirectService; + private RedirectService redirectService; @Inject - HttpServerRequest request; + private HttpServerRequest request; @Inject - ThemeService themeService; + private ThemeService themeService; + + @ConfigProperty(name = "talkpages.siteName") + private String siteName; @CheckedTemplate public static class Templates { @@ -36,12 +45,23 @@ public class IndexResource { @GET @Produces(MediaType.TEXT_HTML) - public TemplateInstance index() { + public Response index() { + Page page = Page.findByPath(siteName); - Cookie cookie = request.getCookie("theme"); - String currentTheme = cookie != null ? cookie.getValue() : null; + if (page == null) { // TODO maybe ask to create + Cookie cookie = request.getCookie("theme"); + String currentTheme = cookie != null ? cookie.getValue() : null; - return Templates.index(themeService.getThemes(), currentTheme); + return Response.ok(Templates.index(themeService.getThemes(), currentTheme)).build(); + } + + PageRevision revision = page.getLatestRevision(); + if (revision.getContent().startsWith("@")) { + String target = revision.getContent().substring(1); + return Response.temporaryRedirect(URI.create("/page/" + redirectService.titleEncoded(target) + "?redirectFrom=" + URLEncoder.encode(siteName, StandardCharsets.UTF_8))).build(); + } + + return Response.ok().entity(PageResource.Templates.page(page, page.getLatestRevision(), false)).build(); } @GET diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 993aea0..d3e3466 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,7 @@ talkpages.homePage=/ talkpages.systemUser.name=System talkpages.theme.default=light +talkpages.siteName=TalkPages quarkus.http.auth.basic=true diff --git a/src/main/resources/templates/IndexResource/index.html b/src/main/resources/templates/IndexResource/index.html index fad0983..7a652fd 100644 --- a/src/main/resources/templates/IndexResource/index.html +++ b/src/main/resources/templates/IndexResource/index.html @@ -37,6 +37,4 @@ Terms of Service -
- Running TalkPages version {config:["quarkus.application.version"]} {/include} \ No newline at end of file