txt route
Some checks failed
ci/woodpecker/push/build Pipeline failed

This commit is contained in:
JMARyA 2024-12-31 17:41:52 +01:00
parent 0e5ca89f1d
commit 3ed87eaba2
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 19 additions and 2 deletions

View file

@ -198,7 +198,7 @@ impl Document {
let mut buf = Vec::new(); let mut buf = Vec::new();
std::fs::File::open(file_path) std::fs::File::open(file_path)
.unwrap() .ok()?
.read_to_end(&mut buf) .read_to_end(&mut buf)
.unwrap(); .unwrap();
let content = String::from_utf8_lossy(&buf); let content = String::from_utf8_lossy(&buf);

View file

@ -41,7 +41,8 @@ async fn launch() -> _ {
pages::render_website, pages::render_website,
pages::domain_info_route, pages::domain_info_route,
pages::favicon_route, pages::favicon_route,
pages::vector_search pages::vector_search,
pages::render_txt_website
], ],
) )
.manage(arc) .manage(arc)

View file

@ -135,6 +135,22 @@ pub async fn domain_info_route(
render_page(content, ctx).await render_page(content, ctx).await
} }
#[get("/txt/<domain>/<path..>?<time>")]
pub async fn render_txt_website(
domain: &str,
path: PathBuf,
time: Option<&str>,
arc: &State<WebsiteArchive>,
) -> Option<String> {
let document = arc.get_domain(domain).path(path.to_str().unwrap());
let content = document
.render_local(time.map(|time| time.to_string()))
.await;
content.map(|content_html| html2md::parse_html(&content_html))
}
/// Return archived version of `domain` / `path` at `time` /// Return archived version of `domain` / `path` at `time`
#[get("/s/<domain>/<path..>?<time>")] #[get("/s/<domain>/<path..>?<time>")]
pub async fn render_website( pub async fn render_website(