aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-06-23 20:00:56 -0700
committerFuwn <[email protected]>2024-06-23 20:00:56 -0700
commitce932942347bd602b4bc5a67a4809bbbf3bd2621 (patch)
tree1615816f4df1ea9ce1ed07ef94fc86160982cb74
parentrefactor(blogs): shift content (diff)
downloadlocus-ce932942347bd602b4bc5a67a4809bbbf3bd2621.tar.xz
locus-ce932942347bd602b4bc5a67a4809bbbf3bd2621.zip
feat(web): id filtering
-rw-r--r--content/blogs/technology/Nix.gmi3
-rw-r--r--src/modules/web.rs18
2 files changed, 19 insertions, 2 deletions
diff --git a/content/blogs/technology/Nix.gmi b/content/blogs/technology/Nix.gmi
new file mode 100644
index 0000000..fe93ddd
--- /dev/null
+++ b/content/blogs/technology/Nix.gmi
@@ -0,0 +1,3 @@
+# Nix
+
+=> /web/www.theregister.com/2024/05/14/nix_forked_but_over_politics/?id=article Nix forked, but over politics instead of progress
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" => {