use askama::Template; use db::models::{Board, Post}; use error::NekrochanError; use web::tcx::TemplateCtx; const GENERIC_PAGE_SIZE: i64 = 10; pub mod auth; pub mod cfg; pub mod ctx; pub mod db; pub mod error; pub mod files; pub mod filters; pub mod live_hub; pub mod live_session; pub mod markup; pub mod perms; pub mod qsform; pub mod schedule; pub mod trip; pub mod web; pub fn paginate(page_size: i64, count: i64) -> i64 { let pages = count / page_size + (count % page_size).signum(); if pages == 0 { 1 } else { pages } } pub fn check_page( page: i64, pages: i64, page_limit: impl Into>, ) -> Result<(), NekrochanError> { if page <= 0 || (page > pages && page != 1) { return Err(NekrochanError::InvalidPageError); } if let Some(page_limit) = page_limit.into() { if page > page_limit { return Err(NekrochanError::InvalidPageError); } } Ok(()) } #[derive(Template)] #[template( ext = "html", source = "{% import \"./macros/post.html\" as post %}{% call post::post(board, post, post.thread.is_some()) %}" )] pub struct PostTemplate<'a> { tcx: &'a TemplateCtx, board: &'a Board, post: &'a Post, }