Merge asset and page server
This commit is contained in:
@@ -9,9 +9,7 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
libservice = { workspace = true }
|
||||
macro-assets = { workspace = true }
|
||||
macro-sass = { workspace = true }
|
||||
assetserver = { workspace = true }
|
||||
toolbox = { workspace = true }
|
||||
page = { workspace = true }
|
||||
|
||||
@@ -29,5 +27,4 @@ lazy_static = { workspace = true }
|
||||
toml = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
reqwest = { workspace = true }
|
||||
tower-http = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
|
||||
@@ -4,7 +4,6 @@ use std::{
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use assetserver::Asset;
|
||||
use chrono::{DateTime, TimeDelta, Utc};
|
||||
use maud::{Markup, PreEscaped, html};
|
||||
use page::{DeviceType, RequestContext, page::Page};
|
||||
@@ -18,7 +17,6 @@ use crate::{
|
||||
misc::FarLink,
|
||||
},
|
||||
pages::page_wrapper,
|
||||
routes::assets::Image_Icon,
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@@ -194,7 +192,7 @@ pub fn handouts() -> Page {
|
||||
let mut meta = meta_from_markdown(&md).unwrap().unwrap();
|
||||
|
||||
if meta.image.is_none() {
|
||||
meta.image = Some(Image_Icon::URL.to_owned());
|
||||
meta.image = Some("/assets/img/icon.png".to_owned());
|
||||
}
|
||||
|
||||
let html = PreEscaped(md.render());
|
||||
@@ -202,6 +200,7 @@ pub fn handouts() -> Page {
|
||||
Page {
|
||||
meta,
|
||||
html_ttl: Some(TimeDelta::seconds(300)),
|
||||
immutable: false,
|
||||
|
||||
generate_html: Box::new(move |page, ctx| {
|
||||
let html = html.clone(); // TODO: find a way to not clone here
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use assetserver::Asset;
|
||||
use maud::html;
|
||||
use page::page::{Page, PageMetadata};
|
||||
|
||||
@@ -10,7 +9,6 @@ use crate::{
|
||||
misc::FarLink,
|
||||
},
|
||||
pages::page_wrapper,
|
||||
routes::assets::{Image_Cover, Image_Icon},
|
||||
};
|
||||
|
||||
pub fn index() -> Page {
|
||||
@@ -19,7 +17,7 @@ pub fn index() -> Page {
|
||||
title: "Betalupi: About".into(),
|
||||
author: Some("Mark".into()),
|
||||
description: Some("Description".into()),
|
||||
image: Some(Image_Icon::URL.into()),
|
||||
image: Some("/assets/img/icon.png".to_owned()),
|
||||
backlinks: Some(false),
|
||||
},
|
||||
|
||||
@@ -30,7 +28,7 @@ pub fn index() -> Page {
|
||||
|
||||
div {
|
||||
img
|
||||
src=(Image_Cover::URL)
|
||||
src="/assets/img/cover-small.jpg"
|
||||
style="float:left;margin:10px 10px 10px 10px;display:block;width:25%;"
|
||||
{}
|
||||
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
use assetserver::Asset;
|
||||
use chrono::TimeDelta;
|
||||
use maud::{DOCTYPE, Markup, PreEscaped, html};
|
||||
use page::page::{Page, PageMetadata};
|
||||
use std::pin::Pin;
|
||||
|
||||
use crate::{
|
||||
components::{
|
||||
md::{Markdown, backlinks, meta_from_markdown},
|
||||
misc::FarLink,
|
||||
},
|
||||
routes::assets::{Image_Icon, Styles_Main},
|
||||
use crate::components::{
|
||||
md::{Markdown, backlinks, meta_from_markdown},
|
||||
misc::FarLink,
|
||||
};
|
||||
|
||||
mod handouts;
|
||||
@@ -26,20 +22,23 @@ pub fn links() -> Page {
|
||||
http://www.3dprintmath.com/
|
||||
*/
|
||||
|
||||
page_from_markdown(include_str!("links.md"), Some(Image_Icon::URL.to_owned()))
|
||||
page_from_markdown(
|
||||
include_str!("links.md"),
|
||||
Some("/assets/img/icon.png".to_string()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn betalupi() -> Page {
|
||||
page_from_markdown(
|
||||
include_str!("betalupi.md"),
|
||||
Some(Image_Icon::URL.to_owned()),
|
||||
Some("/assets/img/icon.png".to_string()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn htwah_typesetting() -> Page {
|
||||
page_from_markdown(
|
||||
include_str!("htwah-typesetting.md"),
|
||||
Some(Image_Icon::URL.to_owned()),
|
||||
Some("/assets/img/icon.png".to_string()),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -66,6 +65,7 @@ fn page_from_markdown(md: impl Into<String>, default_image: Option<String>) -> P
|
||||
|
||||
Page {
|
||||
meta,
|
||||
immutable: true,
|
||||
|
||||
html_ttl: Some(TimeDelta::seconds(60 * 24 * 30)),
|
||||
generate_html: Box::new(move |page, ctx| {
|
||||
@@ -104,7 +104,7 @@ pub fn page_wrapper<'a>(
|
||||
meta content="text/html; charset=UTF-8" http-equiv="content-type" {}
|
||||
meta property="og:type" content="website" {}
|
||||
|
||||
link rel="stylesheet" href=(Styles_Main::URL) {}
|
||||
link rel="stylesheet" href=("/assets/css/main.css") {}
|
||||
|
||||
(&meta)
|
||||
title { (PreEscaped(meta.title.clone())) }
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
use assetserver::Asset;
|
||||
use axum::http::header;
|
||||
use macro_assets::assets;
|
||||
use macro_sass::sass;
|
||||
use toolbox::mime::MimeType;
|
||||
|
||||
assets! {
|
||||
prefix: "/assets"
|
||||
router: asset_router()
|
||||
|
||||
//
|
||||
// MARK: styles
|
||||
//
|
||||
|
||||
Styles_Main {
|
||||
source: sass!("css/main.scss").as_bytes(),
|
||||
target: "/css/main.css",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "text/css")
|
||||
]
|
||||
}
|
||||
|
||||
//
|
||||
// MARK: images
|
||||
//
|
||||
|
||||
Image_Cover {
|
||||
source: include_bytes!("../../assets/images/cover-small.jpg"),
|
||||
target: "/img/face.jpg",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "image/jpg")
|
||||
]
|
||||
}
|
||||
|
||||
Image_Betalupi {
|
||||
source: include_bytes!("../../assets/images/betalupi-map.png"),
|
||||
target: "/img/betalupi.png",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "image/png")
|
||||
]
|
||||
}
|
||||
|
||||
Image_Icon {
|
||||
source: include_bytes!("../../assets/images/icon.png"),
|
||||
target: "/img/icon.png",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "image/png")
|
||||
]
|
||||
}
|
||||
|
||||
//
|
||||
// MARK: fonts
|
||||
//
|
||||
|
||||
FiraCode_Bold_woff2 {
|
||||
source: include_bytes!("../../assets/fonts/fira/FiraCode-Bold.woff2"),
|
||||
target: "/fonts/FiraCode-Bold.woff2",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-woff2")
|
||||
]
|
||||
}
|
||||
|
||||
FiraCode_Light_woff2 {
|
||||
source: include_bytes!("../../assets/fonts/fira/FiraCode-Light.woff2"),
|
||||
target: "/fonts/FiraCode-Light.woff2",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-woff2")
|
||||
]
|
||||
}
|
||||
|
||||
FiraCode_Medium_woff2 {
|
||||
source: include_bytes!("../../assets/fonts/fira/FiraCode-Medium.woff2"),
|
||||
target: "/fonts/FiraCode-Medium.woff2",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-woff2")
|
||||
]
|
||||
}
|
||||
|
||||
FiraCode_Regular_woff2 {
|
||||
source: include_bytes!("../../assets/fonts/fira/FiraCode-Regular.woff2"),
|
||||
target: "/fonts/FiraCode-Regular.woff2",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-woff2")
|
||||
]
|
||||
}
|
||||
|
||||
FiraCode_SemiBold_woff2 {
|
||||
source: include_bytes!("../../assets/fonts/fira/FiraCode-SemiBold.woff2"),
|
||||
target: "/fonts/FiraCode-SemiBold.woff2",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-woff2")
|
||||
]
|
||||
}
|
||||
|
||||
FiraCode_VF_woff2 {
|
||||
source: include_bytes!("../../assets/fonts/fira/FiraCode-VF.woff2"),
|
||||
target: "/fonts/FiraCode-VF.woff2",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-woff2")
|
||||
]
|
||||
}
|
||||
|
||||
//
|
||||
// MARK: icons
|
||||
//
|
||||
|
||||
Fa_Brands_woff2 {
|
||||
source: include_bytes!("../../assets/fonts/fa/fa-brands-400.woff2"),
|
||||
target: "/fonts/fa/fa-brands-400.woff2",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-woff2")
|
||||
]
|
||||
}
|
||||
|
||||
Fa_Regular_woff2 {
|
||||
source: include_bytes!("../../assets/fonts/fa/fa-regular-400.woff2"),
|
||||
target: "/fonts/fa/fa-regular-400.woff2",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-woff2")
|
||||
]
|
||||
}
|
||||
|
||||
Fa_Solid_woff2 {
|
||||
source: include_bytes!("../../assets/fonts/fa/fa-solid-900.woff2"),
|
||||
target: "/fonts/fa/fa-solid-900.woff2",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-woff2")
|
||||
]
|
||||
}
|
||||
|
||||
Fa_Brands_ttf {
|
||||
source: include_bytes!("../../assets/fonts/fa/fa-brands-400.ttf"),
|
||||
target: "/fonts/fa/fa-brands-400.ttf",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-ttf")
|
||||
]
|
||||
}
|
||||
|
||||
Fa_Regular_ttf {
|
||||
source: include_bytes!("../../assets/fonts/fa/fa-regular-400.ttf"),
|
||||
target: "/fonts/fa/fa-regular-400.ttf",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-ttf")
|
||||
]
|
||||
}
|
||||
|
||||
Fa_Solid_ttf {
|
||||
source: include_bytes!("../../assets/fonts/fa/fa-solid-900.ttf"),
|
||||
target: "/fonts/fa/fa-solid-900.ttf",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, "application/font-ttf")
|
||||
]
|
||||
}
|
||||
|
||||
//
|
||||
// MARK: htwah
|
||||
//
|
||||
|
||||
Htwah_Definitions {
|
||||
source: include_bytes!("../../assets/htwah/definitions.pdf"),
|
||||
target: "/htwah/definitions.pdf",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, MimeType::Pdf.to_string())
|
||||
]
|
||||
}
|
||||
|
||||
Htwah_Numbering {
|
||||
source: include_bytes!("../../assets/htwah/numbering.pdf"),
|
||||
target: "/htwah/numbering.pdf",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, MimeType::Pdf.to_string())
|
||||
]
|
||||
}
|
||||
|
||||
Htwah_SolsA {
|
||||
source: include_bytes!("../../assets/htwah/sols-a.pdf"),
|
||||
target: "/htwah/sols-a.pdf",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, MimeType::Pdf.to_string())
|
||||
]
|
||||
}
|
||||
|
||||
Htwah_SolsB {
|
||||
source: include_bytes!("../../assets/htwah/sols-b.pdf"),
|
||||
target: "/htwah/sols-b.pdf",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, MimeType::Pdf.to_string())
|
||||
]
|
||||
}
|
||||
|
||||
Htwah_SpacingA {
|
||||
source: include_bytes!("../../assets/htwah/spacing-a.pdf"),
|
||||
target: "/htwah/spacing-a.pdf",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, MimeType::Pdf.to_string())
|
||||
]
|
||||
}
|
||||
|
||||
Htwah_SpacingB {
|
||||
source: include_bytes!("../../assets/htwah/spacing-b.pdf"),
|
||||
target: "/htwah/spacing-b.pdf",
|
||||
headers: [
|
||||
(header::CONTENT_TYPE, MimeType::Pdf.to_string())
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,13 @@
|
||||
use axum::Router;
|
||||
use page::{PageServer, redirect::Redirect};
|
||||
use macro_sass::sass;
|
||||
use page::{PageServer, asset::StaticAsset, redirect::Redirect};
|
||||
use std::sync::Arc;
|
||||
use tracing::info;
|
||||
use toolbox::mime::MimeType;
|
||||
|
||||
use crate::pages;
|
||||
|
||||
pub mod assets;
|
||||
|
||||
pub(super) fn router() -> Router<()> {
|
||||
let (asset_prefix, asset_router) = assets::asset_router();
|
||||
info!("Serving assets at {asset_prefix}");
|
||||
|
||||
let router = build_server().into_router();
|
||||
|
||||
Router::new().merge(router).nest(asset_prefix, asset_router)
|
||||
build_server().into_router()
|
||||
}
|
||||
|
||||
fn build_server() -> Arc<PageServer> {
|
||||
@@ -26,7 +20,171 @@ fn build_server() -> Arc<PageServer> {
|
||||
.add_page("/whats-a-betalupi", pages::betalupi())
|
||||
.add_page("/handouts", pages::handouts())
|
||||
.add_page("/htwah", Redirect::new("/handouts").unwrap())
|
||||
.add_page("/htwah/typesetting", pages::htwah_typesetting());
|
||||
.add_page("/htwah/typesetting", pages::htwah_typesetting())
|
||||
//
|
||||
.add_page(
|
||||
"/assets/css/main.css",
|
||||
StaticAsset {
|
||||
bytes: sass!("css/main.scss").as_bytes(),
|
||||
mime: MimeType::Css,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/img/cover-small.jpg",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/images/cover-small.jpg"),
|
||||
mime: MimeType::Css,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/img/betalupi.png",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/images/betalupi-map.png"),
|
||||
mime: MimeType::Css,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/img/icon.png",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/images/icon.png"),
|
||||
mime: MimeType::Css,
|
||||
},
|
||||
)
|
||||
//
|
||||
// MARK: fonts
|
||||
//
|
||||
.add_page(
|
||||
"/assets/fonts/FiraCode-Bold.woff2",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fira/FiraCode-Bold.woff2"),
|
||||
mime: MimeType::Woff2,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/fonts/FiraCode-Light.woff2",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fira/FiraCode-Light.woff2"),
|
||||
mime: MimeType::Woff2,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/fonts/FiraCode-Medium.woff2",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fira/FiraCode-Medium.woff2"),
|
||||
mime: MimeType::Woff2,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/fonts/FiraCode-Regular.woff2",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fira/FiraCode-Regular.woff2"),
|
||||
mime: MimeType::Woff2,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/fonts/FiraCode-SemiBold.woff2",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fira/FiraCode-SemiBold.woff2"),
|
||||
mime: MimeType::Woff2,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/fonts/FiraCode-VF.woff2",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fira/FiraCode-VF.woff2"),
|
||||
mime: MimeType::Woff2,
|
||||
},
|
||||
)
|
||||
//
|
||||
// MARK: icons
|
||||
//
|
||||
.add_page(
|
||||
"/assets/fonts/fa/fa-brands-400.woff2",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fa/fa-brands-400.woff2"),
|
||||
mime: MimeType::Woff2,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/fonts/fa/fa-regular-400.woff2",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fa/fa-regular-400.woff2"),
|
||||
mime: MimeType::Woff2,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/fonts/fa/fa-solid-900.woff2",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fa/fa-solid-900.woff2"),
|
||||
mime: MimeType::Woff2,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/fonts/fa/fa-brands-400.ttf",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fa/fa-brands-400.ttf"),
|
||||
mime: MimeType::Ttf,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/fonts/fa/fa-regular-400.ttf",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fa/fa-regular-400.ttf"),
|
||||
mime: MimeType::Ttf,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/fonts/fa/fa-solid-900.ttf",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/fonts/fa/fa-solid-900.ttf"),
|
||||
mime: MimeType::Ttf,
|
||||
},
|
||||
)
|
||||
//
|
||||
// MARK: htwah
|
||||
//
|
||||
.add_page(
|
||||
"/assets/htwah/definitions.pdf",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/htwah/definitions.pdf"),
|
||||
mime: MimeType::Pdf,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/htwah/numbering.pdf",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/htwah/numbering.pdf"),
|
||||
mime: MimeType::Pdf,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/htwah/sols-a.pdf",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/htwah/sols-a.pdf"),
|
||||
mime: MimeType::Pdf,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/htwah/sols-b.pdf",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/htwah/sols-b.pdf"),
|
||||
mime: MimeType::Pdf,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/htwah/spacing-a.pdf",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/htwah/spacing-a.pdf"),
|
||||
mime: MimeType::Pdf,
|
||||
},
|
||||
)
|
||||
.add_page(
|
||||
"/assets/htwah/spacing-b.pdf",
|
||||
StaticAsset {
|
||||
bytes: include_bytes!("../../assets/htwah/spacing-b.pdf"),
|
||||
mime: MimeType::Pdf,
|
||||
},
|
||||
);
|
||||
|
||||
server
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user