fix
Some checks are pending
ci/woodpecker/push/build Pipeline is running

This commit is contained in:
JMARyA 2024-12-30 23:08:38 +01:00
parent 37cd37018f
commit 5cbc7ef0d2
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263

View file

@ -22,6 +22,7 @@ pub fn read_dir(dir: &PathBuf) -> Vec<String> {
/// Rewrite all URLs in `input` to the format `/s/<domain>/<path..>` /// Rewrite all URLs in `input` to the format `/s/<domain>/<path..>`
fn internalize_urls(input: &str) -> String { fn internalize_urls(input: &str) -> String {
// TODO : Ignore blacklisted urls
let url_pattern = r"https?://([a-zA-Z0-9.-]+)(/[\w./-]*)"; let url_pattern = r"https?://([a-zA-Z0-9.-]+)(/[\w./-]*)";
let re = regex::Regex::new(url_pattern).unwrap(); let re = regex::Regex::new(url_pattern).unwrap();
@ -149,13 +150,18 @@ impl Document {
/// # Returns /// # Returns
/// A new `Document` instance. /// A new `Document` instance.
pub fn new(domain: &str, path: &str, base_dir: PathBuf) -> Self { pub fn new(domain: &str, path: &str, base_dir: PathBuf) -> Self {
let split = path
.split('/')
.filter(|x| !x.is_empty())
.collect::<Vec<&str>>();
Self { Self {
domain: domain.to_string(), domain: domain.to_string(),
path: path path: if split.is_empty() {
.split('/') "/".to_string()
.filter(|x| !x.is_empty()) } else {
.collect::<Vec<&str>>() split.join("/")
.join("/"), },
base_dir, base_dir,
} }
} }
@ -186,7 +192,7 @@ impl Document {
versions.first().cloned()? versions.first().cloned()?
}; };
file_path = file_path.join(latest_version); file_path = file_path.join(format!("index_{}.html", latest_version));
let content = std::fs::read_to_string(file_path).ok()?; let content = std::fs::read_to_string(file_path).ok()?;
@ -204,7 +210,7 @@ impl Document {
pub fn doc_dir(&self) -> PathBuf { pub fn doc_dir(&self) -> PathBuf {
let mut file_path = self.base_dir.join(&self.domain); let mut file_path = self.base_dir.join(&self.domain);
for p in self.path.split('/') { for p in self.path.split('/').filter(|x| !x.is_empty()) {
file_path = file_path.join(p); file_path = file_path.join(p);
} }