mirror of
https://github.com/YGGverse/pulsarss.git
synced 2026-04-02 01:55:33 +00:00
update index file separately
This commit is contained in:
parent
4d4c78a4fc
commit
925ae08bf7
1 changed files with 32 additions and 23 deletions
55
src/main.rs
55
src/main.rs
|
|
@ -48,19 +48,43 @@ fn crawl(
|
||||||
|
|
||||||
match channel.pub_date() {
|
match channel.pub_date() {
|
||||||
Some(pub_date) => {
|
Some(pub_date) => {
|
||||||
// detect index file update required
|
// update `index.gmi` on channel `pub_date` change
|
||||||
let mut index_request = {
|
{
|
||||||
let remote = chrono::DateTime::parse_from_rfc2822(pub_date)?;
|
let remote = chrono::DateTime::parse_from_rfc2822(pub_date)?;
|
||||||
if status.is_some_and(|local| local != remote) || status.is_none() {
|
if status.is_none() || status.is_some_and(|local| local != remote) {
|
||||||
|
// update global state (to skip `index.gmi` overwrites without changes)
|
||||||
*status = Some(remote);
|
*status = Some(remote);
|
||||||
Some((
|
// build `index.gmi` members
|
||||||
|
let (mut file, mut data) = (
|
||||||
File::create(Path::build(target, pub_date, true)?.index())?,
|
File::create(Path::build(target, pub_date, true)?.index())?,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
))
|
);
|
||||||
} else {
|
// collect `index.gmi` data
|
||||||
None
|
for item in channel.items().iter() {
|
||||||
|
match item.pub_date() {
|
||||||
|
Some(pub_date) => {
|
||||||
|
let path = Path::build(target, pub_date, true)?;
|
||||||
|
|
||||||
|
data.push(format!("=> {} {pub_date}", path.filename()));
|
||||||
|
|
||||||
|
if let Some(description) = item.description() {
|
||||||
|
data.push(description.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(content) = item.content() {
|
||||||
|
data.push(content.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
output.warning("item skipped as `pub_date` required by application")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// update `index.gmi` file with new version
|
||||||
|
file.write_all(data.join("\n\n").as_bytes())?;
|
||||||
|
output.debug("index file updated");
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// handle feed items
|
// handle feed items
|
||||||
for item in channel.items().iter() {
|
for item in channel.items().iter() {
|
||||||
|
|
@ -76,9 +100,6 @@ fn crawl(
|
||||||
exist += 1;
|
exist += 1;
|
||||||
continue; // skip existing records
|
continue; // skip existing records
|
||||||
}
|
}
|
||||||
if let Some((_, ref mut index)) = index_request {
|
|
||||||
index.push(format!("=> {} {pub_date}", path.filename()));
|
|
||||||
}
|
|
||||||
data.push(format!("# {pub_date}"));
|
data.push(format!("# {pub_date}"));
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
@ -89,16 +110,10 @@ fn crawl(
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(description) = item.description() {
|
if let Some(description) = item.description() {
|
||||||
if let Some((_, ref mut index)) = index_request {
|
|
||||||
index.push(description.to_string());
|
|
||||||
}
|
|
||||||
data.push(description.to_string());
|
data.push(description.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(content) = item.content() {
|
if let Some(content) = item.content() {
|
||||||
if let Some((_, ref mut index)) = index_request {
|
|
||||||
index.push(content.to_string());
|
|
||||||
}
|
|
||||||
data.push(content.to_string());
|
data.push(content.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,12 +144,6 @@ fn crawl(
|
||||||
// record new item file
|
// record new item file
|
||||||
File::create(path.filepath())?.write_all(data.join("\n\n").as_bytes())?;
|
File::create(path.filepath())?.write_all(data.join("\n\n").as_bytes())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update index file
|
|
||||||
if let Some((mut file, index)) = index_request {
|
|
||||||
file.write_all(index.join("\n\n").as_bytes())?;
|
|
||||||
output.debug("index file updated");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => output.warning("channel skipped as `pub_date` required by application"),
|
None => output.warning("channel skipped as `pub_date` required by application"),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue