Skip to content

Commit

Permalink
feat(homepage): Add the homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
malikzh committed Aug 23, 2024
1 parent 82cb024 commit e490462
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/kz/ncanode/NCANode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void main(String[] args) {
System.out.println(banner());
SpringApplication.run(NCANode.class, args);
}
private static String banner() {
public static String banner() {
return """
____ _____ ______ _ ____ _____ __ ______ \s
|_ \\|_ _|.' ___ | / \\ |_ \\|_ _| | ] / ____ `.\s
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/kz/ncanode/controller/HomePageController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package kz.ncanode.controller;

import kz.ncanode.NCANode;
import kz.ncanode.service.MaintenanceService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;

@Controller
@RequiredArgsConstructor
public class HomePageController {
private final MaintenanceService maintenanceService;

@Value("classpath:home.html")
private Resource homePage;
@RequestMapping(value = "/", produces = MediaType.TEXT_HTML_VALUE)
@ResponseBody
public String homePage() {
return loadHtml()
.replace(variable("VERSION"), maintenanceService.getNCANodeVersion())
.replace(variable("BANNER"), NCANode.banner());
}

private String loadHtml() {
try (Reader reader = new InputStreamReader(homePage.getInputStream(), StandardCharsets.UTF_8)) {
return FileCopyUtils.copyToString(reader);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private static String variable(String name) {
return String.format("#{%s}", name);
}
}
50 changes: 50 additions & 0 deletions src/main/resources/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">

<style type="text/css">
body {
background-color: #d1dce0;
font-family: sans-serif;
font-size: 14px;
}

.content {
display: flex;
flex-direction: column;
align-items: center;
}

.version, .links {
margin-top: 10px;
}
</style>

<title>NCANode v#{VERSION}</title>
</head>
<body>
<div class="content">
<pre>#{BANNER}</pre>

<div class="version">
v#{VERSION}
</div>

<div class="links">
<a href="https://v3.ncanode.kz/docs/" target="_blank">
docs
</a>
<span>|</span>
<a href="https://v3.ncanode.kz/swagger-ui/" target="_blank">
swagger
</a>
<span>|</span>
<a href="https://github.com/malikzh/NCANode" target="_blank">
github
</a>
</div>
</div>
</body>
</html>

0 comments on commit e490462

Please sign in to comment.