This commit is contained in:
@@ -25,7 +25,7 @@ use std::{
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use log::{info};
|
||||
use log::info;
|
||||
|
||||
use crate::{
|
||||
law::LawBuilder,
|
||||
@@ -87,7 +87,7 @@ impl Parser {
|
||||
}
|
||||
|
||||
let xml = if self.move_para_headers_into_content {
|
||||
Self::do_move_para_headers_into_content(xml)
|
||||
Self::do_move_para_headers_into_content(&xml)
|
||||
} else {
|
||||
xml
|
||||
};
|
||||
@@ -95,8 +95,8 @@ impl Parser {
|
||||
Risdok::from_str(&xml, builder)
|
||||
}
|
||||
|
||||
fn do_move_para_headers_into_content(xml: String) -> String {
|
||||
let mut result = String::from(&xml);
|
||||
fn do_move_para_headers_into_content(xml: &str) -> String {
|
||||
let mut result = String::from(xml);
|
||||
let ueberschrift_regex = Regex::new(
|
||||
"<ueberschrift typ=\"[^\"]*\" ct=\"[^\"]*\" halign=\"[^\"]*\">(§.*?)</ueberschrift>",
|
||||
)
|
||||
@@ -116,7 +116,7 @@ impl Parser {
|
||||
// Insert the <gldsym> tag with the ueberschrift content into the result string
|
||||
result.insert_str(
|
||||
insert_point,
|
||||
&format!("<gldsym>{}</gldsym>", ueberschrift_content),
|
||||
&format!("<gldsym>{ueberschrift_content}</gldsym>"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -133,20 +133,18 @@ fn fetch(url: &str) -> Result<String, Error> {
|
||||
let hash = format!("{:x}", hasher.finish());
|
||||
|
||||
let expected_filename = format!("{}par-{hash}", get_cache_dir()?);
|
||||
|
||||
match fs::read_to_string(&expected_filename) {
|
||||
Ok(data) => Ok(data),
|
||||
Err(_) => {
|
||||
info!("Not finding url {url} in the cache, downloading...");
|
||||
let data = fetch_with_retries(url)?;
|
||||
let path = Path::new(&expected_filename);
|
||||
if let Some(parent) = path.parent() {
|
||||
// Try to create the directory (and any necessary parent directories)
|
||||
fs::create_dir_all(parent).expect("Unable to create directory");
|
||||
}
|
||||
fs::write(expected_filename, &data).expect("Unable to write file");
|
||||
Ok(data)
|
||||
if let Ok(data) = fs::read_to_string(&expected_filename) {
|
||||
Ok(data)
|
||||
} else {
|
||||
info!("Not finding url {url} in the cache, downloading...");
|
||||
let data = fetch_with_retries(url)?;
|
||||
let path = Path::new(&expected_filename);
|
||||
if let Some(parent) = path.parent() {
|
||||
// Try to create the directory (and any necessary parent directories)
|
||||
fs::create_dir_all(parent).expect("Unable to create directory");
|
||||
}
|
||||
fs::write(expected_filename, &data).expect("Unable to write file");
|
||||
Ok(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user