Basic server, styling, and layout.
This commit is contained in:
parent
ef56eebf7b
commit
bd9c1cffe1
@ -2,6 +2,9 @@ package com.jessebrault.site
|
|||||||
|
|
||||||
import groowt.view.component.web.BaseWebViewComponent
|
import groowt.view.component.web.BaseWebViewComponent
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
class StandardPage extends BaseWebViewComponent {
|
class StandardPage extends BaseWebViewComponent {
|
||||||
|
|
||||||
final String title
|
final String title
|
||||||
@ -14,4 +17,8 @@ class StandardPage extends BaseWebViewComponent {
|
|||||||
this.children
|
this.children
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getCopyrightYear() {
|
||||||
|
LocalDate.now().format(DateTimeFormatter.ofPattern('yyyy'))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,12 @@ package com.jessebrault.site
|
|||||||
---
|
---
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
|
||||||
<title>$title</title>
|
<title>$title</title>
|
||||||
|
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;600&family=EB+Garamond:wght@400;600&display=swap" rel="stylesheet" />
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/main.css" />
|
||||||
</head>
|
</head>
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
|
---
|
||||||
|
package com.jessebrault.site
|
||||||
|
---
|
||||||
<header>
|
<header>
|
||||||
<h1>$siteName</h1>
|
<div class="titles">
|
||||||
<h2>$siteTagLine</h2>
|
<h1 class="eb-garamond-semibold">$siteName</h1>
|
||||||
|
<h2 class="eb-garamond-semibold">$siteTagLine</h2>
|
||||||
|
</div>
|
||||||
<nav>
|
<nav>
|
||||||
<ul>
|
<ul>
|
||||||
<Each items={menuItems} transform={<li><a href={it.path}>$it.name</a></li>} />
|
<Each items={menuItems} transform={<li class="eb-garamond-regular"><a href={it.path}>$it.name</a></li>} />
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
---
|
---
|
||||||
package com.jessebrault.site
|
package com.jessebrault.site
|
||||||
---
|
---
|
||||||
<html lang="en">
|
<html lang="en" class="cormorant-garamond-regular">
|
||||||
<Head title={title} />
|
<Head title={title} />
|
||||||
<body>
|
<body>
|
||||||
<Header />
|
<Header />
|
||||||
<% bodyChildren -> pageChildren.each { bodyChildren << it } %>
|
<main>
|
||||||
|
<% children -> pageChildren.each { children << it } %>
|
||||||
|
</main>
|
||||||
|
<footer>
|
||||||
|
<p>Copyright $copyrightYear Jesse R. Brault. All rights reserved.</p>
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -8,25 +8,22 @@ import org.eclipse.jetty.util.Callback;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class JbHandler extends Handler.Abstract {
|
public final class JbHandler extends Handler.Abstract {
|
||||||
|
|
||||||
private static final Pattern extensionPattern = Pattern.compile("\\.(?<extension>.+)$");
|
private static final Pattern extensionPattern = Pattern.compile(".*\\..+$");
|
||||||
|
|
||||||
private static String getExtension(String path) {
|
private static boolean hasExtension(String path) {
|
||||||
final var m = extensionPattern.matcher(path);
|
final var m = extensionPattern.matcher(path);
|
||||||
if (m.matches()) {
|
return m.matches();
|
||||||
return m.group("extension");
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Path base;
|
private final Set<Path> bases;
|
||||||
|
|
||||||
public JbHandler(Path base) {
|
public JbHandler(Set<Path> bases) {
|
||||||
this.base = base;
|
this.bases = bases;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,15 +41,13 @@ public final class JbHandler extends Handler.Abstract {
|
|||||||
relative = "index.html";
|
relative = "index.html";
|
||||||
}
|
}
|
||||||
|
|
||||||
final String extension = getExtension(relative);
|
if (!hasExtension(relative)) {
|
||||||
if (extension == null) {
|
|
||||||
relative = relative + ".html";
|
relative = relative + ".html";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (final Path base : this.bases) {
|
||||||
final Path resolved = base.resolve(relative);
|
final Path resolved = base.resolve(relative);
|
||||||
if (!Files.exists(resolved)) {
|
if (Files.exists(resolved)) {
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
try (final var inputStream = Files.newInputStream(resolved)) {
|
try (final var inputStream = Files.newInputStream(resolved)) {
|
||||||
final ByteBuffer byteBuffer = ByteBuffer.wrap(inputStream.readAllBytes());
|
final ByteBuffer byteBuffer = ByteBuffer.wrap(inputStream.readAllBytes());
|
||||||
response.write(true, byteBuffer, callback);
|
response.write(true, byteBuffer, callback);
|
||||||
@ -60,5 +55,7 @@ public final class JbHandler extends Handler.Abstract {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@CommandLine.Command(
|
@CommandLine.Command(
|
||||||
name = "jbServer",
|
name = "jbServer",
|
||||||
@ -30,8 +32,11 @@ public class JbServer implements Runnable {
|
|||||||
@CommandLine.Option(names = { "-p", "--port" }, defaultValue = "8080")
|
@CommandLine.Option(names = { "-p", "--port" }, defaultValue = "8080")
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
@CommandLine.Option(names = { "-b", "--base" }, defaultValue = "dist/default")
|
@CommandLine.Option(names = { "-d", "--dist" }, defaultValue = "default")
|
||||||
private Path base;
|
private String dist;
|
||||||
|
|
||||||
|
@CommandLine.Option(names = { "-s", "--static", "--static-dir" }, arity = "0..*", defaultValue = "static")
|
||||||
|
private Set<Path> staticDirs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -45,7 +50,12 @@ public class JbServer implements Runnable {
|
|||||||
server.addConnector(connector);
|
server.addConnector(connector);
|
||||||
|
|
||||||
final Handler.Sequence sequence = new Handler.Sequence();
|
final Handler.Sequence sequence = new Handler.Sequence();
|
||||||
sequence.addHandler(new JbHandler(this.base));
|
|
||||||
|
final Set<Path> bases = new HashSet<>();
|
||||||
|
bases.add(Path.of("dist", this.dist));
|
||||||
|
bases.addAll(this.staticDirs);
|
||||||
|
|
||||||
|
sequence.addHandler(new JbHandler(bases));
|
||||||
sequence.addHandler(new DefaultHandler());
|
sequence.addHandler(new DefaultHandler());
|
||||||
server.setHandler(sequence);
|
server.setHandler(sequence);
|
||||||
|
|
||||||
|
14
start
14
start
@ -1,5 +1,13 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
gradle -q installServerDist \
|
function jbServer() {
|
||||||
&& bin/ssg build -g \
|
if [ "$1" == "--debug" ]; then
|
||||||
&& build/install/jb-ssg-site-server/bin/JbServer "$@"
|
shift
|
||||||
|
build/install/jb-ssg-site-server/bin/JbServer \
|
||||||
|
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:8192 "$@"
|
||||||
|
else
|
||||||
|
build/install/jb-ssg-site-server/bin/JbServer "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
gradle -q installServerDist && jbServer
|
||||||
|
75
static/main.css
Normal file
75
static/main.css
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
.cormorant-garamond-regular {
|
||||||
|
font-family: 'Cormorant Garamond', serif;
|
||||||
|
font-weight: 400;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cormorant-garamond-semibold {
|
||||||
|
font-family: 'Cormorant Garamond', serif;
|
||||||
|
font-weight: 600;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.eb-garamond-regular {
|
||||||
|
font-family: 'EB Garamond', serif;
|
||||||
|
font-optical-sizing: auto;
|
||||||
|
font-weight: 400;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.eb-garamond-semibold {
|
||||||
|
font-family: 'EB Garamond', serif;
|
||||||
|
font-optical-sizing: auto;
|
||||||
|
font-weight: 600;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
font-size: 14pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
header,
|
||||||
|
footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
header .titles {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
column-gap: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav ul {
|
||||||
|
display: flex;
|
||||||
|
column-gap: 25px;
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
padding: 0 25px;
|
||||||
|
text-align: justify;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
main > * {
|
||||||
|
max-width: 700px;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user