| 1 | use crate::{markdown, prelude::*, routes::PageQuery}; |
| 2 | |
| 3 | #[derive(Template)] |
| 4 | #[template(path = "repository/about.html")] |
| 5 | struct AboutPage { |
| 6 | repo: Repository, |
| 7 | current_ref: Ref, |
| 8 | branch_names: Vec<String>, |
| 9 | readme_html: Option<String>, |
| 10 | query: web::Query<PageQuery>, |
| 11 | } |
| 12 | |
| 13 | #[get("/{repo}/about/")] |
| 14 | pub async fn page( |
| 15 | path: web::Path<String>, |
| 16 | query: web::Query<PageQuery>, |
| 17 | data: web::Data<App>, |
| 18 | ) -> Result<HttpResponse, Error> { |
| 19 | let repo = data.get_repo(&path)?; |
| 20 | let current_ref = Ref::resolve(&repo, &query)?; |
| 21 | let branch_names = repo.branch_names()?; |
| 22 | let readme_html = repo |
| 23 | .readme(¤t_ref) |
| 24 | .map(|raw| markdown::render(&raw, &repo.name, ¤t_ref.name)); |
| 25 | |
| 26 | render_html(&AboutPage { |
| 27 | repo, |
| 28 | current_ref, |
| 29 | branch_names, |
| 30 | readme_html, |
| 31 | query, |
| 32 | }) |
| 33 | } |
