mirror of
https://github.com/YGGverse/nexy.git
synced 2026-03-31 09:15:28 +00:00
implement list_url_encode argument with optional regex value support
This commit is contained in:
parent
aa40a51440
commit
bc4bc506f8
4 changed files with 44 additions and 4 deletions
13
README.md
13
README.md
|
|
@ -77,14 +77,20 @@ nexy -p /path/to/public_dir
|
||||||
|
|
||||||
* this template file expects pattern and cannot be in binary format
|
* this template file expects pattern and cannot be in binary format
|
||||||
|
|
||||||
**Patterns** * `{list}` - entries list for the `public` directory * `{hosts}` - unique visitors count * `{hits}` - requests count
|
**Patterns**
|
||||||
|
* `{list}` - entries list for the `public` directory
|
||||||
|
* `{hosts}` - unique visitors count
|
||||||
|
* `{hits}` - requests count
|
||||||
|
|
||||||
--template-index <TEMPLATE_INDEX>
|
--template-index <TEMPLATE_INDEX>
|
||||||
Absolute path to the `Index` template file for each directory
|
Absolute path to the `Index` template file for each directory
|
||||||
|
|
||||||
* this template file expects pattern and cannot be in binary format
|
* this template file expects pattern and cannot be in binary format
|
||||||
|
|
||||||
**Patterns** * `{list}` - entries list for the current directory * `{hosts}` - unique visitors count * `{hits}` - requests count
|
**Patterns**
|
||||||
|
* `{list}` - entries list for the current directory
|
||||||
|
* `{hosts}` - unique visitors count
|
||||||
|
* `{hits}` - requests count
|
||||||
|
|
||||||
--list-dir-show-count
|
--list-dir-show-count
|
||||||
Show files count in dir (as the alternative text for navigation links)
|
Show files count in dir (as the alternative text for navigation links)
|
||||||
|
|
@ -150,6 +156,9 @@ nexy -p /path/to/public_dir
|
||||||
|
|
||||||
[default: %Y/%m/%d]
|
[default: %Y/%m/%d]
|
||||||
|
|
||||||
|
--list-url-encode <LIST_URL_ENCODE>
|
||||||
|
Encode listing URL match regex pattern (use `.*` for all entries)
|
||||||
|
|
||||||
-r, --read-chunk <READ_CHUNK>
|
-r, --read-chunk <READ_CHUNK>
|
||||||
Optimize memory usage on reading large files or stream
|
Optimize memory usage on reading large files or stream
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,10 @@ pub struct Config {
|
||||||
#[arg(long, default_value_t = String::from("%Y/%m/%d"))]
|
#[arg(long, default_value_t = String::from("%Y/%m/%d"))]
|
||||||
pub list_time_format: String,
|
pub list_time_format: String,
|
||||||
|
|
||||||
|
/// Encode listing URL match regex pattern (use `.*` for all entries)
|
||||||
|
#[arg(long)]
|
||||||
|
pub list_url_encode: Option<String>,
|
||||||
|
|
||||||
/// Optimize memory usage on reading large files or stream
|
/// Optimize memory usage on reading large files or stream
|
||||||
#[arg(short, long, default_value_t = 1024)]
|
#[arg(short, long, default_value_t = 1024)]
|
||||||
pub read_chunk: usize,
|
pub read_chunk: usize,
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,18 @@ impl Public {
|
||||||
}
|
}
|
||||||
for dir in dirs {
|
for dir in dirs {
|
||||||
r.push({
|
r.push({
|
||||||
let mut l = format!("=> {}/", encode(&dir.name)); // link
|
let mut l = format!(
|
||||||
|
"=> {}/",
|
||||||
|
self.list_config
|
||||||
|
.list_url_encode
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|r| if r.is_match(&dir.name) {
|
||||||
|
Some(encode(&dir.name).to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap_or(dir.name)
|
||||||
|
); // link
|
||||||
let mut a = Vec::new(); // alt
|
let mut a = Vec::new(); // alt
|
||||||
if dc.alt.time.is_accessed {
|
if dc.alt.time.is_accessed {
|
||||||
a.push(self.t(dir.meta.atime()))
|
a.push(self.t(dir.meta.atime()))
|
||||||
|
|
@ -226,7 +237,18 @@ impl Public {
|
||||||
}
|
}
|
||||||
for file in files {
|
for file in files {
|
||||||
r.push({
|
r.push({
|
||||||
let mut l = format!("=> {}", encode(&file.name)); // link
|
let mut l = format!(
|
||||||
|
"=> {}",
|
||||||
|
self.list_config
|
||||||
|
.list_url_encode
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|r| if r.is_match(&file.name) {
|
||||||
|
Some(encode(&file.name).to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap_or(file.name)
|
||||||
|
); // link
|
||||||
let mut a = Vec::new(); // alt
|
let mut a = Vec::new(); // alt
|
||||||
if fc.alt.time.is_accessed {
|
if fc.alt.time.is_accessed {
|
||||||
a.push(self.t(file.meta.atime()))
|
a.push(self.t(file.meta.atime()))
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ pub struct ListConfig {
|
||||||
pub dir: Dir,
|
pub dir: Dir,
|
||||||
pub file: File,
|
pub file: File,
|
||||||
pub time_format: String,
|
pub time_format: String,
|
||||||
|
pub list_url_encode: Option<Regex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ListConfig {
|
impl ListConfig {
|
||||||
|
|
@ -123,6 +124,10 @@ impl ListConfig {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
time_format: config.list_time_format.clone(),
|
time_format: config.list_time_format.clone(),
|
||||||
|
list_url_encode: config
|
||||||
|
.list_url_encode
|
||||||
|
.as_ref()
|
||||||
|
.map(|p| Regex::new(p).unwrap()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue