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 java.time.LocalDate
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class StandardPage extends BaseWebViewComponent {
|
||||
|
||||
final String title
|
||||
@ -14,4 +17,8 @@ class StandardPage extends BaseWebViewComponent {
|
||||
this.children
|
||||
}
|
||||
|
||||
String getCopyrightYear() {
|
||||
LocalDate.now().format(DateTimeFormatter.ofPattern('yyyy'))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,5 +3,12 @@ package com.jessebrault.site
|
||||
---
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
|
||||
<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>
|
||||
|
@ -1,9 +1,14 @@
|
||||
---
|
||||
package com.jessebrault.site
|
||||
---
|
||||
<header>
|
||||
<h1>$siteName</h1>
|
||||
<h2>$siteTagLine</h2>
|
||||
<div class="titles">
|
||||
<h1 class="eb-garamond-semibold">$siteName</h1>
|
||||
<h2 class="eb-garamond-semibold">$siteTagLine</h2>
|
||||
</div>
|
||||
<nav>
|
||||
<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>
|
||||
</nav>
|
||||
</header>
|
||||
|
@ -1,10 +1,15 @@
|
||||
---
|
||||
package com.jessebrault.site
|
||||
---
|
||||
<html lang="en">
|
||||
<html lang="en" class="cormorant-garamond-regular">
|
||||
<Head title={title} />
|
||||
<body>
|
||||
<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>
|
||||
</html>
|
||||
|
@ -8,25 +8,22 @@ import org.eclipse.jetty.util.Callback;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
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);
|
||||
if (m.matches()) {
|
||||
return m.group("extension");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return m.matches();
|
||||
}
|
||||
|
||||
private final Path base;
|
||||
private final Set<Path> bases;
|
||||
|
||||
public JbHandler(Path base) {
|
||||
this.base = base;
|
||||
public JbHandler(Set<Path> bases) {
|
||||
this.bases = bases;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,21 +41,21 @@ public final class JbHandler extends Handler.Abstract {
|
||||
relative = "index.html";
|
||||
}
|
||||
|
||||
final String extension = getExtension(relative);
|
||||
if (extension == null) {
|
||||
if (!hasExtension(relative)) {
|
||||
relative = relative + ".html";
|
||||
}
|
||||
|
||||
final Path resolved = base.resolve(relative);
|
||||
if (!Files.exists(resolved)) {
|
||||
return false;
|
||||
} else {
|
||||
try (final var inputStream = Files.newInputStream(resolved)) {
|
||||
final ByteBuffer byteBuffer = ByteBuffer.wrap(inputStream.readAllBytes());
|
||||
response.write(true, byteBuffer, callback);
|
||||
for (final Path base : this.bases) {
|
||||
final Path resolved = base.resolve(relative);
|
||||
if (Files.exists(resolved)) {
|
||||
try (final var inputStream = Files.newInputStream(resolved)) {
|
||||
final ByteBuffer byteBuffer = ByteBuffer.wrap(inputStream.readAllBytes());
|
||||
response.write(true, byteBuffer, callback);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import org.slf4j.LoggerFactory;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@CommandLine.Command(
|
||||
name = "jbServer",
|
||||
@ -30,8 +32,11 @@ public class JbServer implements Runnable {
|
||||
@CommandLine.Option(names = { "-p", "--port" }, defaultValue = "8080")
|
||||
private int port;
|
||||
|
||||
@CommandLine.Option(names = { "-b", "--base" }, defaultValue = "dist/default")
|
||||
private Path base;
|
||||
@CommandLine.Option(names = { "-d", "--dist" }, defaultValue = "default")
|
||||
private String dist;
|
||||
|
||||
@CommandLine.Option(names = { "-s", "--static", "--static-dir" }, arity = "0..*", defaultValue = "static")
|
||||
private Set<Path> staticDirs;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -45,7 +50,12 @@ public class JbServer implements Runnable {
|
||||
server.addConnector(connector);
|
||||
|
||||
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());
|
||||
server.setHandler(sequence);
|
||||
|
||||
|
14
start
14
start
@ -1,5 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
gradle -q installServerDist \
|
||||
&& bin/ssg build -g \
|
||||
&& build/install/jb-ssg-site-server/bin/JbServer "$@"
|
||||
function jbServer() {
|
||||
if [ "$1" == "--debug" ]; then
|
||||
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