diff --git a/src/main/java/zone/nox/Main.java b/src/main/java/zone/nox/Main.java index 4660c08..136c984 100644 --- a/src/main/java/zone/nox/Main.java +++ b/src/main/java/zone/nox/Main.java @@ -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; @@ -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(); diff --git a/src/main/java/zone/nox/components/Components.java b/src/main/java/zone/nox/components/Components.java index 6e58ace..e9cab7f 100644 --- a/src/main/java/zone/nox/components/Components.java +++ b/src/main/java/zone/nox/components/Components.java @@ -6,6 +6,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; +import java.util.Optional; public class Components { @@ -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'"); diff --git a/src/main/java/zone/nox/components/PostHeader.java b/src/main/java/zone/nox/components/PageHeader.java similarity index 61% rename from src/main/java/zone/nox/components/PostHeader.java rename to src/main/java/zone/nox/components/PageHeader.java index 2473f13..47dd5d8 100644 --- a/src/main/java/zone/nox/components/PostHeader.java +++ b/src/main/java/zone/nox/components/PageHeader.java @@ -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 { +public record PageHeader(String title, String summary, Optional dateLine) implements CustomSingleElement, CssStyled { public record Style(Classes container, Classes title, Classes date, Classes summary, Css css) implements CssStyle { } private static final Style STYLE = Css.parse(Style.class, """ @@ -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. map(p.classes(STYLE.date)::text).orElse(nothing), + p.classes(STYLE.summary).text(summary + period(summary)) ); } @@ -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; diff --git a/src/main/java/zone/nox/components/PostContent.java b/src/main/java/zone/nox/components/PostContent.java index c6ff06a..13a526e 100644 --- a/src/main/java/zone/nox/components/PostContent.java +++ b/src/main/java/zone/nox/components/PostContent.java @@ -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 { @@ -79,7 +79,7 @@ public PostContent(Post post) { @Override public List 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())); diff --git a/src/main/java/zone/nox/templates/FourOhFour.java b/src/main/java/zone/nox/templates/FourOhFour.java new file mode 100644 index 0000000..4f3e5e3 --- /dev/null +++ b/src/main/java/zone/nox/templates/FourOhFour.java @@ -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, CssStyled { + + 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 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.)")) + ); + } + +}