]> git.r.bdr.sh - rbdr/page/commitdiff
Replace gemini links
authorRuben Beltran del Rio <redacted>
Sun, 16 Apr 2023 14:41:52 +0000 (16:41 +0200)
committerRuben Beltran del Rio <redacted>
Sun, 16 Apr 2023 14:41:52 +0000 (16:41 +0200)
src/file_handler/file_strategies/gemini.rs
src/gemini_parser.rs

index 04e2b6aae554e9cf2094bb1cbb1b6407096e2def..1c8a111f7a7b2f5dc1c83445e9025a19dd4664ca 100644 (file)
@@ -75,7 +75,8 @@ impl FileHandlerStrategy for Strategy {
 
 
         let relative_path = file.path.strip_prefix(&source).unwrap();
 
 
         let relative_path = file.path.strip_prefix(&source).unwrap();
-        let complete_destination = destination.join(relative_path);
+        let mut complete_destination = destination.join(relative_path);
+        complete_destination.set_extension("html");
         let destination_parent = complete_destination.parent().unwrap();
         create_dir_all(destination_parent).unwrap();
 
         let destination_parent = complete_destination.parent().unwrap();
         create_dir_all(destination_parent).unwrap();
 
index 5c204263bebede10c4c083ff70399ae1aa11b793..d0715f102246aef12dbeade159c285b9d856ccd8 100644 (file)
@@ -8,9 +8,12 @@ pub fn parse(source: &str) -> String {
 
     for line in lines {
         let mut line_type = LineType::Text;
 
     for line in lines {
         let mut line_type = LineType::Text;
-        if line.len() > 2 {
-            let end = line.char_indices().map(|(i, _)| i).nth(2).unwrap();
-            line_type = identify_line(&(line[..end]), is_preformatted);
+        if line.char_indices().count() > 2 {
+            let mut end = line.len();
+            if line.char_indices().count() > 3 {
+                end = line.char_indices().map(|(i, _)| i).nth(3).unwrap();
+            }
+            line_type = identify_line(&line[..end], is_preformatted);
         }
         match line_type {
             LineType::PreformattedToggle => is_preformatted = !is_preformatted,
         }
         match line_type {
             LineType::PreformattedToggle => is_preformatted = !is_preformatted,
@@ -72,7 +75,14 @@ fn get_full_line_content(line_type: &LineType, line: &str) -> String {
      match line_type {
         LineType::Text => format!("<p>{}</p>\n", line.trim()),
         LineType::Blank => "<br/>\n".to_string(),
      match line_type {
         LineType::Text => format!("<p>{}</p>\n", line.trim()),
         LineType::Blank => "<br/>\n".to_string(),
-        LineType::Link => format!("<div><a href=\"{}\">{}</a></div>\n", get_link_address(line), get_link_content(line)),
+        LineType::Link => {
+            let url = get_link_address(line);
+            if url.starts_with("gemini:") {
+                format!("<div><a href=\"{}\">{}</a></div>\n", url, get_link_content(line))
+            } else {
+                format!("<div><a href=\"{}\">{}</a></div>\n", url.replace(".gmi", ".html"), get_link_content(line))
+            }
+        },
         LineType::Heading1 => format!("<h1>{}</h1>\n", line[1..].trim()),
         LineType::Heading2 => format!("<h2>{}</h2>\n", line[2..].trim()),
         LineType::Heading3 => format!("<h3>{}</h3>\n", line[3..].trim()),
         LineType::Heading1 => format!("<h1>{}</h1>\n", line[1..].trim()),
         LineType::Heading2 => format!("<h2>{}</h2>\n", line[2..].trim()),
         LineType::Heading3 => format!("<h3>{}</h3>\n", line[3..].trim()),