Add 404 page

This commit is contained in:
Shadowfacts 2025-01-13 15:13:46 -05:00
parent 009e9cfcb1
commit 49feefaedc
4 changed files with 55 additions and 1 deletions

11
site_test/404.html Normal file
View File

@ -0,0 +1,11 @@
{% extends "default" %}
{% block titlevariable %}
{% set title = "Not Found" %}
{% endblock %}
{% block content -%}
<h1 class="headline">404 Not Found</h1>
{%- endblock %}

View File

@ -2,6 +2,7 @@ mod archive;
mod css;
mod home;
mod markdown;
mod not_found;
mod posts;
mod rss;
mod static_files;
@ -66,6 +67,12 @@ fn make_graph(watcher: Rc<RefCell<FileWatcher>>) -> anyhow::Result<AsyncGraph<()
let tv = tv::make_graph(&mut builder, default_template.clone(), Rc::clone(&watcher));
let not_found = not_found::make_graph(
&mut builder,
default_template.clone(),
&mut *watcher.borrow_mut(),
);
let output = Combine::make(&mut builder, &[
void_outputs,
archive,
@ -75,6 +82,7 @@ fn make_graph(watcher: Rc<RefCell<FileWatcher>>) -> anyhow::Result<AsyncGraph<()
statics,
rss,
tv,
not_found,
]);
builder.set_existing_output(output);
Ok(builder.build()?)

View File

@ -0,0 +1,35 @@
use compute_graph::{builder::GraphBuilder, input::Input, synchronicity::Asynchronous};
use crate::generator::{
templates::{AddTemplate, BuildTemplateContext, RenderTemplate},
util::content_path,
};
use super::{FileWatcher, templates::Templates};
pub fn make_graph(
builder: &mut GraphBuilder<(), Asynchronous>,
default_template: Input<Templates>,
watcher: &mut FileWatcher,
) -> Input<()> {
let path = content_path("404.html");
let (templates, invalidate) =
builder.add_invalidatable_rule(AddTemplate::new("404", path.clone(), default_template));
watcher.watch(path, move || invalidate.invalidate());
let void = builder.add_value(());
let context = builder.add_rule(BuildTemplateContext::new(
"/404.html".into(),
void,
|_, _| {},
));
let render = builder.add_rule(RenderTemplate {
name: "404",
output_path: "404.html".into(),
templates,
context,
});
render
}

View File

@ -35,7 +35,7 @@ pub async fn handle(
Ok(response.map(|b| b.map_err(|_: Infallible| unreachable!()).boxed_unsync()))
} else {
let fallback_resp = fallback.call(request).await?;
Ok(Response::new(fallback_resp.boxed_unsync()))
Ok(fallback_resp.map(|b| b.boxed_unsync()))
}
}