diff options
| author | Fuwn <[email protected]> | 2024-06-23 20:00:56 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-06-23 20:00:56 -0700 |
| commit | ce932942347bd602b4bc5a67a4809bbbf3bd2621 (patch) | |
| tree | 1615816f4df1ea9ce1ed07ef94fc86160982cb74 /src/modules | |
| parent | refactor(blogs): shift content (diff) | |
| download | locus-ce932942347bd602b4bc5a67a4809bbbf3bd2621.tar.xz locus-ce932942347bd602b4bc5a67a4809bbbf3bd2621.zip | |
feat(web): id filtering
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/web.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/modules/web.rs b/src/modules/web.rs index 2bb2833..df13058 100644 --- a/src/modules/web.rs +++ b/src/modules/web.rs @@ -36,6 +36,8 @@ To visit the web version of this exact page, <{ROOT_HTTPS_URL}/web>, you would v "/web/*url", "World Wide Web to Gemini Gateway Visitor", async move |context: RouteContext| { + let queries = windmark::utilities::queries_from_url(&context.url); + Response::success({ let Ok(url) = url::Url::parse(&format!( "https://{}", @@ -47,7 +49,7 @@ To visit the web version of this exact page, <{ROOT_HTTPS_URL}/web>, you would v )) else { return error("The URL you provided is invalid.", &context); }; - let mut contents = vec![]; + let mut contents = vec![format!("=> {url} {url}")]; let website = if let Ok(website) = reqwest::get(url.clone()).await { if let Ok(text) = website.text().await { text @@ -72,6 +74,18 @@ To visit the web version of this exact page, <{ROOT_HTTPS_URL}/web>, you would v let parser = dom.parser(); let mut nodes = dom.nodes().iter().peekable(); + if let Some(id) = queries.get("id") { + nodes = if let Some(element) = dom.get_element_by_id(id.as_str()) { + if let Some(children) = element.get(parser).unwrap().children() { + children.all(parser).iter().peekable() + } else { + nodes + } + } else { + nodes + }; + } + while let Some(element) = nodes.next() { let mut text = String::new(); @@ -127,7 +141,7 @@ To visit the web version of this exact page, <{ROOT_HTTPS_URL}/web>, you would v "h3" => { contents.push(format!("\n### {}\n\n", tag.inner_text(parser))); } - "pre" => { + "pre" | "code" => { contents.push(format!("```\n{}```\n", tag.inner_text(parser))); } "blockquote" => { |