aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-06-19 07:52:02 +0000
committerFuwn <[email protected]>2024-06-19 07:52:02 +0000
commitf25e3befc4636cd96f2a53a93e60296b465b766a (patch)
treefa0d091292c6baea33da2eb22f5899a0f905a410
parentfeat(response): PLAIN_TEXT_ROUTES wildcard matching (diff)
downloadseptember-f25e3befc4636cd96f2a53a93e60296b465b766a.tar.xz
september-f25e3befc4636cd96f2a53a93e60296b465b766a.zip
feat: CONDENSE_LINKS_AT_HEADINGS configuration option
-rw-r--r--Cargo.toml2
-rw-r--r--Configuration.md16
-rw-r--r--src/html.rs17
3 files changed, 33 insertions, 2 deletions
diff --git a/Cargo.toml b/Cargo.toml
index cbd7623..2c3d80e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,7 +21,7 @@ opt-level = 3
[dependencies]
# Gemini
-germ = { version = "0.4.0", features = ["ast", "meta"] }
+germ = { version = "0.4.1", features = ["ast", "meta"] }
# HTTP
actix-web = "4.7.0"
diff --git a/Configuration.md b/Configuration.md
index f58d2c7..8a15428 100644
--- a/Configuration.md
+++ b/Configuration.md
@@ -163,3 +163,19 @@ PRIMARY_COLOUR=var(--base09)
PRIMARY_COLOUR=red
PRIMARY_COLOUR=#ff0000
```
+
+## `CONDENSE_LINKS_AT_HEADING`
+
+This configuration option is similar to `CONDENSE_LINKS`, but only condenses
+links found under certain headings.
+
+For instance, I condense the few links I have on my index page under the
+"# Fuwn[.me]" heading, and I condense my quick links/navigation panel under the
+"## Quick Links" heading.
+
+This way, I don't accidentally condense say my entire sitemap, which could be
+hundreds of links long, but I do condense my quick links on every page.
+
+```dotenv
+CONDENSE_LINKS_AT_HEADINGS="## Quick Links,# Fuwn[.me]"
+```
diff --git a/src/html.rs b/src/html.rs
index 07d979e..ae7dc41 100644
--- a/src/html.rs
+++ b/src/html.rs
@@ -52,9 +52,20 @@ pub fn from_gemini(
links.contains(&url.path().to_string()) || links.contains(&"*".to_string())
};
+ let mut in_condense_links_flag_trap = true;
+ let condensible_headings_value =
+ var("CONDENSE_LINKS_AT_HEADINGS").unwrap_or_default();
+ let condensible_headings =
+ condensible_headings_value.split(',').collect::<Vec<_>>();
for node in ast {
- if previous_link && (!matches!(node, Node::Link { .. }) || !condense_links)
+ if condensible_headings.contains(&node.to_gemtext().as_str()) {
+ in_condense_links_flag_trap = true;
+ }
+
+ if previous_link
+ && (!matches!(node, Node::Link { .. })
+ || (!condense_links && !in_condense_links_flag_trap))
{
html.push_str("\n</p>");
previous_link = false;
@@ -173,6 +184,10 @@ pub fn from_gemini(
));
}
Node::Heading { level, text } => {
+ if !condensible_headings.contains(&node.to_gemtext().as_str()) {
+ in_condense_links_flag_trap = false;
+ }
+
if title.is_empty() && *level == 1 {
title = safe(&text.clone()).to_string();
}