Make index page a page
This commit is contained in:
parent
e7beafc65b
commit
7aa86c71ba
3 changed files with 28 additions and 9 deletions
|
@ -1,5 +1,8 @@
|
||||||
package eu.m724.talkpages;
|
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 eu.m724.talkpages.theme.ThemeService;
|
||||||
import io.quarkus.qute.CheckedTemplate;
|
import io.quarkus.qute.CheckedTemplate;
|
||||||
import io.quarkus.qute.TemplateInstance;
|
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.MediaType;
|
||||||
import jakarta.ws.rs.core.NewCookie;
|
import jakarta.ws.rs.core.NewCookie;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||||
import org.jboss.resteasy.reactive.RestResponse.Status;
|
import org.jboss.resteasy.reactive.RestResponse.Status;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Path("/")
|
@Path("/")
|
||||||
public class IndexResource {
|
public class IndexResource {
|
||||||
@Inject
|
@Inject
|
||||||
RedirectService redirectService;
|
private RedirectService redirectService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
HttpServerRequest request;
|
private HttpServerRequest request;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ThemeService themeService;
|
private ThemeService themeService;
|
||||||
|
|
||||||
|
@ConfigProperty(name = "talkpages.siteName")
|
||||||
|
private String siteName;
|
||||||
|
|
||||||
@CheckedTemplate
|
@CheckedTemplate
|
||||||
public static class Templates {
|
public static class Templates {
|
||||||
|
@ -36,12 +45,23 @@ public class IndexResource {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.TEXT_HTML)
|
@Produces(MediaType.TEXT_HTML)
|
||||||
public TemplateInstance index() {
|
public Response index() {
|
||||||
|
Page page = Page.findByPath(siteName);
|
||||||
|
|
||||||
|
if (page == null) { // TODO maybe ask to create
|
||||||
Cookie cookie = request.getCookie("theme");
|
Cookie cookie = request.getCookie("theme");
|
||||||
String currentTheme = cookie != null ? cookie.getValue() : null;
|
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
|
@GET
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
talkpages.homePage=/
|
talkpages.homePage=/
|
||||||
talkpages.systemUser.name=System
|
talkpages.systemUser.name=System
|
||||||
talkpages.theme.default=light
|
talkpages.theme.default=light
|
||||||
|
talkpages.siteName=TalkPages
|
||||||
|
|
||||||
quarkus.http.auth.basic=true
|
quarkus.http.auth.basic=true
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,4 @@
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<small><a href="/page/TalkPages/Terms of Service">Terms of Service</a></small>
|
<small><a href="/page/TalkPages/Terms of Service">Terms of Service</a></small>
|
||||||
<br>
|
|
||||||
<small>Running <a href="/page/TalkPages">TalkPages</a> version {config:["quarkus.application.version"]}</small>
|
|
||||||
{/include}
|
{/include}
|
Loading…
Reference in a new issue