Add 404 page
This commit is contained in:
parent
009e9cfcb1
commit
49feefaedc
11
site_test/404.html
Normal file
11
site_test/404.html
Normal file
@ -0,0 +1,11 @@
|
||||
{% extends "default" %}
|
||||
|
||||
{% block titlevariable %}
|
||||
{% set title = "Not Found" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content -%}
|
||||
|
||||
<h1 class="headline">404 Not Found</h1>
|
||||
|
||||
{%- endblock %}
|
@ -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()?)
|
||||
|
35
src/generator/not_found.rs
Normal file
35
src/generator/not_found.rs
Normal 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
|
||||
}
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user