This commit is contained in:
parent
37cd37018f
commit
5cbc7ef0d2
1 changed files with 13 additions and 7 deletions
|
@ -22,6 +22,7 @@ pub fn read_dir(dir: &PathBuf) -> Vec<String> {
|
|||
|
||||
/// Rewrite all URLs in `input` to the format `/s/<domain>/<path..>`
|
||||
fn internalize_urls(input: &str) -> String {
|
||||
// TODO : Ignore blacklisted urls
|
||||
let url_pattern = r"https?://([a-zA-Z0-9.-]+)(/[\w./-]*)";
|
||||
let re = regex::Regex::new(url_pattern).unwrap();
|
||||
|
||||
|
@ -149,13 +150,18 @@ impl Document {
|
|||
/// # Returns
|
||||
/// A new `Document` instance.
|
||||
pub fn new(domain: &str, path: &str, base_dir: PathBuf) -> Self {
|
||||
Self {
|
||||
domain: domain.to_string(),
|
||||
path: path
|
||||
let split = path
|
||||
.split('/')
|
||||
.filter(|x| !x.is_empty())
|
||||
.collect::<Vec<&str>>()
|
||||
.join("/"),
|
||||
.collect::<Vec<&str>>();
|
||||
|
||||
Self {
|
||||
domain: domain.to_string(),
|
||||
path: if split.is_empty() {
|
||||
"/".to_string()
|
||||
} else {
|
||||
split.join("/")
|
||||
},
|
||||
base_dir,
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +192,7 @@ impl Document {
|
|||
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()?;
|
||||
|
||||
|
@ -204,7 +210,7 @@ impl Document {
|
|||
pub fn doc_dir(&self) -> PathBuf {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue