Skip to content

Commit

Permalink
Add 404 page
Browse files Browse the repository at this point in the history
  • Loading branch information
nipafx committed Aug 14, 2024
1 parent 4350966 commit 2ec29cc
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/main/java/zone/nox/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.nipafx.ginevra.outline.Outline;
import dev.nipafx.ginevra.outline.Outliner;
import zone.nox.data.Post;
import zone.nox.templates.FourOhFour;
import zone.nox.templates.LandingTemplate;
import zone.nox.templates.PostTemplate;

Expand Down Expand Up @@ -47,6 +48,7 @@ public Outline createOutline(Outliner outliner) {

outliner.generate(new LandingTemplate());
outliner.generate(new PostTemplate(Target.from(config)));
outliner.generate(new FourOhFour());
outliner.generateStaticResources(Path.of(""), "favicon.ico");

return outliner.build();
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/zone/nox/components/Components.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;

public class Components {

Expand All @@ -19,14 +20,12 @@ public static PostBlock postBlock(Post post) {
return new PostBlock(post);
}

public static PageHeader pageHeader = new PageHeader("", "", Optional.empty());

public static PostContent postContent(Post post) {
return new PostContent(post);
}

public static PostHeader postHeader(Post post) {
return new PostHeader(post);
}

private static final LocalDateTime FIRST_DAY_2024 = LocalDate.of(2024, 4, 24).atTime(0, 0);
private static final DateTimeFormatter ABSOLUTE_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd / HH:mm 'NTZ'");
private static final DateTimeFormatter TIME = DateTimeFormatter.ofPattern("HH:mm 'NTZ'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import dev.nipafx.ginevra.html.Element;
import zone.nox.data.Post;

import java.util.Optional;

import static dev.nipafx.ginevra.html.GmlElement.nothing;
import static dev.nipafx.ginevra.html.HtmlElement.div;
import static dev.nipafx.ginevra.html.HtmlElement.h1;
import static dev.nipafx.ginevra.html.HtmlElement.p;
import static zone.nox.components.Components.format;

public record PostHeader(Post post) implements CustomSingleElement, CssStyled<PostHeader.Style> {
public record PageHeader(String title, String summary, Optional<String> dateLine) implements CustomSingleElement, CssStyled<PageHeader.Style> {

public record Style(Classes container, Classes title, Classes date, Classes summary, Css css) implements CssStyle { }
private static final Style STYLE = Css.parse(Style.class, """
Expand Down Expand Up @@ -50,9 +53,9 @@ public Element composeSingle() {
return div
.classes(STYLE.container)
.children(
h1.classes(STYLE.title).text(post().title()),
p.classes(STYLE.date).text("#%03d / %s".formatted(post.index(), format(post.date()))),
p.classes(STYLE.summary).text(post().summary() + period(post().summary()))
h1.classes(STYLE.title).text(title),
dateLine.<Element> map(p.classes(STYLE.date)::text).orElse(nothing),
p.classes(STYLE.summary).text(summary + period(summary))
);
}

Expand All @@ -63,6 +66,23 @@ private static String period(String text) {
};
}

public PageHeader summary(String summary) {
return new PageHeader(title, summary, dateLine);
}

public PageHeader title(String title) {
return new PageHeader(title, summary, dateLine);
}

public PageHeader dateLine(String dateLine) {
return new PageHeader(title, summary, Optional.of(dateLine));
}

public PageHeader post(Post post) {
var dateLine = "#%03d / %s".formatted(post.index(), format(post.date()));
return new PageHeader(post.title(), post.summary(), Optional.of(dateLine));
}

@Override
public Style style() {
return STYLE;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/zone/nox/components/PostContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static dev.nipafx.ginevra.html.GmlElement.nothing;
import static dev.nipafx.ginevra.html.HtmlElement.div;
import static dev.nipafx.ginevra.html.HtmlElement.video;
import static zone.nox.components.Components.postHeader;
import static zone.nox.components.Components.pageHeader;

public record PostContent(Post post, boolean embedLocalVideo, boolean embedYouTubeVideo) implements CustomElement, CssStyled<PostContent.Style> {

Expand Down Expand Up @@ -79,7 +79,7 @@ public PostContent(Post post) {
@Override
public List<Element> compose() {
return List.of(
div.classes(STYLE.header).children(postHeader(post)),
div.classes(STYLE.header).children(pageHeader.post(post)),
embeddedLocalVideo(),
embeddedYouTubeVideo(),
div.classes(STYLE.content).children(post.content().elements()));
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/zone/nox/templates/FourOhFour.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package zone.nox.templates;

import dev.nipafx.ginevra.css.Css;
import dev.nipafx.ginevra.css.CssStyle;
import dev.nipafx.ginevra.css.CssStyled;
import dev.nipafx.ginevra.outline.HtmlPage;
import dev.nipafx.ginevra.outline.Query;
import dev.nipafx.ginevra.outline.Query.RootQuery;
import dev.nipafx.ginevra.outline.Template;
import zone.nox.data.Root;

import java.nio.file.Path;

import static dev.nipafx.ginevra.html.HtmlElement.h1;
import static dev.nipafx.ginevra.html.HtmlElement.p;
import static zone.nox.components.Components.layout;
import static zone.nox.components.Components.pageHeader;

public class FourOhFour implements Template<Root>, CssStyled<FourOhFour.Style> {

public record Style(Css css) implements CssStyle { }

private static final Style STYLE = Css.parse(Style.class, """
""");

@Override
public Style style() {
return STYLE;
}

@Override
public Query<Root> query() {
return new RootQuery<>(Root.class);
}

@Override
public HtmlPage compose(Root root) {
return new HtmlPage(
Path.of("404"),
layout
.title("404")
.description("Page not found")
.content(
pageHeader
.title("404 - Page not Found")
.summary("Sorry, this page doesn't exist. (Is what they want you to believe.)"))
);
}

}

0 comments on commit 2ec29cc

Please sign in to comment.