Skip to content

Commit dd91aa0

Browse files
author
yggverse
committed
generate index files with given filename, disable by default
1 parent dbd9fa3 commit dd91aa0

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ cargo install pulsarss
2020
## Launch
2121

2222
``` bash
23-
pulsarss --source https://path/to/feed.rss
23+
pulsarss --source https://path/to/feed.rss --index index.gmi
2424
```
2525

2626
### Options
2727

2828
* `source`, `s` - RSS feed source (required)
2929
* `target`, `t` - Destination directory (`public` by default)
3030
* `update`, `u` - Update timeout in seconds (`60` by default)
31-
* `index`, `i` - Generate index files (`index.gmi` by default, empty to disable)
31+
* `index`, `i` - Generate index files with given filename (disabled by default)
3232
* `limit`, `l` - Limit channel items (unlimited by default)
3333
* `output`, `o` - Print output (`dw` by default):
3434
* `d` - debug
@@ -49,7 +49,7 @@ After=network.target
4949
Type=simple
5050
User=pulsarss
5151
Group=pulsarss
52-
ExecStart=pulsarss -s https://path/to/feed.rss
52+
ExecStart=pulsarss -s https://path/to/feed.rss -i index.gmi
5353
5454
[Install]
5555
WantedBy=multi-user.target

src/argument.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use clap::Parser;
33
#[derive(Parser, Debug)]
44
#[command(version, about, long_about = None)]
55
pub struct Argument {
6-
/// Generate index files (`index.gmi` by default, empty to disable)
7-
#[arg(short, long, default_value_t = String::from("index.gmi"))]
8-
pub index: String,
6+
/// Generate index files with given filename (disabled by default)
7+
#[arg(short, long)]
8+
pub index: Option<String>,
99

1010
/// Limit channel items (unlimited by default)
1111
#[arg(short, long, default_value_t = 0)]

src/main.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -94,36 +94,38 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box<dyn Error>> {
9494

9595
File::create(destination.item())?.write_all(data.join("\n\n").as_bytes())?;
9696

97-
if !argument.index.is_empty() {
98-
index.insert(destination.path); // request index file update
97+
if !argument.index.is_none() {
98+
index.insert(destination.path); // request index file update in this location
9999
}
100100
}
101101

102102
// renew pending index files on items crawl completed
103-
for path in index {
104-
let subject = format!("{path}{}", argument.index);
103+
if let Some(ref index_argument) = argument.index {
104+
for path in index {
105+
let subject = format!("{path}{index_argument}");
105106

106-
let mut index = File::create(&subject)?;
107-
let mut data = Vec::with_capacity(argument.limit);
107+
let mut index = File::create(&subject)?;
108+
let mut data = Vec::with_capacity(argument.limit);
108109

109-
let mut total = 0;
110-
for file in read_dir(&path)? {
111-
let name = file?.file_name().into_string().unwrap();
110+
let mut total = 0;
111+
for file in read_dir(&path)? {
112+
let name = file?.file_name().into_string().unwrap();
112113

113-
if name == argument.index {
114-
continue;
115-
}
114+
if &name == index_argument {
115+
continue;
116+
}
116117

117-
let mut buffer = String::from("##"); // correct heading levels
118-
File::open(format!("{path}{name}"))?.read_to_string(&mut buffer)?;
119-
data.push(buffer);
118+
let mut buffer = String::from("##"); // correct heading levels
119+
File::open(format!("{path}{name}"))?.read_to_string(&mut buffer)?;
120+
data.push(buffer);
120121

121-
total += 1;
122-
}
122+
total += 1;
123+
}
123124

124-
index.write_all(data.join("\n\n").as_bytes())?;
125+
index.write_all(data.join("\n\n").as_bytes())?;
125126

126-
output.debug(&format!("renew `{subject}` (total: {total})"));
127+
output.debug(&format!("renew `{subject}` (total: {total})"));
128+
}
127129
}
128130

129131
// print totals

0 commit comments

Comments
 (0)